multiple schedule suppport kinda
This commit is contained in:
@@ -16,7 +16,7 @@ interface IDevStore {
|
||||
reloadTabId?: number;
|
||||
}
|
||||
|
||||
export const DevStore = createLocalStore<IDevStore>({
|
||||
export const devStore = createLocalStore<IDevStore>({
|
||||
debugTabId: undefined,
|
||||
isTabReloading: true,
|
||||
wasDebugTabVisible: false,
|
||||
@@ -24,5 +24,4 @@ export const DevStore = createLocalStore<IDevStore>({
|
||||
reloadTabId: undefined,
|
||||
});
|
||||
|
||||
|
||||
debugStore({ DevStore });
|
||||
debugStore({ devStore });
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { createLocalStore, debugStore } from 'chrome-extension-toolkit';
|
||||
|
||||
/**
|
||||
@@ -9,31 +8,11 @@ interface IExtensionStore {
|
||||
version: string;
|
||||
/** When was the last update */
|
||||
lastUpdate: number;
|
||||
/** A unique identifier generated for the current user in lieu of a userId */
|
||||
deviceId: string;
|
||||
}
|
||||
|
||||
interface Actions {
|
||||
getDeviceId(): Promise<string>;
|
||||
}
|
||||
export const extensionStore = createLocalStore<IExtensionStore>({
|
||||
version: chrome.runtime.getManifest().version,
|
||||
lastUpdate: Date.now(),
|
||||
});
|
||||
|
||||
export const ExtensionStore = createLocalStore<IExtensionStore, Actions>(
|
||||
{
|
||||
version: chrome.runtime.getManifest().version,
|
||||
lastUpdate: Date.now(),
|
||||
deviceId: '',
|
||||
},
|
||||
store => ({
|
||||
getDeviceId: async () => {
|
||||
const deviceId = await store.getDeviceId();
|
||||
if (deviceId) {
|
||||
return deviceId;
|
||||
}
|
||||
const newDeviceId = uuidv4();
|
||||
await store.setDeviceId(newDeviceId);
|
||||
return newDeviceId;
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
debugStore({ ExtensionStore });
|
||||
debugStore({ extensionStore });
|
||||
|
||||
@@ -10,9 +10,9 @@ interface IOptionsStore {
|
||||
shouldScrollToLoad: boolean;
|
||||
}
|
||||
|
||||
export const OptionsStore = createSyncStore<IOptionsStore>({
|
||||
export const optionsStore = createSyncStore<IOptionsStore>({
|
||||
shouldHighlightConflicts: true,
|
||||
shouldScrollToLoad: true,
|
||||
});
|
||||
|
||||
debugStore({ OptionsStore });
|
||||
debugStore({ optionsStore });
|
||||
|
||||
@@ -4,8 +4,8 @@ interface ISessionStore {
|
||||
chromeSessionId?: string;
|
||||
}
|
||||
|
||||
export const SessionStore = createSessionStore<ISessionStore>({
|
||||
export const sessionStore = createSessionStore<ISessionStore>({
|
||||
chromeSessionId: undefined,
|
||||
});
|
||||
|
||||
debugStore({ SessionStore });
|
||||
debugStore({ sessionStore });
|
||||
|
||||
@@ -1,62 +1,15 @@
|
||||
import { createLocalStore, debugStore } from 'chrome-extension-toolkit';
|
||||
import { Course } from 'src/shared/types/Course';
|
||||
/**
|
||||
* A store that is used for storing user options
|
||||
*/
|
||||
import { UserSchedule } from 'src/shared/types/UserSchedule';
|
||||
|
||||
interface IUserScheduleStore {
|
||||
current: string;
|
||||
schedules: {
|
||||
[id: string]: Course[];
|
||||
};
|
||||
schedules: UserSchedule[];
|
||||
}
|
||||
|
||||
interface Actions {
|
||||
createSchedule(name: string): Promise<void>;
|
||||
addCourseToSchedule(name: string, course: Course): Promise<void>;
|
||||
removeCourseFromSchedule(name: string, course: Course): Promise<void>;
|
||||
removeSchedule(name: string): Promise<void>;
|
||||
getSchedule(name: string): Promise<Course[] | undefined>;
|
||||
}
|
||||
/**
|
||||
* A store that is used for storing user schedules (and the active schedule)
|
||||
*/
|
||||
export const userScheduleStore = createLocalStore<IUserScheduleStore>({
|
||||
schedules: [],
|
||||
});
|
||||
|
||||
const UserScheduleStore = createLocalStore<IUserScheduleStore, Actions>(
|
||||
{
|
||||
current: 'Schedule 1',
|
||||
schedules: {},
|
||||
},
|
||||
store => ({
|
||||
async createSchedule(name: string) {
|
||||
const schedules = await store.getSchedules();
|
||||
if (!schedules[name]) {
|
||||
schedules[name] = [];
|
||||
await store.setSchedules(schedules as any);
|
||||
}
|
||||
},
|
||||
async removeSchedule(name: string) {
|
||||
const schedules = await store.getSchedules();
|
||||
delete schedules[name];
|
||||
await store.setSchedules(schedules);
|
||||
},
|
||||
async getSchedule(name) {
|
||||
const schedules = await store.getSchedules();
|
||||
return schedules[name]?.map(course => new Course(course));
|
||||
},
|
||||
async addCourseToSchedule(name, course) {
|
||||
const schedules = await store.getSchedules();
|
||||
const scheduleToEdit = schedules[name];
|
||||
if (scheduleToEdit) {
|
||||
scheduleToEdit.push(course);
|
||||
await store.setSchedules(schedules);
|
||||
}
|
||||
},
|
||||
async removeCourseFromSchedule(name, course) {
|
||||
const schedules = await store.getSchedules();
|
||||
const scheduleToEdit = schedules[name];
|
||||
if (scheduleToEdit) {
|
||||
schedules[name] = scheduleToEdit.filter(c => c.uniqueId !== course.uniqueId);
|
||||
await store.setSchedules(schedules);
|
||||
}
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
debugStore({ UserScheduleStore });
|
||||
debugStore({ userScheduleStore });
|
||||
|
||||
Reference in New Issue
Block a user