Skip to content

Commit 2eedea2

Browse files
committed
Add checkbox for remote/onsite
1 parent 5cb1ec0 commit 2eedea2

3 files changed

Lines changed: 81 additions & 11 deletions

File tree

frontend/src/components/TalkList.tsx

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { computed } from "@preact/signals";
22
import { useState } from "preact/hooks";
33
import { talks, currentTimeSecs, sendCommand, currentUser } from "../store";
44
import { TalkCard } from "./TalkCard";
5-
import { type Talk } from "../types";
5+
import { AttendanceMode, type Talk } from "../types";
66

77
export function TalkList() {
88
const user = currentUser.value!;
@@ -115,20 +115,72 @@ function Section({
115115
}
116116

117117
function Header() {
118+
const user = currentUser.value;
119+
const isRemote = user?.attendance_mode === AttendanceMode.Remote;
120+
121+
const toggleMode = (e: Event) => {
122+
const checked = (e.currentTarget as HTMLInputElement).checked;
123+
const newMode = checked ? AttendanceMode.Remote : AttendanceMode.OnSite;
124+
125+
sendCommand({
126+
SetAttendanceMode: { attendance_mode: newMode },
127+
});
128+
};
129+
118130
return (
119131
<div class="title">
120132
<h1>MOPAD</h1>
121-
<a
122-
class="calendar"
123-
href="#calendar"
124-
onClick={(e) => {
125-
e.preventDefault();
126-
const dialog = document.querySelector(".calendar-dialog");
127-
dialog?.classList.add("open");
133+
134+
{/* Wrapper to group right-aligned elements */}
135+
<div
136+
style={{
137+
justifySelf: "end",
138+
display: "flex",
139+
flexDirection: "column",
140+
alignItems: "flex-end",
141+
gap: "0.5rem",
128142
}}
129143
>
130-
Subscribe as calendar
131-
</a>
144+
<a
145+
class="calendar"
146+
href="#calendar"
147+
onClick={(e) => {
148+
e.preventDefault();
149+
const dialog = document.querySelector(".calendar-dialog");
150+
dialog?.classList.add("open");
151+
}}
152+
>
153+
Subscribe as calendar
154+
</a>
155+
156+
{/* New Attendance Checkbox */}
157+
<div
158+
style={{
159+
fontSize: "0.9rem",
160+
display: "flex",
161+
alignItems: "center",
162+
gap: "0.5rem",
163+
}}
164+
>
165+
<input
166+
type="checkbox"
167+
id="attendance-mode-toggle"
168+
checked={isRemote}
169+
onChange={toggleMode}
170+
style={{ width: "auto", margin: 0 }}
171+
/>
172+
<label
173+
htmlFor="attendance-mode-toggle"
174+
style={{
175+
cursor: "pointer",
176+
userSelect: "none",
177+
color: "var(--color-primary)",
178+
}}
179+
>
180+
Participating remotely
181+
</label>
182+
</div>
183+
</div>
132184
</div>
133185
);
134186
}

frontend/src/store.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { signal, effect } from "@preact/signals";
2-
import type { Talk, User, AuthCommand, Command } from "./types";
2+
import type { Talk, User, AuthCommand, Command, AttendanceMode } from "./types";
33

44
export const currentUser = signal<User | null>(null);
55
export const users = signal<Record<number, User>>({});
@@ -127,6 +127,18 @@ function handleMessage(msg: any) {
127127
patchTalk(t.id, {
128128
nerds: t.nerds.filter((id) => id !== msg.RemoveNerd.user_id),
129129
});
130+
} else if (msg.UpdateAttendanceMode) {
131+
const user_id = msg.UpdateAttendanceMode.user_id;
132+
const mode: AttendanceMode = msg.UpdateAttendanceMode.attendance_mode;
133+
users.value = {
134+
...users.value,
135+
[user_id]: {
136+
...users.value[user_id],
137+
attendance_mode: mode,
138+
},
139+
};
140+
} else {
141+
console.log("Unknown message", msg);
130142
}
131143
}
132144

frontend/src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ export interface TalkUserPayload {
7878
talk_id: number;
7979
}
8080

81+
export interface SetAttendanceModePayload {
82+
attendance_mode: AttendanceMode;
83+
}
84+
8185
export type AddTalkCommand = { AddTalk: AddTalkPayload };
8286
export type RemoveTalkCommand = { RemoveTalk: RemoveTalkPayload };
8387
export type UpdateTitleCommand = { UpdateTitle: UpdateTitlePayload };
@@ -93,6 +97,7 @@ export type AddNoobCommand = { AddNoob: TalkUserPayload };
9397
export type RemoveNoobCommand = { RemoveNoob: TalkUserPayload };
9498
export type AddNerdCommand = { AddNerd: TalkUserPayload };
9599
export type RemoveNerdCommand = { RemoveNerd: TalkUserPayload };
100+
export type SetAttendanceMode = { SetAttendanceMode: SetAttendanceModePayload };
96101

97102
export type Command =
98103
| AddTalkCommand
@@ -105,6 +110,7 @@ export type Command =
105110
| AddNoobCommand
106111
| RemoveNoobCommand
107112
| AddNerdCommand
113+
| SetAttendanceMode
108114
| RemoveNerdCommand;
109115

110116
export type AuthCommand =

0 commit comments

Comments
 (0)