infrastructure for multiple schedules

This commit is contained in:
Sriram Hariharan
2023-03-10 23:37:57 -06:00
parent f28ab5182c
commit d06b0f9f7a
11 changed files with 113 additions and 40 deletions

14
package-lock.json generated
View File

@@ -9,7 +9,7 @@
"version": "0.0.0",
"dependencies": {
"@types/sql.js": "^1.4.4",
"chrome-extension-toolkit": "^0.0.23",
"chrome-extension-toolkit": "^0.0.32",
"classnames": "^2.3.2",
"clean-webpack-plugin": "^4.0.0",
"highcharts": "^10.3.3",
@@ -4808,9 +4808,9 @@
}
},
"node_modules/chrome-extension-toolkit": {
"version": "0.0.23",
"resolved": "https://registry.npmjs.org/chrome-extension-toolkit/-/chrome-extension-toolkit-0.0.23.tgz",
"integrity": "sha512-Xjj96nyXDbnD/1sCInEW7WtQ+bsOHFXSyjfV5KAUX7IdhhNb0BXfTX4Q7FGh00JhxPW2rUwe0l0u0iYN9GaxZw==",
"version": "0.0.32",
"resolved": "https://registry.npmjs.org/chrome-extension-toolkit/-/chrome-extension-toolkit-0.0.32.tgz",
"integrity": "sha512-0MZFp7MfVVgW1OSZbJD120+21GLS5DFjUG3sAsmAUoPUxbOhmqltGkQT9S23KuipjslcRCwzSlWR+lIkxeXHKw==",
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
@@ -21236,9 +21236,9 @@
}
},
"chrome-extension-toolkit": {
"version": "0.0.23",
"resolved": "https://registry.npmjs.org/chrome-extension-toolkit/-/chrome-extension-toolkit-0.0.23.tgz",
"integrity": "sha512-Xjj96nyXDbnD/1sCInEW7WtQ+bsOHFXSyjfV5KAUX7IdhhNb0BXfTX4Q7FGh00JhxPW2rUwe0l0u0iYN9GaxZw==",
"version": "0.0.32",
"resolved": "https://registry.npmjs.org/chrome-extension-toolkit/-/chrome-extension-toolkit-0.0.32.tgz",
"integrity": "sha512-0MZFp7MfVVgW1OSZbJD120+21GLS5DFjUG3sAsmAUoPUxbOhmqltGkQT9S23KuipjslcRCwzSlWR+lIkxeXHKw==",
"requires": {
"react": "^18.2.0",
"react-dom": "^18.2.0"

View File

@@ -14,7 +14,7 @@
},
"dependencies": {
"@types/sql.js": "^1.4.4",
"chrome-extension-toolkit": "^0.0.23",
"chrome-extension-toolkit": "^0.0.32",
"classnames": "^2.3.2",
"clean-webpack-plugin": "^4.0.0",
"highcharts": "^10.3.3",

View File

@@ -1,4 +1,4 @@
import { createStore } from 'chrome-extension-toolkit';
import { createLocalStore, debugStore } from 'chrome-extension-toolkit';
/**
* A store that is used to store data that is only relevant during development
@@ -16,10 +16,12 @@ interface IDevStore {
reloadTabId?: number;
}
export const DevStore = createStore<IDevStore>('DEV_STORE', {
export const DevStore = createLocalStore<IDevStore>({
debugTabId: undefined,
isTabReloading: true,
wasDebugTabVisible: false,
isExtensionReloading: true,
reloadTabId: undefined,
});
debugStore({ DevStore });

View File

@@ -1,5 +1,5 @@
import { v4 as uuidv4 } from 'uuid';
import { createStore } from 'chrome-extension-toolkit';
import { createLocalStore, debugStore } from 'chrome-extension-toolkit';
/**
* A store that is used for storing user options
@@ -13,19 +13,27 @@ interface IExtensionStore {
deviceId: string;
}
const base = createStore<IExtensionStore>('EXTENSION_STORE', {
version: chrome.runtime.getManifest().version,
lastUpdate: Date.now(),
deviceId: '',
});
interface Actions {
getDeviceId(): Promise<string>;
}
export const ExtensionStore = base.modify({
async getDeviceId() {
const deviceId = await base.getDeviceId();
if (deviceId) {
return deviceId;
}
const newDeviceId = uuidv4();
return newDeviceId;
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 });

View File

@@ -1,4 +1,4 @@
import { createStore } from 'chrome-extension-toolkit';
import { createSyncStore, debugStore } from 'chrome-extension-toolkit';
/**
* A store that is used for storing user options
@@ -10,7 +10,9 @@ interface IOptionsStore {
shouldScrollToLoad: boolean;
}
export const OptionsStore = createStore<IOptionsStore>('OPTIONS_STORE', {
export const OptionsStore = createSyncStore<IOptionsStore>({
shouldHighlightConflicts: true,
shouldScrollToLoad: true,
});
debugStore({ OptionsStore });

View File

@@ -1,15 +1,11 @@
import { createStore, Store } from 'chrome-extension-toolkit';
import { createSessionStore, debugStore } from 'chrome-extension-toolkit';
interface ISessionStore {
chromeSessionId?: string;
}
export const SessionStore = createStore<ISessionStore>(
'SESSION_STORE',
{
chromeSessionId: undefined,
},
{
area: 'session',
}
);
export const SessionStore = createSessionStore<ISessionStore>({
chromeSessionId: undefined,
});
debugStore({ SessionStore });

View File

@@ -0,0 +1,62 @@
import { createLocalStore, debugStore, Serialized } from 'chrome-extension-toolkit';
import { Course } from 'src/shared/types/Course';
/**
* A store that is used for storing user options
*/
interface IUserScheduleStore {
current: string;
schedules: {
[id: string]: Course[];
};
}
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>;
}
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 as Serialized<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 });

View File

@@ -1,3 +1,4 @@
/* eslint-disable max-classes-per-file */
import { Serialized } from 'chrome-extension-toolkit';
import { capitalize } from '../util/string';
import { CourseSchedule } from './CourseSchedule';

View File

@@ -16,7 +16,8 @@
select {
z-index: $MAX_Z_INDEX;
padding: 4px;
border-radius: 12px;
font-family: 'Inter';
border-radius: 8px;
border-color: $charcoal;
}
}

View File

@@ -14,6 +14,7 @@ import {
queryAggregateDistribution,
querySemesterDistribution,
} from 'src/views/lib/database/queryDistribution';
import { bMessenger } from 'src/shared/messages';
import styles from './GradeDistribution.module.scss';
enum DataStatus {

View File

@@ -23,7 +23,7 @@ Last Updated: 03/4/2023
- [ ] Tooltip that says which classes conflict, maybe suggest a different section or time that doesn't conflict
- [ ] import / export schedules from JSON file
- [ ] Search for classes from within extension
- [ ] Grade distribution
- [x] Grade distribution
- [x] Course description
- [x] Highlight and use rich text to make course description more readable
- [ ] calendar
@@ -71,7 +71,7 @@ Last Updated: 03/4/2023
- [ ] polish
- [ ] more 'at a glance info'
- [ ] Rearrange Courses
- [ ] Firefo Support
- [ ] Firefox Support
- [ ] RMP (cumulative score for class based off CIS, RMP, grade dist., etc.)
- [ ] Conflict indicator ( Possible different section? )
- [ ] Compare classes mode