2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-27 10:51:33 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2021-03-23 20:50:34 +00:00
|
|
|
import { files } from 'browser';
|
2018-11-05 15:26:18 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
|
2020-11-16 15:16:51 +00:00
|
|
|
import { AccessGrantsApiGql } from '@/api/accessGrants';
|
2019-10-29 14:24:16 +00:00
|
|
|
import { AuthHttpApi } from '@/api/auth';
|
2019-08-21 15:07:49 +01:00
|
|
|
import { BucketsApiGql } from '@/api/buckets';
|
2019-10-23 18:33:24 +01:00
|
|
|
import { PaymentsHttpApi } from '@/api/payments';
|
2019-08-20 13:57:43 +01:00
|
|
|
import { ProjectMembersApiGql } from '@/api/projectMembers';
|
2019-09-09 11:33:39 +01:00
|
|
|
import { ProjectsApiGql } from '@/api/projects';
|
2019-11-06 12:27:26 +00:00
|
|
|
import { notProjectRelatedRoutes, router } from '@/router';
|
2020-11-16 15:16:51 +00:00
|
|
|
import { AccessGrantsState, makeAccessGrantsModule } from '@/store/modules/accessGrants';
|
2019-09-09 11:33:39 +01:00
|
|
|
import { appStateModule } from '@/store/modules/appState';
|
2019-08-21 15:07:49 +01:00
|
|
|
import { makeBucketsModule } from '@/store/modules/buckets';
|
2019-11-06 12:27:26 +00:00
|
|
|
import { makeNotificationsModule, NotificationsState } from '@/store/modules/notifications';
|
2021-03-18 18:09:04 +00:00
|
|
|
import { makeObjectsModule, ObjectsState } from '@/store/modules/objects';
|
2019-11-06 12:27:26 +00:00
|
|
|
import { makePaymentsModule, PaymentsState } from '@/store/modules/payments';
|
|
|
|
import { makeProjectMembersModule, ProjectMembersState } from '@/store/modules/projectMembers';
|
2021-07-27 16:32:47 +01:00
|
|
|
import { makeProjectsModule, PROJECTS_MUTATIONS, ProjectsState } from '@/store/modules/projects';
|
2020-02-27 18:28:11 +00:00
|
|
|
import { makeUsersModule } from '@/store/modules/users';
|
2019-11-06 12:27:26 +00:00
|
|
|
import { User } from '@/types/users';
|
2018-11-26 15:57:11 +00:00
|
|
|
|
2021-10-14 14:28:55 +01:00
|
|
|
import { MetaUtils } from '@/utils/meta';
|
|
|
|
import internalFiles from '@/store/modules/files';
|
|
|
|
import * as externalBrowser from 'browser';
|
|
|
|
const files = MetaUtils.getMetaContent('new-browser') === "true" ? internalFiles : externalBrowser.files;
|
|
|
|
|
2018-11-05 15:26:18 +00:00
|
|
|
Vue.use(Vuex);
|
|
|
|
|
2021-08-25 09:41:05 +01:00
|
|
|
type Mutation<State> =
|
|
|
|
(state: State, ...args: any[]) => any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
|
|
|
|
|
|
type Action<Context> =
|
|
|
|
(context: Context, ...args: any[]) => (Promise<any> | void | any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
|
|
|
|
|
|
type Getter<State, Context> =
|
|
|
|
Context extends {rootGetters: any} ? ( // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
|
|
((state: State) => any) | // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
|
|
((state: State, rootGetters: Context["rootGetters"]) => any) // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
|
|
) : ((state: State) => any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
|
|
|
|
|
|
export interface StoreModule<State, Context> { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
|
|
state: State;
|
|
|
|
mutations: Record<string, Mutation<State>>
|
|
|
|
actions: Record<string, Action<Context>>
|
|
|
|
getters?: Record<string, Getter<State, Context>>
|
2019-08-14 19:11:18 +01:00
|
|
|
}
|
|
|
|
|
2019-08-19 19:12:23 +01:00
|
|
|
// TODO: remove it after we will use modules as classes and use some DI framework
|
2019-10-29 14:24:16 +00:00
|
|
|
const authApi = new AuthHttpApi();
|
2020-11-16 15:16:51 +00:00
|
|
|
const accessGrantsApi = new AccessGrantsApiGql();
|
2019-08-21 15:07:49 +01:00
|
|
|
const bucketsApi = new BucketsApiGql();
|
2019-08-20 13:57:43 +01:00
|
|
|
const projectMembersApi = new ProjectMembersApiGql();
|
2019-08-22 17:03:13 +01:00
|
|
|
const projectsApi = new ProjectsApiGql();
|
2019-10-23 18:33:24 +01:00
|
|
|
const paymentsApi = new PaymentsHttpApi();
|
2019-08-14 19:11:18 +01:00
|
|
|
|
2021-08-05 12:07:45 +01:00
|
|
|
export interface ModulesState {
|
|
|
|
notificationsModule: NotificationsState;
|
|
|
|
accessGrantsModule: AccessGrantsState;
|
|
|
|
appStateModule: typeof appStateModule.state;
|
|
|
|
projectMembersModule: ProjectMembersState;
|
|
|
|
paymentsModule: PaymentsState;
|
|
|
|
usersModule: User;
|
|
|
|
projectsModule: ProjectsState;
|
|
|
|
objectsModule: ObjectsState;
|
2021-10-14 14:28:55 +01:00
|
|
|
files: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
2019-11-06 12:27:26 +00:00
|
|
|
}
|
|
|
|
|
2018-11-27 13:14:10 +00:00
|
|
|
// Satellite store (vuex)
|
2019-11-06 12:27:26 +00:00
|
|
|
export const store = new Vuex.Store<ModulesState>({
|
2019-02-20 13:33:56 +00:00
|
|
|
modules: {
|
2019-08-21 14:21:23 +01:00
|
|
|
notificationsModule: makeNotificationsModule(),
|
2020-11-16 15:16:51 +00:00
|
|
|
accessGrantsModule: makeAccessGrantsModule(accessGrantsApi),
|
2019-08-20 13:57:43 +01:00
|
|
|
appStateModule,
|
|
|
|
projectMembersModule: makeProjectMembersModule(projectMembersApi),
|
2019-10-23 18:33:24 +01:00
|
|
|
paymentsModule: makePaymentsModule(paymentsApi),
|
2019-10-29 14:24:16 +00:00
|
|
|
usersModule: makeUsersModule(authApi),
|
2019-08-22 17:03:13 +01:00
|
|
|
projectsModule: makeProjectsModule(projectsApi),
|
2019-08-21 15:07:49 +01:00
|
|
|
bucketUsageModule: makeBucketsModule(bucketsApi),
|
2021-03-18 18:09:04 +00:00
|
|
|
objectsModule: makeObjectsModule(),
|
2021-03-23 20:50:34 +00:00
|
|
|
files,
|
2019-09-13 15:58:18 +01:00
|
|
|
},
|
2018-11-05 15:26:18 +00:00
|
|
|
});
|
2019-11-06 12:27:26 +00:00
|
|
|
|
|
|
|
store.subscribe((mutation, state) => {
|
|
|
|
const currentRouteName = router.currentRoute.name;
|
|
|
|
const satelliteName = state.appStateModule.satelliteName;
|
|
|
|
|
|
|
|
switch (mutation.type) {
|
2021-08-02 19:17:49 +01:00
|
|
|
case PROJECTS_MUTATIONS.REMOVE:
|
|
|
|
document.title = `${router.currentRoute.name} | ${satelliteName}`;
|
2019-11-06 12:27:26 +00:00
|
|
|
|
2021-08-02 19:17:49 +01:00
|
|
|
break;
|
|
|
|
case PROJECTS_MUTATIONS.SELECT_PROJECT:
|
|
|
|
if (currentRouteName && !notProjectRelatedRoutes.includes(currentRouteName)) {
|
|
|
|
document.title = `${state.projectsModule.selectedProject.name} | ${currentRouteName} | ${satelliteName}`;
|
|
|
|
}
|
2019-11-06 12:27:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default store;
|