Explorar el Código

refactor: Minor news model store fixes and addition

Owen Diffey hace 1 año
padre
commit
16f4d7d6fe

+ 4 - 5
frontend/src/App.vue

@@ -5,7 +5,6 @@ import Toast from "toasters";
 import { storeToRefs } from "pinia";
 import { GenericResponse } from "@musare_types/actions/GenericActions";
 import { GetPreferencesResponse } from "@musare_types/actions/UsersActions";
-import { NewestResponse } from "@musare_types/actions/NewsActions";
 import { useWebsocketsStore } from "@/stores/websockets";
 import { useConfigStore } from "@/stores/config";
 import { useUserAuthStore } from "@/stores/userAuth";
@@ -13,6 +12,7 @@ import { useUserPreferencesStore } from "@/stores/userPreferences";
 import { useModalsStore } from "@/stores/modals";
 import aw from "@/aw";
 import keyboardShortcuts from "@/keyboardShortcuts";
+import { useNewsModelStore } from "./stores/models/news";
 
 const ModalManager = defineAsyncComponent(
 	() => import("@/components/ModalManager.vue")
@@ -32,6 +32,7 @@ const configStore = useConfigStore();
 const userAuthStore = useUserAuthStore();
 const userPreferencesStore = useUserPreferencesStore();
 const modalsStore = useModalsStore();
+const { newest } = useNewsModelStore();
 
 const socketConnected = ref(true);
 const keyIsDown = ref("");
@@ -196,10 +197,8 @@ onMounted(async () => {
 		);
 
 		const newUser = !localStorage.getItem("firstVisited");
-		socket.dispatch("news.newest", newUser, (res: NewestResponse) => {
-			if (res.status !== "success") return;
-
-			const { news } = res.data;
+		newest(newUser).then(data => {
+			const news = data[0]?.value;
 
 			if (news) {
 				if (newUser) {

+ 1 - 1
frontend/src/components/modals/WhatIsNew.vue

@@ -46,7 +46,7 @@ const { sanitize } = dompurify;
 					:alt="news.createdBy" /></span
 			>&nbsp;<span :title="new Date(news.createdAt).toString()">
 				{{
-					formatDistance(news.createdAt, new Date(), {
+					formatDistance(new Date(news.createdAt), new Date(), {
 						addSuffix: true
 					})
 				}}

+ 13 - 3
frontend/src/pages/Admin/News.vue

@@ -127,7 +127,7 @@ const remove = async (_id: string) => {
 			</div>
 			<div class="button-row">
 				<button
-					v-if="hasPermission('news.create')"
+					v-if="hasPermission('data.news.create')"
 					class="is-primary button"
 					@click="
 						openModal({
@@ -150,7 +150,12 @@ const remove = async (_id: string) => {
 			<template #column-options="slotProps">
 				<div class="row-options">
 					<button
-						v-if="hasPermission('news.update', slotProps.item._id)"
+						v-if="
+							hasPermission(
+								'data.news.updateById',
+								slotProps.item._id
+							)
+						"
 						class="button is-primary icon-with-button material-icons"
 						@click="
 							openModal({
@@ -164,7 +169,12 @@ const remove = async (_id: string) => {
 						edit
 					</button>
 					<quick-confirm
-						v-if="hasPermission('news.remove', slotProps.item._id)"
+						v-if="
+							hasPermission(
+								'data.news.deleteById',
+								slotProps.item._id
+							)
+						"
 						@confirm="remove(slotProps.item._id)"
 						:disabled="slotProps.item.removed"
 					>