forked from icssc/AntAlmanac
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
60 changed files
with
2,004 additions
and
1,466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lts/iron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,27 @@ | ||
/** @type {import('eslint').Linter.Config} */ | ||
// @ts-check | ||
|
||
/** | ||
* @type {import('eslint').Linter.Config} | ||
*/ | ||
const config = { | ||
root: true, | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
}, | ||
plugins: [ | ||
'react', | ||
'react-hooks', | ||
'import', | ||
'jsx-a11y', | ||
'@typescript-eslint/eslint-plugin', | ||
], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:react/recommended', | ||
'plugin:react-hooks/recommended', | ||
'plugin:react/jsx-runtime', | ||
'plugin:jsx-a11y/recommended', | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'prettier', | ||
], | ||
rules: { | ||
'import/order': 'error', | ||
}, | ||
env: { | ||
browser: true, | ||
es6: true, | ||
}, | ||
globals: { | ||
React: true, | ||
}, | ||
settings: { | ||
react: { | ||
version: 'detect', | ||
} | ||
}, | ||
ignorePatterns: ['vite.config.ts'], | ||
} | ||
parserOptions: { | ||
project: ['tsconfig.json'], | ||
}, | ||
plugins: ['react', 'react-hooks', 'jsx-a11y'], | ||
extends: [ | ||
'plugin:react/recommended', | ||
'plugin:react-hooks/recommended', | ||
'plugin:react/jsx-runtime', | ||
'plugin:jsx-a11y/recommended', | ||
], | ||
globals: { | ||
React: true, | ||
}, | ||
settings: { | ||
react: { | ||
version: 'detect', | ||
}, | ||
}, | ||
}; | ||
|
||
module.exports = config | ||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import { EventEmitter } from 'events'; | ||
|
||
import { RepeatingCustomEvent, ScheduleCourse } from '@packages/antalmanac-types'; | ||
|
||
import { autoSaveSchedule } from '$actions/AppStoreActions'; | ||
import AppStore from '$stores/AppStore'; | ||
|
||
const MAX_UNSAVED_ACTIONS = 1000; | ||
|
||
export interface UndoAction { | ||
type: 'undoAction'; | ||
} | ||
|
||
export interface AddCourseAction { | ||
type: 'addCourse'; | ||
course: ScheduleCourse; | ||
scheduleIndex: number; | ||
} | ||
|
||
export interface DeleteCourseAction { | ||
type: 'deleteCourse'; | ||
sectionCode: string; | ||
term: string; | ||
} | ||
|
||
export interface AddCustomEventAction { | ||
type: 'addCustomEvent'; | ||
customEvent: RepeatingCustomEvent; | ||
scheduleIndices: number[]; | ||
} | ||
|
||
export interface DeleteCustomEventAction { | ||
type: 'deleteCustomEvent'; | ||
customEventId: number; | ||
} | ||
|
||
export interface EditCustomEventAction { | ||
type: 'editCustomEvent'; | ||
editedCustomEvent: RepeatingCustomEvent; | ||
newScheduleIndices: number[]; | ||
} | ||
|
||
export interface ChangeCustomEventColorAction { | ||
type: 'changeCustomEventColor'; | ||
customEventId: number; | ||
newColor: string; | ||
} | ||
|
||
export interface ClearScheduleAction { | ||
type: 'clearSchedule'; | ||
} | ||
|
||
export interface CopyScheduleAction { | ||
type: 'copySchedule'; | ||
to: number; | ||
} | ||
|
||
export interface ChangeCourseColorAction { | ||
type: 'changeCourseColor'; | ||
sectionCode: string; | ||
term: string; | ||
newColor: string; | ||
} | ||
|
||
export type ActionType = | ||
| AddCourseAction | ||
| DeleteCourseAction | ||
| AddCustomEventAction | ||
| DeleteCustomEventAction | ||
| EditCustomEventAction | ||
| ChangeCustomEventColorAction | ||
| ClearScheduleAction | ||
| CopyScheduleAction | ||
| ChangeCourseColorAction | ||
| UndoAction; | ||
|
||
function parseUnsavedActionsString(unsavedActionsString: string): ActionType[] { | ||
try { | ||
return JSON.parse(unsavedActionsString); | ||
} catch { | ||
return []; | ||
} | ||
} | ||
|
||
class ActionTypesStore extends EventEmitter { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
async autoSaveSchedule(action: ActionType) { | ||
const autoSave = typeof Storage !== 'undefined' && window.localStorage.getItem('autoSave') == 'true'; | ||
if (autoSave) { | ||
const savedUserID = window.localStorage.getItem('userID'); | ||
|
||
if (savedUserID) { | ||
this.emit('autoSaveStart'); | ||
await autoSaveSchedule(savedUserID); | ||
AppStore.unsavedChanges = false; | ||
this.emit('autoSaveEnd'); | ||
} | ||
} else { | ||
const unsavedActionsString = window.localStorage.getItem('unsavedActions'); | ||
if (unsavedActionsString == null) { | ||
const unsavedActions = [action]; | ||
localStorage.setItem('unsavedActions', JSON.stringify(unsavedActions)); | ||
} else { | ||
let unsavedActions = parseUnsavedActionsString(unsavedActionsString); | ||
if (unsavedActions.length > MAX_UNSAVED_ACTIONS) { | ||
unsavedActions = unsavedActions.slice(100); | ||
} | ||
unsavedActions.push(action); | ||
localStorage.setItem('unsavedActions', JSON.stringify(unsavedActions)); | ||
} | ||
} | ||
} | ||
|
||
async loadScheduleFromLocalSave() { | ||
const unsavedActionsString = window.localStorage.getItem('unsavedActions'); | ||
|
||
if (unsavedActionsString == null) return; | ||
if (!confirm('You have unsaved changes. Would you like to load them?')) { | ||
window.localStorage.removeItem('unsavedActions'); | ||
return; | ||
} | ||
|
||
const actions = parseUnsavedActionsString(unsavedActionsString); | ||
|
||
actions.forEach((action) => { | ||
switch (action.type) { | ||
case 'addCourse': | ||
AppStore.schedule.addCourse(action.course, action.scheduleIndex); | ||
break; | ||
case 'deleteCourse': | ||
AppStore.schedule.deleteCourse(action.sectionCode, action.term); | ||
break; | ||
case 'addCustomEvent': | ||
AppStore.schedule.addCustomEvent(action.customEvent, action.scheduleIndices); | ||
break; | ||
case 'deleteCustomEvent': | ||
AppStore.schedule.deleteCustomEvent(action.customEventId); | ||
break; | ||
case 'editCustomEvent': | ||
AppStore.schedule.editCustomEvent(action.editedCustomEvent, action.newScheduleIndices); | ||
break; | ||
case 'changeCustomEventColor': | ||
AppStore.schedule.changeCustomEventColor(action.customEventId, action.newColor); | ||
break; | ||
case 'changeCourseColor': | ||
AppStore.schedule.changeCourseColor(action.sectionCode, action.term, action.newColor); | ||
break; | ||
case 'clearSchedule': | ||
AppStore.schedule.clearCurrentSchedule(); | ||
break; | ||
case 'copySchedule': | ||
AppStore.schedule.copySchedule(action.to); | ||
break; | ||
default: | ||
break; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
const actionTypesStore = new ActionTypesStore(); | ||
export default actionTypesStore; |
Oops, something went wrong.