Explorar o código

refactor: Converted removeAccount Vuex store to Pinia store

Owen Diffey %!s(int64=2) %!d(string=hai) anos
pai
achega
02b9b4b48d

+ 4 - 7
frontend/src/components/modals/RemoveAccount.vue

@@ -3,9 +3,10 @@ import { useStore } from "vuex";
 import { ref, onMounted } from "vue";
 import { useRoute } from "vue-router";
 import Toast from "toasters";
-import { useModalState } from "@/vuex_helpers";
+import { storeToRefs } from "pinia";
 import { useSettingsStore } from "@/stores/settings";
 import { useWebsocketsStore } from "@/stores/websockets";
+import { useRemoveAccountStore } from "@/stores/removeAccount";
 
 const props = defineProps({
 	modalUuid: { type: String, default: "" }
@@ -18,12 +19,8 @@ const store = useStore();
 
 const { socket } = useWebsocketsStore();
 
-const { githubLinkConfirmed } = useModalState(
-	"modals/removeAccount/MODAL_UUID",
-	{
-		modalUuid: props.modalUuid
-	}
-);
+const removeAccountStore = useRemoveAccountStore(props);
+const { githubLinkConfirmed } = storeToRefs(removeAccountStore);
 
 const { isPasswordLinked, isGithubLinked } = settingsStore;
 const closeCurrentModal = () =>

+ 1 - 2
frontend/src/store/index.ts

@@ -18,8 +18,7 @@ export default createStore({
 				viewPunishment: emptyModule,
 				report: emptyModule,
 				viewReport: emptyModule,
-				viewYoutubeVideo: emptyModule,
-				removeAccount: emptyModule
+				viewYoutubeVideo: emptyModule
 			}
 		}
 	},

+ 7 - 4
frontend/src/store/modules/modalVisibility.ts

@@ -7,7 +7,6 @@ import viewReport from "./modals/viewReport";
 import viewApiRequest from "./modals/viewApiRequest";
 import viewPunishment from "./modals/viewPunishment";
 import viewYoutubeVideo from "./modals/viewYoutubeVideo";
-import removeAccount from "./modals/removeAccount";
 
 import { useEditUserStore } from "@/stores/editUser";
 import { useEditSongStore } from "@/stores/editSong";
@@ -19,6 +18,7 @@ import { useEditNewsStore } from "@/stores/editNews";
 import { useEditPlaylistStore } from "@/stores/editPlaylist";
 import { useImportAlbumStore } from "@/stores/importAlbum";
 import { useManageStationStore } from "@/stores/manageStation";
+import { useRemoveAccountStore } from "@/stores/removeAccount";
 
 const state = {
 	modals: {},
@@ -35,7 +35,8 @@ const piniaStores = [
 	"editNews",
 	"editPlaylist",
 	"importAlbum",
-	"manageStation"
+	"manageStation",
+	"removeAccount"
 ];
 
 const modalModules = {
@@ -44,8 +45,7 @@ const modalModules = {
 	viewReport,
 	viewApiRequest,
 	viewPunishment,
-	viewYoutubeVideo,
-	removeAccount
+	viewYoutubeVideo
 };
 
 const getters = {};
@@ -137,6 +137,9 @@ const mutations = {
 				case "manageStation":
 					store = useManageStationStore({ modalUuid: uuid });
 					break;
+				case "removeAccount":
+					store = useRemoveAccountStore({ modalUuid: uuid });
+					break;
 				default:
 					break;
 			}

+ 0 - 16
frontend/src/store/modules/modals/removeAccount.ts

@@ -1,16 +0,0 @@
-/* eslint no-param-reassign: 0 */
-
-export default {
-	namespaced: true,
-	state: {
-		githubLinkConfirmed: false
-	},
-	actions: {
-		init: ({ commit }, data) => commit("init", data)
-	},
-	mutations: {
-		init(state, { githubLinkConfirmed }) {
-			state.githubLinkConfirmed = githubLinkConfirmed;
-		}
-	}
-};

+ 17 - 0
frontend/src/stores/removeAccount.ts

@@ -0,0 +1,17 @@
+import { defineStore } from "pinia";
+
+// TODO fix/decide eslint rule properly
+// eslint-disable-next-line
+export const useRemoveAccountStore = props => {
+	const { modalUuid } = props;
+	return defineStore(`removeAccount-${modalUuid}`, {
+		state: () => ({
+			githubLinkConfirmed: false
+		}),
+		actions: {
+			init({ githubLinkConfirmed }) {
+				this.githubLinkConfirmed = !!githubLinkConfirmed;
+			}
+		}
+	})();
+};