This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Dlurak/timetable
Timetables
- Loading branch information
Showing
24 changed files
with
661 additions
and
89 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 @@ | ||
export const weekdays = ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su'] as const; | ||
export const emptyTimeTable = { | ||
mo: [], | ||
tu: [], | ||
we: [], | ||
th: [], | ||
fr: [], | ||
sa: [], | ||
su: [] | ||
} as TimeTable; | ||
|
||
export type WeekDay = (typeof weekdays)[number]; | ||
|
||
export type TimeTable = { | ||
[day in WeekDay]: string[]; | ||
}; |
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
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
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,49 @@ | ||
export const selectFile = async (accept: string) => { | ||
const input = document.createElement('input'); | ||
input.type = 'file'; | ||
input.accept = accept; | ||
|
||
return new Promise<File | undefined>((resolve, reject) => { | ||
input.onchange = async () => { | ||
const files = input.files; | ||
if (!files) { | ||
reject('No file selected'); | ||
return; | ||
} | ||
const file = files[0]; | ||
if (!file) { | ||
reject('No file selected'); | ||
return; | ||
} | ||
|
||
resolve(file); | ||
}; | ||
input.click(); | ||
}); | ||
}; | ||
|
||
export const readFileContent = (file: File): Promise<string> => { | ||
const reader = new FileReader(); | ||
return new Promise((resolve, reject) => { | ||
reader.onload = (event) => { | ||
const result = event.target?.result; | ||
if (typeof result !== 'string') { | ||
reject('Could not read file'); | ||
return; | ||
} | ||
resolve(result); | ||
}; | ||
reader.onerror = (error) => reject(error); | ||
reader.readAsText(file); | ||
}); | ||
}; | ||
|
||
export const getFile = async (accept: string) => { | ||
const file = await selectFile(accept).catch(() => undefined); | ||
if (!file) { | ||
return; | ||
} | ||
const content = await readFileContent(file); | ||
|
||
return { file, content }; | ||
}; |
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,15 @@ | ||
type ObjectOf<T> = Record<string | number | symbol, T>; | ||
|
||
/** | ||
* Map over the values of an object, returning a new object with the same keys | ||
* and mapped values. | ||
*/ | ||
export const mapValues = <T, U>(object: ObjectOf<T>, fn: (value: T) => U) => { | ||
// iterate over the keys of the object | ||
const newObject: ObjectOf<U> = {}; | ||
for (const key of Object.keys(object)) { | ||
const mappedValue = fn(object[key]); | ||
newObject[key] = mappedValue; | ||
} | ||
return newObject; | ||
}; |
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
Oops, something went wrong.