Browse Source

fix: Fix frontend eslint issues

Owen Diffey 4 months ago
parent
commit
868bc549f2

+ 3 - 1
frontend/src/Model.ts

@@ -73,7 +73,9 @@ export default class Model {
 		force: boolean,
 		pathParts?: string[]
 	): Promise<void> {
-		let [head, ...rest] = path.split(".");
+		const parts = path.split(".");
+		let [head] = parts;
+		const [, ...rest] = parts;
 		let [next] = rest;
 
 		if (Number.isInteger(head)) head = Number.parseInt(head);

+ 1 - 3
frontend/src/main.ts

@@ -8,10 +8,8 @@ import Toast from "toasters";
 
 import { useConfigStore } from "@/stores/config";
 import { useUserAuthStore } from "@/stores/userAuth";
-import { useUserPreferencesStore } from "@/stores/userPreferences";
 import { useModalsStore } from "@/stores/modals";
 import { useWebsocketsStore } from "@/stores/websockets";
-import ms from "@/ms";
 import i18n from "@/i18n";
 
 import AppComponent from "./App.vue";
@@ -84,7 +82,7 @@ app.use(createPinia());
 const configStore = useConfigStore();
 const modalsStore = useModalsStore();
 const userAuthStore = useUserAuthStore();
-const ws = useWebsocketStore();
+useWebsocketStore();
 const { createSocket } = useWebsocketsStore();
 
 createSocket();

+ 1 - 7
frontend/src/pages/News.vue

@@ -5,12 +5,6 @@ import { formatDistance } from "date-fns";
 import { marked } from "marked";
 import DOMPurify from "dompurify";
 import { NewsModel } from "@musare_types/models/News";
-import {
-	NewsCreatedResponse,
-	NewsUpdatedResponse,
-	NewsRemovedResponse
-} from "@musare_types/events/NewsEvents";
-import { GetPublishedNewsResponse } from "@musare_types/actions/NewsActions";
 import { useEvents } from "@/composables/useEvents";
 import { useModels } from "@/composables/useModels";
 import { useWebsocketStore } from "@/stores/websocket";
@@ -24,7 +18,7 @@ const MainFooter = defineAsyncComponent(
 
 const { runJob } = useWebsocketStore();
 const { onReady } = useEvents();
-const { registerModels, onCreated, onDeleted, subscriptions } = useModels();
+const { registerModels, onCreated, onDeleted } = useModels();
 
 const news = ref<NewsModel[]>([]);
 

+ 38 - 38
frontend/src/stores/model.ts

@@ -34,6 +34,44 @@ export const useModelStore = defineStore("model", () => {
 		return !!data[permission];
 	};
 
+	const unregisterModels = async modelIds =>
+		Promise.all(
+			(Array.isArray(modelIds) ? modelIds : [modelIds]).map(
+				async modelId => {
+					const model = models.value.find(
+						model => model._id === modelId
+					);
+
+					if (!model || model.getUses() > 1) {
+						model?.removeUse();
+
+						return;
+					}
+
+					await model.unregisterRelations();
+
+					const { updated, deleted } = model.getSubscriptions() ?? {};
+
+					if (updated)
+						await unsubscribe(
+							`model.${model.getName()}.updated.${modelId}`,
+							updated
+						);
+
+					if (deleted)
+						await unsubscribe(
+							`model.${model.getName()}.deleted.${modelId}`,
+							deleted
+						);
+
+					models.value.splice(
+						models.value.findIndex(model => model._id === modelId),
+						1
+					);
+				}
+			)
+		);
+
 	const onCreatedCallback = async (modelName: string, data) => {
 		if (!subscriptions.value.created[modelName]) return;
 
@@ -176,44 +214,6 @@ export const useModelStore = defineStore("model", () => {
 			})
 		);
 
-	const unregisterModels = async modelIds =>
-		Promise.all(
-			(Array.isArray(modelIds) ? modelIds : [modelIds]).map(
-				async modelId => {
-					const model = models.value.find(
-						model => model._id === modelId
-					);
-
-					if (!model || model.getUses() > 1) {
-						model?.removeUse();
-
-						return;
-					}
-
-					await model.unregisterRelations();
-
-					const { updated, deleted } = model.getSubscriptions() ?? {};
-
-					if (updated)
-						await unsubscribe(
-							`model.${model.getName()}.updated.${modelId}`,
-							updated
-						);
-
-					if (deleted)
-						await unsubscribe(
-							`model.${model.getName()}.deleted.${modelId}`,
-							deleted
-						);
-
-					models.value.splice(
-						models.value.findIndex(model => model._id === modelId),
-						1
-					);
-				}
-			)
-		);
-
 	const findById = async (modelName: string, _id) => {
 		const existingModel = models.value.find(model => model._id === _id);
 

+ 0 - 1
frontend/src/stores/userAuth.ts

@@ -1,5 +1,4 @@
 import { defineStore } from "pinia";
-import Toast from "toasters";
 import { computed, ref } from "vue";
 import validation from "@/validation";
 import { useWebsocketStore } from "@/stores/websocket";

+ 1 - 0
frontend/src/stores/websocket.ts

@@ -236,6 +236,7 @@ export const useWebsocketStore = defineStore("websocket", () => {
 		ready.value = false;
 
 		// try to reconnect every 1000ms, if the user isn't banned
+		// eslint-disable-next-line no-use-before-define
 		if (!userAuthStore.banned) setTimeout(init, 1000);
 	};