Skip to content

Commit

Permalink
feat: autoimport pinia module
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjackwills committed May 11, 2023
1 parent d4430a6 commit 379d1e6
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 44 deletions.
14 changes: 7 additions & 7 deletions src/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
export {}
declare global {
const EffectScope: typeof import('vue')['EffectScope']
const aircraftModule: typeof import('./store/index')['aircraftModule']
const aircraftModule: typeof import('./store/aircraft')['aircraftModule']
const computed: typeof import('vue')['computed']
const createApp: typeof import('vue')['createApp']
const customRef: typeof import('vue')['customRef']
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
const defineComponent: typeof import('vue')['defineComponent']
const dialogModule: typeof import('./store/index')['dialogModule']
const dialogModule: typeof import('./store/dialog')['dialogModule']
const effectScope: typeof import('vue')['effectScope']
const flightboxStatusModule: typeof import('./store/index')['flightboxStatusModule']
const flightboxStatusModule: typeof import('./store/flightboxStatus')['flightboxStatusModule']
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
const getCurrentScope: typeof import('vue')['getCurrentScope']
const h: typeof import('vue')['h']
Expand All @@ -22,7 +22,7 @@ declare global {
const isReactive: typeof import('vue')['isReactive']
const isReadonly: typeof import('vue')['isReadonly']
const isRef: typeof import('vue')['isRef']
const loadingModule: typeof import('./store/index')['loadingModule']
const loadingModule: typeof import('./store/loading')['loadingModule']
const markRaw: typeof import('vue')['markRaw']
const nextTick: typeof import('vue')['nextTick']
const onActivated: typeof import('vue')['onActivated']
Expand All @@ -48,7 +48,7 @@ declare global {
const shallowReactive: typeof import('vue')['shallowReactive']
const shallowReadonly: typeof import('vue')['shallowReadonly']
const shallowRef: typeof import('vue')['shallowRef']
const snackbarModule: typeof import('./store/index')['snackbarModule']
const snackbarModule: typeof import('./store/snackbar')['snackbarModule']
const toRaw: typeof import('vue')['toRaw']
const toRef: typeof import('vue')['toRef']
const toRefs: typeof import('vue')['toRefs']
Expand All @@ -61,12 +61,12 @@ declare global {
const useRoute: typeof import('vue-router')['useRoute']
const useRouter: typeof import('vue-router')['useRouter']
const useSlots: typeof import('vue')['useSlots']
const userModule: typeof import('./store/index')['userModule']
const userModule: typeof import('./store/user')['userModule']
const watch: typeof import('vue')['watch']
const watchEffect: typeof import('vue')['watchEffect']
const watchPostEffect: typeof import('vue')['watchPostEffect']
const watchSyncEffect: typeof import('vue')['watchSyncEffect']
const websocketModule: typeof import('./store/index')['websocketModule']
const websocketModule: typeof import('./store/websocket')['websocketModule']
}
// for type re-export
declare global {
Expand Down
1 change: 0 additions & 1 deletion src/services/WS.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { env } from '@/vanillaTS/env';
import { userModule } from '@/store';

export class CreateWs {
#ws?: WebSocket;
Expand Down
1 change: 0 additions & 1 deletion src/services/axios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { env } from '@/vanillaTS/env';
import { snackError, snackReset } from './snack';
import { userModule, websocketModule } from '@/store';
import Axios, { AxiosError, type AxiosInstance } from 'axios';

// Some kind of dirty work around for strict axios typing?
Expand Down
1 change: 0 additions & 1 deletion src/services/snack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { mdiAlertCircle, mdiCheckCircleOutline } from '@mdi/js';
import { snackbarModule } from '@/store';
import type { TSnack } from '@/types';

export const snackSuccess = async ({ message = 'Success', icon = mdiCheckCircleOutline, timeout=5000, loading=false }: TSnack): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/aircraft.ts → src/store/aircraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineStore } from 'pinia';
import { ModuleName } from '@/types/enum_module';
import type { TAdsbdb } from '@/types';

export const aircraftStore = defineStore(ModuleName.AIRCRAFT, {
export const aircraftModule = defineStore(ModuleName.AIRCRAFT, {

state: () => ({
_current_flights: [] as Array<TAdsbdb>,
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/dialog.ts → src/store/dialog.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import { ModuleName } from '@/types/enum_module';

export const dialogStore = defineStore(ModuleName.DIALOG, {
export const dialogModule = defineStore(ModuleName.DIALOG, {

state: () => ({
imgSrc: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import { ModuleName } from '@/types/enum_module';

export const flightboxStatusStore = defineStore(ModuleName.FLIGHTBOX_STATUS, {
export const flightboxStatusModule = defineStore(ModuleName.FLIGHTBOX_STATUS, {

state: () => ({
api_version: '',
Expand Down
15 changes: 0 additions & 15 deletions src/store/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/store/modules/loading.ts → src/store/loading.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import { ModuleName } from '@/types/enum_module';

export const loadingStore = defineStore(ModuleName.LOADING, {
export const loadingModule = defineStore(ModuleName.LOADING, {

state: () => ({
loading: false,
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/snackbar.ts → src/store/snackbar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import { ModuleName } from '@/types/enum_module';

export const snackbarStore = defineStore(ModuleName.SNACKBAR, {
export const snackbarModule = defineStore(ModuleName.SNACKBAR, {

state: () => ({
icon: '',
Expand Down
22 changes: 11 additions & 11 deletions src/store/modules/user.ts → src/store/user.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { aircraftStore } from './aircraft';
import { aircraftModule } from './aircraft';
import { defineStore } from 'pinia';
import { dialogStore } from './dialog';
import { flightboxStatusStore } from './flightboxStatus';
import { loadingStore } from './loading';
import { dialogModule } from './dialog';
import { flightboxStatusModule } from './flightboxStatus';
import { loadingModule } from './loading';
import { ModuleName } from '@/types/enum_module';
import { snackError } from '@/services/snack';
import { websocketStore } from './websocket';
import { websocketModule } from './websocket';
// import { useRoute, useRouter } from 'vue-router';
import { getActivePinia } from 'pinia';
import { FrontendRoutes } from '@/types/enum_routes';

export const userStore = defineStore(ModuleName.USER, {
export const userModule = defineStore(ModuleName.USER, {

state: () => ({
authenticated: false,
Expand All @@ -19,11 +19,11 @@ export const userStore = defineStore(ModuleName.USER, {
actions: {
logout (message?: string): void {
this.authenticated = false;
loadingStore().set_loading(false);
flightboxStatusStore().$reset();
aircraftStore().$reset();
websocketStore().closeWS();
dialogStore().$reset();
loadingModule().set_loading(false);
flightboxStatusModule().$reset();
aircraftModule().$reset();
websocketModule().closeWS();
dialogModule().$reset();
if (message) snackError({ message });
getActivePinia()?.router().push(FrontendRoutes.LOGIN);
},
Expand Down
6 changes: 3 additions & 3 deletions src/store/modules/websocket.ts → src/store/websocket.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { defineStore } from 'pinia';
import { ModuleName } from '@/types/enum_module';
import { userStore } from './user';
import { userModule } from './user';

import type { TWSToServer } from '@/types';
import { ws } from '@/services/WS';

export const websocketStore = defineStore(ModuleName.WEBSOCKET, {
export const websocketModule = defineStore(ModuleName.WEBSOCKET, {

state: () => ({
connected: false
Expand All @@ -19,7 +19,7 @@ export const websocketStore = defineStore(ModuleName.WEBSOCKET, {
},

openWs (password: string): void {
const user_store = userStore();
const user_store = userModule();
if (!user_store.authenticated) return;
ws.openWs(password);
ws.connection?.addEventListener('open', () => {
Expand Down

0 comments on commit 379d1e6

Please sign in to comment.