|
@@ -1,8 +1,11 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { defineAsyncComponent, onMounted } from "vue";
|
|
|
+import { defineAsyncComponent, onMounted, ref } from "vue";
|
|
|
import { formatDistance } from "date-fns";
|
|
|
import { marked } from "marked";
|
|
|
import dompurify from "dompurify";
|
|
|
+import { useNewsModelStore } from "@/stores/models/news";
|
|
|
+import { useModels } from "@/composables/useModels";
|
|
|
+import { useModalsStore } from "@/stores/modals";
|
|
|
|
|
|
const Modal = defineAsyncComponent(() => import("@/components/Modal.vue"));
|
|
|
const UserLink = defineAsyncComponent(
|
|
@@ -10,11 +13,49 @@ const UserLink = defineAsyncComponent(
|
|
|
);
|
|
|
|
|
|
defineProps({
|
|
|
- modalUuid: { type: String, required: true },
|
|
|
- news: { type: Object, required: true }
|
|
|
+ modalUuid: { type: String, required: true }
|
|
|
});
|
|
|
|
|
|
-onMounted(() => {
|
|
|
+const { registerModels, onDeleted } = useModels();
|
|
|
+
|
|
|
+const newsStore = useNewsModelStore();
|
|
|
+
|
|
|
+const { closeCurrentModal } = useModalsStore();
|
|
|
+
|
|
|
+const news = ref();
|
|
|
+
|
|
|
+onMounted(async () => {
|
|
|
+ let firstVisited = localStorage.getItem("firstVisited");
|
|
|
+
|
|
|
+ const newUser = !firstVisited;
|
|
|
+
|
|
|
+ const [model] = await newsStore.newest(newUser, 1);
|
|
|
+
|
|
|
+ if (model && newUser) {
|
|
|
+ firstVisited = Date.now().toString();
|
|
|
+
|
|
|
+ localStorage.setItem("firstVisited", firstVisited);
|
|
|
+ } else if (
|
|
|
+ !model ||
|
|
|
+ (localStorage.getItem("whatIsNew") &&
|
|
|
+ parseInt(localStorage.getItem("whatIsNew") as string) >=
|
|
|
+ Date.parse(model.createdAt)) ||
|
|
|
+ parseInt(firstVisited as string) >= model.createdAt
|
|
|
+ ) {
|
|
|
+ closeCurrentModal(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ localStorage.setItem("whatIsNew", Date.parse(model.createdAt).toString());
|
|
|
+
|
|
|
+ const [_model] = await registerModels(newsStore, model);
|
|
|
+
|
|
|
+ news.value = _model;
|
|
|
+
|
|
|
+ await onDeleted(newsStore, ({ oldDoc }) => {
|
|
|
+ if (oldDoc._id === news.value?._id) closeCurrentModal(true);
|
|
|
+ });
|
|
|
+
|
|
|
marked.use({
|
|
|
renderer: {
|
|
|
table(header, body) {
|
|
@@ -31,7 +72,7 @@ const { sanitize } = dompurify;
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
- <modal title="News" class="what-is-news-modal">
|
|
|
+ <modal v-if="news" title="News" class="what-is-news-modal">
|
|
|
<template #body>
|
|
|
<div
|
|
|
class="section news-item"
|