|
@@ -212,6 +212,8 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
+import { mapActions, mapState } from "vuex";
|
|
|
|
+
|
|
import { Toast } from "vue-roaster";
|
|
import { Toast } from "vue-roaster";
|
|
import io from "../../io";
|
|
import io from "../../io";
|
|
|
|
|
|
@@ -221,7 +223,6 @@ export default {
|
|
components: { EditNews },
|
|
components: { EditNews },
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- modals: { editNews: false },
|
|
|
|
news: [],
|
|
news: [],
|
|
creating: {
|
|
creating: {
|
|
title: "",
|
|
title: "",
|
|
@@ -238,9 +239,10 @@ export default {
|
|
let _this = this;
|
|
let _this = this;
|
|
io.getSocket(socket => {
|
|
io.getSocket(socket => {
|
|
_this.socket = socket;
|
|
_this.socket = socket;
|
|
- _this.socket.emit("news.index", result => {
|
|
|
|
- _this.news = result.data;
|
|
|
|
- });
|
|
|
|
|
|
+ _this.socket.emit(
|
|
|
|
+ "news.index",
|
|
|
|
+ result => (_this.news = result.data)
|
|
|
|
+ );
|
|
_this.socket.on("event:admin.news.created", news => {
|
|
_this.socket.on("event:admin.news.created", news => {
|
|
_this.news.unshift(news);
|
|
_this.news.unshift(news);
|
|
});
|
|
});
|
|
@@ -248,15 +250,15 @@ export default {
|
|
_this.news = _this.news.filter(item => item._id !== news._id);
|
|
_this.news = _this.news.filter(item => item._id !== news._id);
|
|
});
|
|
});
|
|
if (_this.socket.connected) _this.init();
|
|
if (_this.socket.connected) _this.init();
|
|
- io.onConnect(() => {
|
|
|
|
- _this.init();
|
|
|
|
- });
|
|
|
|
|
|
+ io.onConnect(() => _this.init());
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
+ computed: {
|
|
|
|
+ ...mapState("modals", {
|
|
|
|
+ modals: state => state.modals.admin
|
|
|
|
+ })
|
|
|
|
+ },
|
|
methods: {
|
|
methods: {
|
|
- toggleModal: function() {
|
|
|
|
- this.modals.editNews = !this.modals.editNews;
|
|
|
|
- },
|
|
|
|
createNews: function() {
|
|
createNews: function() {
|
|
let _this = this;
|
|
let _this = this;
|
|
|
|
|
|
@@ -299,13 +301,13 @@ export default {
|
|
});
|
|
});
|
|
},
|
|
},
|
|
removeNews: function(news) {
|
|
removeNews: function(news) {
|
|
- this.socket.emit("news.remove", news, res => {
|
|
|
|
- Toast.methods.addToast(res.message, 8000);
|
|
|
|
- });
|
|
|
|
|
|
+ this.socket.emit("news.remove", news, res =>
|
|
|
|
+ Toast.methods.addToast(res.message, 8000)
|
|
|
|
+ );
|
|
},
|
|
},
|
|
editNews: function(news) {
|
|
editNews: function(news) {
|
|
this.editing = news;
|
|
this.editing = news;
|
|
- this.toggleModal();
|
|
|
|
|
|
+ this.toggleModal({ sector: "admin", modal: "editNews" });
|
|
},
|
|
},
|
|
updateNews: function(close) {
|
|
updateNews: function(close) {
|
|
let _this = this;
|
|
let _this = this;
|
|
@@ -316,7 +318,11 @@ export default {
|
|
res => {
|
|
res => {
|
|
Toast.methods.addToast(res.message, 4000);
|
|
Toast.methods.addToast(res.message, 4000);
|
|
if (res.status === "success") {
|
|
if (res.status === "success") {
|
|
- if (close) _this.toggleModal();
|
|
|
|
|
|
+ if (close)
|
|
|
|
+ _this.toggleModal({
|
|
|
|
+ sector: "admin",
|
|
|
|
+ modal: "editNews"
|
|
|
|
+ });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
);
|
|
);
|
|
@@ -337,7 +343,8 @@ export default {
|
|
},
|
|
},
|
|
init: function() {
|
|
init: function() {
|
|
this.socket.emit("apis.joinAdminRoom", "news", () => {});
|
|
this.socket.emit("apis.joinAdminRoom", "news", () => {});
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ ...mapActions("modals", ["toggleModal"])
|
|
}
|
|
}
|
|
};
|
|
};
|
|
</script>
|
|
</script>
|