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
|
|
|
|
2018-11-05 15:26:18 +00:00
|
|
|
Vue.use(Vuex);
|
|
|
|
|
2019-08-14 19:11:18 +01:00
|
|
|
export class StoreModule<S> {
|
|
|
|
public state: S;
|
|
|
|
public mutations: any;
|
|
|
|
public actions: any;
|
2019-08-19 19:12:23 +01:00
|
|
|
public getters?: any;
|
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
|
|
|
|
2019-11-06 12:27:26 +00:00
|
|
|
class ModulesState {
|
|
|
|
public notificationsModule: NotificationsState;
|
2020-11-16 15:16:51 +00:00
|
|
|
public accessGrantsModule: AccessGrantsState;
|
2019-11-06 12:27:26 +00:00
|
|
|
public appStateModule;
|
|
|
|
public projectMembersModule: ProjectMembersState;
|
|
|
|
public paymentsModule: PaymentsState;
|
|
|
|
public usersModule: User;
|
|
|
|
public projectsModule: ProjectsState;
|
2021-03-18 18:09:04 +00:00
|
|
|
public objectsModule: ObjectsState;
|
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;
|