Skip to content

Commit

Permalink
feat(import): import assignment points to notion (#61)
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 4e08990
Author: James <james@jamesnzl.xyz>
Date:   Thu Jul 21 01:29:48 2022 +1200

    feat(import): :sparkles: import assignment points

commit 801a93f
Author: James <james@jamesnzl.xyz>
Date:   Thu Jul 21 01:21:01 2022 +1200

    feat(options): :sparkles: add points property option
  • Loading branch information
JamesNZL committed Jul 20, 2022
1 parent 7d94e7e commit 5154f75
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/apis/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export const Storage = <const>{
category: savedFields['notion.propertyNames.category'],
course: savedFields['notion.propertyNames.course'],
url: savedFields['notion.propertyNames.url'],
points: savedFields['notion.propertyNames.points'],
available: savedFields['notion.propertyNames.available'],
due: savedFields['notion.propertyNames.due'],
span: savedFields['notion.propertyNames.span'],
Expand Down
12 changes: 12 additions & 0 deletions src/options/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ interface InputElements {
'notion.propertyNames.category': 'notion-property-category';
'notion.propertyNames.course': 'notion-property-course';
'notion.propertyNames.url': 'notion-property-url';
'notion.propertyNames.points': 'notion-property-points';
'notion.propertyNames.available': 'notion-property-available';
'notion.propertyNames.due': 'notion-property-due';
'notion.propertyNames.span': 'notion-property-span';
Expand Down Expand Up @@ -269,6 +270,7 @@ export const CONFIGURATION: {
'notion-property-category',
'notion-property-course',
'notion-property-url',
'notion-property-points',
'notion-property-available',
'notion-property-due',
'notion-property-span',
Expand Down Expand Up @@ -317,6 +319,16 @@ export const CONFIGURATION: {
});
},
},
points: {
defaultValue: 'Points',
get input() {
delete (<Partial<typeof this>>this).input;
return this.input = Input.getInstance<InputElementId>({
id: 'notion-property-points',
Validator: StringField,
});
},
},
available: {
defaultValue: 'Reminder',
get input() {
Expand Down
5 changes: 5 additions & 0 deletions src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ <h3 class='hidden'>Property Names</h3>
<select id='notion-property-url' name='notion-property-url' class='row'></select>
</div>

<div class='hidden'>
<label for='notion-property-points'>Points property (<a target='_blank' href='https://www.notion.so/help/database-properties'><code>Number</code></a>)</label>
<select id='notion-property-points' name='notion-property-points' class='row'></select>
</div>

<div class='hidden'>
<label for='notion-property-available'>Unlock date property (<a target='_blank' href='https://www.notion.so/help/database-properties'><code>Date</code></a>)</label>
<select id='notion-property-available' name='notion-property-available' class='row'></select>
Expand Down
8 changes: 8 additions & 0 deletions src/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface OptionsElements {
categoryProperty: 'notion-property-category';
courseProperty: 'notion-property-course';
urlProperty: 'notion-property-url';
pointsProperty: 'notion-property-points';
availableProperty: 'notion-property-available';
dueProperty: 'notion-property-due';
spanProperty: 'notion-property-span';
Expand Down Expand Up @@ -163,6 +164,12 @@ const DatabaseSelect = <const>{
Validator: StringField,
fieldKey: 'notion.propertyNames.url',
}),
points: PropertySelect.getInstance<OptionsSelectId>({
id: 'notion-property-points',
type: 'number',
Validator: StringField,
fieldKey: 'notion.propertyNames.points',
}),
available: PropertySelect.getInstance<OptionsSelectId>({
id: 'notion-property-available',
type: 'date',
Expand Down Expand Up @@ -265,6 +272,7 @@ const buttons: {
'notion.propertyNames.category',
'notion.propertyNames.course',
'notion.propertyNames.url',
'notion.propertyNames.points',
'notion.propertyNames.available',
'notion.propertyNames.due',
'notion.propertyNames.span',
Expand Down
1 change: 0 additions & 1 deletion src/popup/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ function roundToNextHour(date: Date): Date {
.map(assignment => ({
name: assignment.name,
description: assignment.description,
// TODO(main): normalise this as a percentage of total points?
points: assignment.points_possible,
course: courseCode,
icon: courseIcon,
Expand Down
3 changes: 3 additions & 0 deletions src/popup/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export async function exportToNotion(): Promise<void | IFetchedAssignment[]> {
[options.propertyNames.url ?? EMPTY_PROPERTY]: {
url: this.url,
},
[options.propertyNames.points ?? EMPTY_PROPERTY]: {
number: this.points ?? 0,
},
[options.propertyNames.available ?? EMPTY_PROPERTY]: {
date: {
start: this.available,
Expand Down
2 changes: 2 additions & 0 deletions src/types/storage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface OptionalFields {
'notion.propertyNames.category': NullIfEmpty<string>;
'notion.propertyNames.course': NullIfEmpty<string>;
'notion.propertyNames.url': NullIfEmpty<string>;
'notion.propertyNames.points': NullIfEmpty<string>;
'notion.propertyNames.available': NullIfEmpty<string>;
'notion.propertyNames.due': NullIfEmpty<string>;
'notion.propertyNames.span': NullIfEmpty<string>;
Expand Down Expand Up @@ -60,6 +61,7 @@ export type SavedOptions = {
category: OptionalFields['notion.propertyNames.category'];
course: OptionalFields['notion.propertyNames.course'];
url: OptionalFields['notion.propertyNames.url'];
points: OptionalFields['notion.propertyNames.points'];
available: OptionalFields['notion.propertyNames.available'];
due: OptionalFields['notion.propertyNames.due'];
span: OptionalFields['notion.propertyNames.span'];
Expand Down

0 comments on commit 5154f75

Please sign in to comment.