refactor(ui): one rule for resettable, role key and display name; an honest reset label
The card menu's reset read 'Clear watch progress' but also un-hides and un-watches; it now says so. The resettable rule, the demo-first role key and the display-name fallback each lived in several components tied by comments; they are shared helpers now, and the menu reuses the card's own strings instead of duplicate keys.
This commit is contained in:
@@ -35,6 +35,17 @@ export interface Me {
|
||||
diagnostics: DiagnosticsState;
|
||||
}
|
||||
|
||||
/** The `nav.role.*` key an account is shown under. Demo isn't a real role (it's a flag on a `user`
|
||||
* row), so it comes first. */
|
||||
export function roleKey(a: Pick<Me, "is_demo" | "role">): "admin" | "user" | "demo" {
|
||||
return a.is_demo ? "demo" : a.role === "admin" ? "admin" : "user";
|
||||
}
|
||||
|
||||
/** What an account is called on screen: its display name, else the local part of its email. */
|
||||
export function displayName(a: { display_name: string | null; email: string }): string {
|
||||
return a.display_name ?? a.email.split("@")[0]!;
|
||||
}
|
||||
|
||||
export interface Account {
|
||||
id: number;
|
||||
email: string;
|
||||
|
||||
@@ -28,6 +28,12 @@ export interface Video {
|
||||
watch_url: string;
|
||||
}
|
||||
|
||||
/** Whether a video has anything its reset would clear: pristine = never opened, the default status
|
||||
* and no resume position. The card's reset button and the card menu's reset both ask this. */
|
||||
export function isResettable(v: Pick<Video, "status" | "position_seconds">): boolean {
|
||||
return v.status !== "new" || v.position_seconds > 0;
|
||||
}
|
||||
|
||||
export interface VideoDetail {
|
||||
id: string;
|
||||
description: string | null;
|
||||
|
||||
Reference in New Issue
Block a user