✨ Delete data
This commit is contained in:
@@ -1,20 +1,41 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<virtual-list
|
||||||
<p v-for="ball in store.ballsInFeed" :key="ball.id">
|
class="virtual-list"
|
||||||
<span> {{ ball.author_name }}:</span>
|
:class="{ filled: store.feedsInFeed.length }"
|
||||||
{{ ball.message }}
|
:size="56"
|
||||||
</p>
|
:remain="Math.min(5, store.feedsInFeed.length)"
|
||||||
</div>
|
>
|
||||||
|
<ul v-for="feed in store.feedsInFeed" :key="feed.id">
|
||||||
|
<li>{{ feed.message }}</li>
|
||||||
|
<button class="icon" @click="deleteFeed(feed)">
|
||||||
|
<i class="material-icons">delete</i>
|
||||||
|
</button>
|
||||||
|
</ul>
|
||||||
|
</virtual-list>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.virtual-list {
|
||||||
|
max-height: calc(100vh - 284px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { store } from "../../functions/store";
|
import { store } from "../../functions/store";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
components: {
|
||||||
|
VirtualList: () => import("vue-virtual-scroll-list")
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
store
|
store
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
deleteFeed(feed) {
|
||||||
|
store.deleteFeed(feed.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
formPost() {
|
formPost() {
|
||||||
store.writeBall(this.message);
|
store.writeFeed(this.message);
|
||||||
this.message = null;
|
this.message = null;
|
||||||
this.$refs.inputMessage.focus();
|
this.$refs.inputMessage.focus();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,15 +16,15 @@ const firebaseConfig = {
|
|||||||
};
|
};
|
||||||
firebase.initializeApp(firebaseConfig);
|
firebase.initializeApp(firebaseConfig);
|
||||||
|
|
||||||
// a reference to the Balls collection
|
// a reference to the Feeds collection
|
||||||
const ballsCollection = firebase.firestore().collection("balls");
|
const feedsCollection = firebase.firestore().collection("feeds");
|
||||||
|
|
||||||
// the shared state object that any vue component
|
// the shared state object that any vue component
|
||||||
// can get access to
|
// can get access to
|
||||||
export const store = {
|
export const store = {
|
||||||
ballsInFeed: null,
|
feedsInFeed: [],
|
||||||
currentUser: null,
|
currentUser: {},
|
||||||
writeBall: message => {
|
writeFeed: message => {
|
||||||
const dt = {
|
const dt = {
|
||||||
createdOn: new Date(),
|
createdOn: new Date(),
|
||||||
author: store.currentUser.uid,
|
author: store.currentUser.uid,
|
||||||
@@ -32,9 +32,15 @@ export const store = {
|
|||||||
author_image: store.currentUser.photoURL,
|
author_image: store.currentUser.photoURL,
|
||||||
message
|
message
|
||||||
};
|
};
|
||||||
return ballsCollection
|
return feedsCollection
|
||||||
.add(dt)
|
.add(dt)
|
||||||
.catch(e => console.error("error inserting", dt, e));
|
.catch(e => console.error("error inserting", dt, e));
|
||||||
|
},
|
||||||
|
deleteFeed: id => {
|
||||||
|
return feedsCollection
|
||||||
|
.doc(id)
|
||||||
|
.delete()
|
||||||
|
.catch(e => console.error("error deleting", dt, e));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -42,17 +48,17 @@ export const store = {
|
|||||||
// in the underlying firestore collection changes
|
// in the underlying firestore collection changes
|
||||||
// It will get passed an array of references to
|
// It will get passed an array of references to
|
||||||
// the documents that match your query
|
// the documents that match your query
|
||||||
ballsCollection
|
feedsCollection
|
||||||
.orderBy("createdOn", "desc")
|
.orderBy("createdOn", "desc")
|
||||||
.limit(5)
|
// .limit(0)
|
||||||
.onSnapshot(ballsRef => {
|
.onSnapshot(feedsRef => {
|
||||||
const balls = [];
|
const feeds = [];
|
||||||
ballsRef.forEach(doc => {
|
feedsRef.forEach(doc => {
|
||||||
const ball = doc.data();
|
const feed = doc.data();
|
||||||
ball.id = doc.id;
|
feed.id = doc.id;
|
||||||
balls.push(ball);
|
feeds.push(feed);
|
||||||
});
|
});
|
||||||
store.ballsInFeed = balls;
|
store.feedsInFeed = feeds;
|
||||||
});
|
});
|
||||||
|
|
||||||
// When a user logs in or out, save that in the store
|
// When a user logs in or out, save that in the store
|
||||||
|
|||||||
Reference in New Issue
Block a user