Skip to content

Commit

Permalink
Add option to add a location to non-class activities (#43)
Browse files Browse the repository at this point in the history
closes #12
  • Loading branch information
kierajreed authored Aug 30, 2023
1 parent 23d0b38 commit e5b59dc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
beautifulsoup4==4.11.1
lxml==4.9.1
lxml==4.9.3
requests==2.27.1
2 changes: 1 addition & 1 deletion scrapers/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def run():
courses[course].update(info)

term_info = utils.get_term_info()
now = datetime.datetime.now().strftime("%Y-%m-%d %l:%M %p")
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
obj = {
"termInfo": term_info,
"lastUpdated": now,
Expand Down
33 changes: 32 additions & 1 deletion src/components/ActivityButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,12 @@ export function NonClassButtons(props: { activity: NonClass; state: State }) {

const isSelected = state.isSelectedActivity(activity);
const [isRenaming, setIsRenaming] = useState(false);
const [name, setName] = useState(activity.name);
const [isRelocating, setIsRelocating] = useState(false);
const [showColors, setShowColors] = useState(false);

const [name, setName] = useState(activity.name);
const [room, setRoom] = useState(activity.room);

const [renderHeading, renderButtons] = (() => {
if (isRenaming) {
const renderHeading = () => (
Expand All @@ -312,19 +315,47 @@ export function NonClassButtons(props: { activity: NonClass; state: State }) {
</>
);
return [renderHeading, renderButtons];
} else if(isRelocating) {
const renderHeading = () => (
<Input
value={room}
onChange={(e) => setRoom(e.target.value)}
fontWeight="bold"
placeholder="room"
/>
);
const onConfirm = () => {
state.relocateNonClass(activity, room);
setIsRelocating(false);
};
const onCancel = () => {
setIsRelocating(false);
};
const renderButtons = () => (
<>
<Button onClick={onConfirm}>Confirm</Button>
<Button onClick={onCancel}>Cancel</Button>
</>
);
return [renderHeading, renderButtons];
}

const renderHeading = () => <Heading size="sm">{activity.name}</Heading>;
const onRename = () => {
setName(activity.name);
setIsRenaming(true);
};
const onRelocate = () => {
setRoom(activity.room);
setIsRelocating(true);
};
const renderButtons = () => (
<>
<Button onClick={() => state.toggleActivity(activity)}>
{isSelected ? "Remove activity" : "Add activity"}
</Button>
<Button onClick={onRename}>Rename activity</Button>
<Button onClick={onRelocate}>Edit location</Button>
{isSelected && (
<ToggleButton
active={showColors}
Expand Down
7 changes: 5 additions & 2 deletions src/lib/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class NonClass {
/** Is the color set by the user (as opposed to chosen automatically?) */
manualColor: boolean = false;
timeslots: Array<Timeslot> = [];
room: string | undefined = undefined;

constructor(colorScheme: ColorScheme) {
this.id = nanoid(8);
Expand All @@ -137,7 +138,7 @@ export class NonClass {

/** Get all calendar events corresponding to this activity. */
get events(): Array<Event> {
return [new Event(this, this.name, this.timeslots)];
return [new Event(this, this.name, this.timeslots, this.room)];
}

/**
Expand Down Expand Up @@ -168,17 +169,19 @@ export class NonClass {
]),
this.name,
this.backgroundColor,
this.room ?? "",
];
return res;
}

/** Inflate a non-class activity with info from the output of deflate. */
inflate(parsed: Array<Array<RawTimeslot> | string>): void {
const [timeslots, name, backgroundColor] = parsed;
const [timeslots, name, backgroundColor, room] = parsed;
this.timeslots = (timeslots as Array<RawTimeslot>).map(
(slot) => new Timeslot(...slot)
);
this.name = name as string;
this.room = room=="" ? undefined : room as string;
if (backgroundColor) {
this.manualColor = true;
this.backgroundColor = backgroundColor as string;
Expand Down
9 changes: 9 additions & 0 deletions src/lib/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ export class State {
this.updateState();
}

/** Changes the room for a given non-class. */
relocateNonClass(nonClass: NonClass, room: string | undefined): void {
const nonClass_ = this.selectedNonClasses.find(
(nonClass_) => nonClass_.id === nonClass.id
)!;
nonClass_.room = room;
this.updateState();
}

/** Add the timeslot to currently viewed activity. */
addTimeslot(nonClass: NonClass, slot: Timeslot): void {
nonClass.addTimeslot(slot);
Expand Down

0 comments on commit e5b59dc

Please sign in to comment.