1
0
Fork 0

Compare commits

...

4 Commits

Author SHA1 Message Date
Pabloader 7f2987041e horde -> hordeseer 2026-04-10 09:38:23 +00:00
Pabloader 663f102cd1 UI refactor 2026-04-10 09:31:22 +00:00
Pabloader 3f675966a6 Extract modal to ui kit 2026-04-10 09:05:11 +00:00
Pabloader 810035547c ui kit 2026-04-10 08:43:14 +00:00
41 changed files with 843 additions and 1108 deletions

View File

@ -18,7 +18,7 @@
"preact": "10.22.0", "preact": "10.22.0",
}, },
"devDependencies": { "devDependencies": {
"@types/bun": "latest", "@types/bun": "^1.3.11",
"@types/html-minifier": "4.0.5", "@types/html-minifier": "4.0.5",
"@types/inquirer": "9.0.7", "@types/inquirer": "9.0.7",
"@types/web-bluetooth": "0.0.21", "@types/web-bluetooth": "0.0.21",

View File

@ -22,7 +22,7 @@
"preact": "10.22.0" "preact": "10.22.0"
}, },
"devDependencies": { "devDependencies": {
"@types/bun": "latest", "@types/bun": "^1.3.11",
"@types/html-minifier": "4.0.5", "@types/html-minifier": "4.0.5",
"@types/inquirer": "9.0.7", "@types/inquirer": "9.0.7",
"@types/web-bluetooth": "0.0.21", "@types/web-bluetooth": "0.0.21",

View File

@ -26,3 +26,19 @@
scrollbar-width: thin; scrollbar-width: thin;
scrollbar-color: var(--bg-active) transparent; scrollbar-color: var(--bg-active) transparent;
} }
html {
padding: 0;
margin: 0;
}
body {
background: var(--bg);
color: var(--text);
font-family: 'Georgia', serif;
font-size: 14px;
line-height: 1.5;
width: 100dvw;
height: 100dvh;
overflow: hidden;
}

View File

@ -0,0 +1,131 @@
@import './global.css';
.dialog {
position: fixed;
inset: 0;
width: 100%;
max-width: 100%;
height: 100%;
max-height: 100%;
display: none;
align-items: center;
justify-content: center;
background: transparent;
border: none;
outline: none;
padding: 0;
&::backdrop {
background: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(8px);
}
&[open] {
display: flex;
}
}
.modal {
background: var(--bg);
color: var(--text);
border-radius: 8px;
width: 90%;
max-width: 960px;
height: 80vh;
display: flex;
flex-direction: column;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 20px;
border-bottom: 1px solid var(--border);
flex-shrink: 0;
}
.title {
font-size: 18px;
font-weight: bold;
color: var(--text);
margin: 0;
}
.closeButton {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
color: var(--text-muted);
background: transparent;
border: none;
border-radius: var(--radius);
cursor: pointer;
padding: 0;
&:hover {
color: var(--text);
background: var(--bg-hover);
}
}
.body {
display: flex;
flex: 1;
overflow: hidden;
}
.sidebar {
display: flex;
flex-direction: column;
width: 160px;
flex-shrink: 0;
border-right: 1px solid var(--border);
padding: 8px;
gap: 2px;
}
.content {
flex: 1;
overflow-y: auto;
padding: 20px;
display: flex;
flex-direction: column;
}
.footer {
padding: 16px 20px;
border-top: 1px solid var(--border);
display: flex;
justify-content: flex-end;
gap: 8px;
flex-shrink: 0;
}
@media (max-width: 600px) {
.body {
flex-direction: column;
}
.sidebar {
flex-direction: row;
width: 100%;
overflow-x: auto;
border-right: none;
border-bottom: 1px solid var(--border);
padding: 4px 8px;
flex-shrink: 0;
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}
.footer {
padding: 12px 16px;
}
}

View File

@ -0,0 +1,267 @@
@import "./global.css";
/* ─── Form Fields ─────────────────────────────────────────── */
.input, input, textarea {
width: 100%;
padding: 8px 12px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: var(--radius);
font-size: 14px;
color: var(--text);
font-family: inherit;
&:focus {
outline: none;
border-color: var(--accent);
}
}
.textarea {
composes: input;
resize: vertical;
box-sizing: border-box;
min-height: 80px;
}
.select {
composes: input;
cursor: pointer;
}
.inputRow {
display: flex;
gap: 8px;
}
/* ─── Buttons ─────────────────────────────────────────────── */
.button, button {
padding: 8px 16px;
border-radius: var(--radius);
font-size: 14px;
font-family: inherit;
cursor: pointer;
border: none;
background: transparent;
transition: all var(--transition);
color: var(--text);
}
.buttonPrimary {
composes: button;
background: var(--accent);
color: var(--bg);
font-weight: 500;
&:hover {
background: var(--accent-alt);
}
}
.buttonDanger {
composes: button;
background: var(--danger, #dc2626);
color: var(--bg);
font-weight: 500;
&:hover {
background: var(--danger-alt, #b91c1c);
}
}
.buttonSecondary {
composes: button;
border: 1px solid var(--border);
color: var(--text);
&:hover {
background: var(--bg-hover);
}
}
.buttonSmall {
padding: 4px 10px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: var(--radius);
font-size: 12px;
font-family: inherit;
color: var(--text);
cursor: pointer;
transition: all var(--transition);
&:hover {
border-color: var(--accent);
color: var(--accent);
}
}
.iconButton {
display: flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
background: transparent;
border: 1px solid var(--border);
border-radius: var(--radius);
color: var(--text-muted);
font-size: 16px;
cursor: pointer;
transition: all var(--transition);
flex-shrink: 0;
&:hover:not(:disabled) {
border-color: var(--accent);
color: var(--accent);
}
&:disabled {
opacity: 0.3;
cursor: not-allowed;
}
}
.deleteButton {
composes: iconButton;
&:hover:not(:disabled) {
background: var(--danger, var(--accent));
border-color: var(--danger, var(--accent));
color: var(--bg);
}
}
.confirmButton {
padding: 4px 10px;
border: 1px solid var(--accent);
border-radius: var(--radius);
font-size: 12px;
font-weight: 600;
font-family: inherit;
cursor: pointer;
background: var(--accent);
color: var(--bg);
transition: all var(--transition);
&:hover {
background: var(--bg);
color: var(--accent);
}
}
.cancelButton {
padding: 4px 10px;
border: 1px solid var(--border);
border-radius: var(--radius);
font-size: 12px;
font-weight: 600;
font-family: inherit;
cursor: pointer;
background: transparent;
color: var(--text-muted);
transition: all var(--transition);
&:hover {
background: var(--bg-hover);
color: var(--text);
}
}
/* ─── Form Layout ─────────────────────────────────────────── */
.form {
display: flex;
flex-direction: column;
gap: 16px;
flex: 1;
}
.formGroup {
display: flex;
flex-direction: column;
gap: 4px;
}
.label {
display: block;
font-weight: bold;
margin-bottom: 4px;
}
/* ─── Cards ───────────────────────────────────────────────── */
.card {
background: var(--bg-secondary);
border-radius: 8px;
padding: 20px;
display: flex;
flex-direction: column;
gap: 16px;
}
.cardHeader {
display: flex;
align-items: center;
gap: 12px;
}
/* ─── Editor Section Header ───────────────────────────────── */
.editorHeader {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 16px;
border-bottom: 1px solid var(--border);
}
/* ─── Badges ──────────────────────────────────────────────── */
.badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 10px;
background: var(--bg-active);
border-radius: 16px;
font-size: 13px;
color: var(--text);
}
.badgeRemove {
display: flex;
align-items: center;
justify-content: center;
width: 16px;
height: 16px;
padding: 0;
background: transparent;
border: none;
border-radius: 50%;
color: var(--text-muted);
cursor: pointer;
font-size: 14px;
line-height: 1;
&:hover {
background: var(--danger, var(--accent));
color: var(--bg);
}
}
/* ─── Utilities ───────────────────────────────────────────── */
.empty {
color: var(--text-muted);
font-style: italic;
font-size: 14px;
}
.divider {
height: 1px;
background: var(--border);
margin: 16px 0;
}

View File

@ -0,0 +1,56 @@
import type { ComponentChildren } from "preact";
import { useCallback, useEffect, useRef } from "preact/hooks";
import { X } from "lucide-preact";
import clsx from "clsx";
import styles from '../assets/modal.module.css';
interface IProps {
open: boolean;
title?: string;
onClose?: () => void;
sidebar?: ComponentChildren;
footer?: ComponentChildren;
class?: string;
className?: string;
children?: ComponentChildren;
}
export const Modal = ({ children, open, title, onClose, sidebar, footer, ['class']: cls, className }: IProps) => {
const ref = useRef<HTMLDialogElement>(null);
useEffect(() => {
if (open) {
ref.current?.showModal();
} else {
console.log(ref.current);
ref.current?.close();
}
}, [open]);
const handleBackdropMouseDown = useCallback((e: MouseEvent) => {
if (e.target === ref.current) onClose?.();
}, [onClose]);
return (
<dialog ref={ref} class={styles.dialog} onMouseDown={handleBackdropMouseDown}>
<div class={clsx(styles.modal, cls ?? className)} onMouseDown={(e) => e.stopPropagation()}>
{(title != null || onClose) && (
<div class={styles.header}>
{title && <h2 class={styles.title}>{title}</h2>}
{onClose && (
<button class={styles.closeButton} onClick={onClose}>
<X size={18} />
</button>
)}
</div>
)}
<div class={styles.body}>
{sidebar && <div class={styles.sidebar}>{sidebar}</div>}
<div class={styles.content}>{children}</div>
</div>
{footer && <div class={styles.footer}>{footer}</div>}
</div>
</dialog>
);
};

View File

@ -1,42 +0,0 @@
.dialog {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 100%;
max-width: 1000px;
height: fit-content;
max-height: 80dvh;
overflow: hidden;
background-color: var(--backgroundColor, #333333);
color: var(--color, white);
border: var(--border, 1px solid white);
outline: none;
padding: 0;
border-radius: var(--border-radius, 0);
&::backdrop {
backdrop-filter: blur(5px);
}
>.content {
display: flex;
flex-direction: column;
max-height: 80dvh;
overflow: hidden;
padding: 30px;
>.close {
font-family: var(--emojiFont, sans-serif);
font-size: 12px;
position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
user-select: none;
}
}
}

View File

@ -1,40 +0,0 @@
import type { ComponentChildren } from "preact";
import { useCallback, useEffect, useRef } from "preact/hooks";
import styles from './Modal.module.css';
interface IProps {
open: boolean;
class?: string;
className?: string;
onClose?: () => void;
children?: ComponentChildren;
}
export const Modal = ({ children, open, onClose, ['class']: cls, className }: IProps) => {
const ref = useRef<HTMLDialogElement>(null);
const handleClickWrapper = useCallback((e: MouseEvent) => {
if (e.currentTarget instanceof HTMLDialogElement) {
onClose?.();
} else {
e.stopPropagation();
}
}, [onClose]);
useEffect(() => {
if (open) {
ref.current?.showModal();
} else {
ref.current?.close();
}
}, [open]);
return (
<dialog ref={ref} onMouseDown={handleClickWrapper} class={styles.dialog}>
<div class={`${styles.content} ${cls ?? className ?? ''}`} onMouseDown={handleClickWrapper}>
<div class={styles.close} onClick={onClose}></div>
{children}
</div>
</dialog>
);
};

View File

@ -1,72 +0,0 @@
.overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.6);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.modal {
background: var(--bg);
border: 1px solid var(--border);
border-radius: 8px;
display: flex;
flex-direction: column;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
max-height: 80vh;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 14px 16px;
border-bottom: 1px solid var(--border);
flex-shrink: 0;
}
.title {
font-size: 16px;
font-weight: bold;
color: var(--text);
}
.closeButton {
display: flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
color: var(--text-muted);
background: transparent;
border: none;
border-radius: var(--radius);
cursor: pointer;
&:hover {
color: var(--text);
background: var(--bg-hover);
}
}
.body {
flex: 1;
overflow-y: auto;
padding: 16px;
display: flex;
flex-direction: column;
gap: 14px;
min-height: 0;
}
.footer {
padding: 12px 16px;
border-top: 1px solid var(--border);
display: flex;
flex-direction: row;
gap: 8px;
flex-shrink: 0;
align-items: center;
}

View File

@ -1,19 +0,0 @@
.modal {
width: 380px;
}
.label {
display: flex;
flex-direction: column;
gap: 6px;
font-size: 13px;
color: var(--text-muted);
input {
width: 100%;
}
}
.saveBtn {
color: var(--accent-alt) !important;
}

View File

@ -1,49 +0,0 @@
@import "@common/assets/global.css";
body {
background: var(--bg);
color: var(--text);
font-family: 'Georgia', serif;
font-size: 14px;
line-height: 1.5;
width: 100dvw;
height: 100dvh;
overflow: hidden;
}
button {
cursor: pointer;
background: none;
border: none;
color: var(--text-muted);
font-family: inherit;
font-size: inherit;
transition: color var(--transition), background var(--transition);
border-radius: var(--radius);
display: inline-flex;
flex-direction: row;
align-items: center;
gap: 4px;
padding: 4px 8px;
&:hover {
color: var(--text);
background: var(--bg-hover);
}
}
input, textarea {
background: var(--bg-active);
border: 1px solid var(--border);
border-radius: var(--radius);
color: var(--text);
font-family: inherit;
font-size: inherit;
padding: 6px 10px;
outline: none;
transition: border-color var(--transition);
&:focus {
border-color: var(--accent);
}
}

View File

@ -1,143 +0,0 @@
import { useEffect, useState } from "preact/hooks";
import { X } from "lucide-preact";
import { useHordeState } from "../../contexts/state";
import { fetchWorker, updateWorker, deleteWorker, type WorkerData } from "../../utils/api";
import modalStyles from "../../assets/modal.module.css";
import styles from "../../assets/manage-workers-modal.module.css";
interface Props {
open: boolean;
onClose: () => void;
}
interface WorkerEdit {
name: string;
info: string;
maintenance_mode: boolean;
}
export const ManageWorkersModal = ({ open, onClose }: Props) => {
const { state, dispatch } = useHordeState();
const { user, apiKey } = state;
const [workerDetails, setWorkerDetails] = useState<WorkerData[]>([]);
const [edits, setEdits] = useState<Record<string, WorkerEdit>>({});
const [saving, setSaving] = useState<Record<string, boolean>>({});
const [deleting, setDeleting] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (!open || !user || !apiKey) return;
let cancelled = false;
setLoading(true);
Promise.all(user.worker_ids.map(id => fetchWorker(id, apiKey)))
.then(details => {
if (cancelled) return;
setWorkerDetails(details);
const initialEdits: Record<string, WorkerEdit> = {};
for (const w of details) {
initialEdits[w.id] = { name: w.name, info: w.info ?? '', maintenance_mode: w.maintenance_mode };
}
setEdits(initialEdits);
})
.catch(console.error)
.finally(() => { if (!cancelled) setLoading(false); });
return () => { cancelled = true; };
}, [open, user?.worker_ids.join(',')]);
useEffect(() => {
if (!open) return;
const handler = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); };
window.addEventListener('keydown', handler);
return () => window.removeEventListener('keydown', handler);
}, [open]);
if (!open || !user) return null;
const setEdit = (id: string, patch: Partial<WorkerEdit>) => {
setEdits(prev => ({ ...prev, [id]: { ...prev[id], ...patch } }));
};
const save = async (id: string) => {
if (!apiKey) return;
setSaving(prev => ({ ...prev, [id]: true }));
try {
const updated = await updateWorker(id, apiKey, edits[id]);
setWorkerDetails(prev => prev.map(w => w.id === id ? updated : w));
} catch (e) {
console.error('[horde] save worker error:', e);
} finally {
setSaving(prev => ({ ...prev, [id]: false }));
}
};
const confirmDelete = async (id: string) => {
if (!apiKey || !confirm('Delete this worker? This cannot be undone.')) return;
setDeleting(id);
try {
await deleteWorker(id, apiKey);
setWorkerDetails(prev => prev.filter(w => w.id !== id));
dispatch({ type: 'SET_USER', user: { ...user, worker_ids: user.worker_ids.filter(i => i !== id) } });
} catch (e) {
console.error('[horde] delete worker error:', e);
} finally {
setDeleting(null);
}
};
return (
<div class={modalStyles.overlay} onMouseDown={e => { if (e.target === e.currentTarget) onClose(); }}>
<div class={`${modalStyles.modal} ${styles.modal}`}>
<div class={modalStyles.header}>
<span class={modalStyles.title}>Manage Workers</span>
<button class={modalStyles.closeButton} onClick={onClose}><X size={16} /></button>
</div>
<div class={modalStyles.body}>
{loading && <p class={styles.loading}>Loading</p>}
{!loading && workerDetails.map(w => {
const edit = edits[w.id] ?? { name: w.name, info: w.info ?? '', maintenance_mode: w.maintenance_mode };
return (
<div key={w.id} class={styles.workerForm}>
<div class={styles.workerName}>{w.name}</div>
<label class={styles.label}>
<span>Name</span>
<input
value={edit.name}
onInput={e => setEdit(w.id, { name: (e.target as HTMLInputElement).value })}
/>
</label>
<label class={styles.label}>
<span>Info</span>
<textarea
class={styles.textarea}
value={edit.info}
onInput={e => setEdit(w.id, { info: (e.target as HTMLTextAreaElement).value })}
rows={3}
/>
</label>
<label class={styles.checkboxLabel}>
<input
type="checkbox"
checked={edit.maintenance_mode}
onChange={e => setEdit(w.id, { maintenance_mode: (e.target as HTMLInputElement).checked })}
/>
<span>Maintenance mode</span>
</label>
<div class={styles.formActions}>
<button class={styles.saveBtn} onClick={() => save(w.id)} disabled={saving[w.id]}>
{saving[w.id] ? 'Saving…' : 'Save'}
</button>
<button class={styles.deleteBtn} onClick={() => confirmDelete(w.id)} disabled={deleting === w.id}>
{deleting === w.id ? 'Deleting…' : 'Delete'}
</button>
</div>
</div>
);
})}
</div>
</div>
</div>
);
};

View File

@ -1,67 +0,0 @@
import { useEffect, useState } from "preact/hooks";
import { X } from "lucide-preact";
import { useHordeState } from "../../contexts/state";
import modalStyles from "../../assets/modal.module.css";
import styles from "../../assets/options-modal.module.css";
interface Props {
open: boolean;
onClose: () => void;
}
export const OptionsModal = ({ open, onClose }: Props) => {
const { state, dispatch } = useHordeState();
const [draft, setDraft] = useState(state.apiKey);
useEffect(() => {
if (open) setDraft(state.apiKey);
}, [open]);
useEffect(() => {
if (!open) return;
const handler = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); };
window.addEventListener('keydown', handler);
return () => window.removeEventListener('keydown', handler);
}, [open]);
if (!open) return null;
const save = () => {
dispatch({ type: 'SET_API_KEY', apiKey: draft.trim() });
onClose();
};
const clear = () => {
dispatch({ type: 'SET_API_KEY', apiKey: '' });
setDraft('');
onClose();
};
return (
<div class={modalStyles.overlay} onMouseDown={e => { if (e.target === e.currentTarget) onClose(); }}>
<div class={`${modalStyles.modal} ${styles.modal}`}>
<div class={modalStyles.header}>
<span class={modalStyles.title}>Options</span>
<button class={modalStyles.closeButton} onClick={onClose}><X size={16} /></button>
</div>
<div class={modalStyles.body}>
<label class={styles.label}>
<span>API Key</span>
<input
type="password"
value={draft}
onInput={e => setDraft((e.target as HTMLInputElement).value)}
onKeyDown={e => { if (e.key === 'Enter') save(); }}
placeholder="Enter your AI Horde API key"
autoFocus
/>
</label>
</div>
<div class={modalStyles.footer}>
<button class={styles.saveBtn} onClick={save}>Save</button>
{state.apiKey && <button onClick={clear}>Clear</button>}
</div>
</div>
</div>
);
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -1,8 +1,10 @@
.modal { .modal {
width: 480px; max-width: 480px;
height: fit-content;
} }
.loading, .error { .loading,
.error {
color: var(--text-muted); color: var(--text-muted);
font-size: 14px; font-size: 14px;
text-align: center; text-align: center;
@ -18,7 +20,8 @@
border-collapse: collapse; border-collapse: collapse;
font-size: 13px; font-size: 13px;
th, td { th,
td {
padding: 7px 10px; padding: 7px 10px;
text-align: left; text-align: left;
border-bottom: 1px solid var(--border); border-bottom: 1px solid var(--border);

View File

@ -1,5 +1,6 @@
.modal { .modal {
width: 480px; max-width: 480px;
height: fit-content;
} }
.loading { .loading {
@ -58,10 +59,9 @@
} }
.saveBtn { .saveBtn {
color: var(--accent-alt) !important; composes: buttonSecondary from '@common/assets/ui.module.css';
} }
.deleteBtn { .deleteBtn {
color: var(--accent) !important; composes: buttonDanger from '@common/assets/ui.module.css';
margin-left: auto;
} }

View File

@ -0,0 +1,24 @@
.modal {
max-width: 380px;
height: fit-content;
}
.label {
display: flex;
flex-direction: column;
gap: 6px;
font-size: 13px;
color: var(--text-muted);
input {
width: 100%;
}
}
.saveBtn {
composes: buttonSecondary from '@common/assets/ui.module.css';
}
.clearBtn {
composes: buttonSecondary from '@common/assets/ui.module.css';
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

View File

@ -59,7 +59,8 @@
} }
} }
.userStats, .networkStats { .userStats,
.networkStats {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
@ -83,7 +84,8 @@
border-collapse: collapse; border-collapse: collapse;
font-size: 12px; font-size: 12px;
th, td { th,
td {
padding: 5px 6px; padding: 5px 6px;
text-align: left; text-align: left;
border-bottom: 1px solid var(--border); border-bottom: 1px solid var(--border);

View File

@ -14,7 +14,7 @@
} }
.own { .own {
border-color: var(--accent) !important; border-color: var(--accent-alt) !important;
} }
.offline { .offline {

View File

@ -1,9 +1,8 @@
import { useEffect, useState } from "preact/hooks"; import { useEffect, useState } from "preact/hooks";
import { X } from "lucide-preact";
import { useHordeState } from "../../contexts/state"; import { useHordeState } from "../../contexts/state";
import { fetchLeaderboard, type LeaderboardEntry } from "../../utils/api"; import { fetchLeaderboard, type LeaderboardEntry } from "../../utils/api";
import { formatNumber, formatTime } from "@common/utils"; import { formatNumber, formatTime } from "@common/utils";
import modalStyles from "../../assets/modal.module.css"; import { Modal } from "@common/components/Modal";
import styles from "../../assets/leaderboard-modal.module.css"; import styles from "../../assets/leaderboard-modal.module.css";
interface Props { interface Props {
@ -93,23 +92,21 @@ export const LeaderboardModal = ({ open, onClose }: Props) => {
return () => { cancelled = true; }; return () => { cancelled = true; };
}, [open, user?.username]); }, [open, user?.username]);
useEffect(() => { const nextRow = rows.length >= 2 ? rows[rows.length - 2] : null;
if (!open) return; const footer = user && nextRow?.diff && nextRow.diff > 0 && kudosPerHour > 0
const handler = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; ? (() => {
window.addEventListener('keydown', handler); const secs = Math.ceil((nextRow.diff / kudosPerHour) * 3600);
return () => window.removeEventListener('keydown', handler); return (
}, [open]); <span class={styles.nextPlace}>
Time to #{nextRow.rank}: <strong>{formatTime(secs)}</strong>
if (!open) return null; <span class={styles.nextPlaceMeta}> ({formatNumber(Math.round(kudosPerHour))} kudos/h)</span>
</span>
);
})()
: undefined;
return ( return (
<div class={modalStyles.overlay} onMouseDown={e => { if (e.target === e.currentTarget) onClose(); }}> <Modal open={open} onClose={onClose} title="Leaderboard" class={styles.modal} footer={footer}>
<div class={`${modalStyles.modal} ${styles.modal}`}>
<div class={modalStyles.header}>
<span class={modalStyles.title}>Leaderboard</span>
<button class={modalStyles.closeButton} onClick={onClose}><X size={16} /></button>
</div>
<div class={modalStyles.body}>
{loading && <p class={styles.loading}>Loading</p>} {loading && <p class={styles.loading}>Loading</p>}
{error && <p class={styles.error}>{error}</p>} {error && <p class={styles.error}>{error}</p>}
{!loading && !error && rows.length > 0 && ( {!loading && !error && rows.length > 0 && (
@ -138,22 +135,6 @@ export const LeaderboardModal = ({ open, onClose }: Props) => {
</tbody> </tbody>
</table> </table>
)} )}
</div> </Modal>
{(() => {
if (!user || rows.length < 2 || kudosPerHour <= 0) return null;
const nextRow = rows[rows.length - 2];
if (!nextRow.diff || nextRow.diff <= 0) return null;
const secs = Math.ceil((nextRow.diff / kudosPerHour) * 3600);
return (
<div class={modalStyles.footer}>
<span class={styles.nextPlace}>
Time to #{nextRow.rank}: <strong>{formatTime(secs)}</strong>
<span class={styles.nextPlaceMeta}> ({formatNumber(Math.round(kudosPerHour))} kudos/h)</span>
</span>
</div>
);
})()}
</div>
</div>
); );
}; };

View File

@ -0,0 +1,125 @@
import { useEffect, useState } from "preact/hooks";
import { useHordeState } from "../../contexts/state";
import { fetchWorker, updateWorker, deleteWorker, type WorkerData } from "../../utils/api";
import { Modal } from "@common/components/Modal";
import styles from "../../assets/manage-workers-modal.module.css";
interface Props {
open: boolean;
onClose: () => void;
}
interface WorkerEdit {
name: string;
info: string;
maintenance_mode: boolean;
}
export const ManageWorkersModal = ({ open, onClose }: Props) => {
const { state, dispatch } = useHordeState();
const { user, apiKey } = state;
const [workerDetails, setWorkerDetails] = useState<WorkerData[]>([]);
const [edits, setEdits] = useState<Record<string, WorkerEdit>>({});
const [saving, setSaving] = useState<Record<string, boolean>>({});
const [deleting, setDeleting] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (!open || !user || !apiKey) return;
let cancelled = false;
setLoading(true);
Promise.all(user.worker_ids.map(id => fetchWorker(id, apiKey)))
.then(details => {
if (cancelled) return;
setWorkerDetails(details);
const initialEdits: Record<string, WorkerEdit> = {};
for (const w of details) {
initialEdits[w.id] = { name: w.name, info: w.info ?? '', maintenance_mode: w.maintenance_mode };
}
setEdits(initialEdits);
})
.catch(console.error)
.finally(() => { if (!cancelled) setLoading(false); });
return () => { cancelled = true; };
}, [open, user?.worker_ids.join(',')]);
const setEdit = (id: string, patch: Partial<WorkerEdit>) => {
setEdits(prev => ({ ...prev, [id]: { ...prev[id], ...patch } }));
};
const save = async (id: string) => {
if (!apiKey) return;
setSaving(prev => ({ ...prev, [id]: true }));
try {
const updated = await updateWorker(id, apiKey, edits[id]);
setWorkerDetails(prev => prev.map(w => w.id === id ? updated : w));
} catch (e) {
console.error('[horde] save worker error:', e);
} finally {
setSaving(prev => ({ ...prev, [id]: false }));
}
};
const confirmDelete = async (id: string) => {
if (!apiKey || !confirm('Delete this worker? This cannot be undone.')) return;
setDeleting(id);
try {
await deleteWorker(id, apiKey);
setWorkerDetails(prev => prev.filter(w => w.id !== id));
dispatch({ type: 'SET_USER', user: { ...user!, worker_ids: user!.worker_ids.filter(i => i !== id) } });
} catch (e) {
console.error('[horde] delete worker error:', e);
} finally {
setDeleting(null);
}
};
return (
<Modal open={open && Boolean(user)} onClose={onClose} title="Manage Workers" class={styles.modal}>
{loading && <p class={styles.loading}>Loading</p>}
{!loading && user && workerDetails.map(w => {
const edit = edits[w.id] ?? { name: w.name, info: w.info ?? '', maintenance_mode: w.maintenance_mode };
return (
<div key={w.id} class={styles.workerForm}>
<div class={styles.workerName}>{w.name}</div>
<label class={styles.label}>
<span>Name</span>
<input
value={edit.name}
onInput={e => setEdit(w.id, { name: (e.target as HTMLInputElement).value })}
/>
</label>
<label class={styles.label}>
<span>Info</span>
<textarea
class={styles.textarea}
value={edit.info}
onInput={e => setEdit(w.id, { info: (e.target as HTMLTextAreaElement).value })}
rows={3}
/>
</label>
<label class={styles.checkboxLabel}>
<input
type="checkbox"
checked={edit.maintenance_mode}
onChange={e => setEdit(w.id, { maintenance_mode: (e.target as HTMLInputElement).checked })}
/>
<span>Maintenance mode</span>
</label>
<div class={styles.formActions}>
<button class={styles.saveBtn} onClick={() => save(w.id)} disabled={saving[w.id]}>
{saving[w.id] ? 'Saving…' : 'Save'}
</button>
<button class={styles.deleteBtn} onClick={() => confirmDelete(w.id)} disabled={deleting === w.id}>
{deleting === w.id ? 'Deleting…' : 'Delete'}
</button>
</div>
</div>
);
})}
</Modal>
);
};

View File

@ -0,0 +1,55 @@
import { useEffect } from "preact/hooks";
import { useHordeState } from "../../contexts/state";
import { useInputState } from "@common/hooks/useInputState";
import { Modal } from "@common/components/Modal";
import styles from "../../assets/options-modal.module.css";
interface Props {
open: boolean;
onClose: () => void;
}
export const OptionsModal = ({ open, onClose }: Props) => {
const { state, dispatch } = useHordeState();
const [draft, setDraft] = useInputState(state.apiKey);
useEffect(() => {
if (open) setDraft(state.apiKey);
}, [open]);
const save = () => {
dispatch({ type: 'SET_API_KEY', apiKey: draft.trim() });
onClose();
};
const clear = () => {
dispatch({ type: 'SET_API_KEY', apiKey: '' });
setDraft('');
onClose();
};
return (
<Modal
open={open}
onClose={onClose}
title="Options"
class={styles.modal}
footer={<>
<button class={styles.saveBtn} onClick={save}>Save</button>
{state.apiKey && <button class={styles.clearBtn} onClick={clear}>Clear</button>}
</>}
>
<label class={styles.label}>
<span>API Key</span>
<input
type="password"
value={draft}
onInput={setDraft}
onKeyDown={e => { if (e.key === 'Enter') save(); }}
placeholder="Enter your AI Horde API key"
autoFocus
/>
</label>
</Modal>
);
};

View File

@ -59,7 +59,7 @@ export const StatsPanel = () => {
</div> </div>
<div class={styles.stat}> <div class={styles.stat}>
<dt>Workers</dt> <dt>Workers</dt>
<dd>{user.worker_count}</dd> <dd>{ownWorkers.length}/{user.worker_count}</dd>
</div> </div>
<div class={styles.stat}> <div class={styles.stat}>
<dt>Tokens generated</dt> <dt>Tokens generated</dt>

View File

@ -2,8 +2,6 @@ import { render } from "preact";
import { App } from "./components/app"; import { App } from "./components/app";
import { HordeStateProvider } from "./contexts/state"; import { HordeStateProvider } from "./contexts/state";
import './assets/style.css';
export default function main() { export default function main() {
render( render(
<HordeStateProvider> <HordeStateProvider>

View File

@ -7,18 +7,11 @@
} }
.empty { .empty {
color: var(--text-muted); composes: empty from '@common/assets/ui.module.css';
font-style: italic;
font-size: 14px;
} }
.chapterCard { .chapterCard {
background: var(--bg-secondary); composes: card from '@common/assets/ui.module.css';
border-radius: 8px;
padding: 20px;
display: flex;
flex-direction: column;
gap: 16px;
} }
.chapterTitle { .chapterTitle {
@ -59,24 +52,9 @@
} }
.summaryEditable { .summaryEditable {
width: 100%; composes: textarea from '@common/assets/ui.module.css';
padding: 10px 12px; padding: 10px 12px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 6px; border-radius: 6px;
font-size: 14px;
color: var(--text);
font-family: inherit;
box-sizing: border-box;
min-height: 80px;
white-space: pre-wrap; white-space: pre-wrap;
word-wrap: break-word; word-wrap: break-word;
resize: vertical;
&:focus {
outline: none;
border-color: var(--accent);
}
} }

View File

@ -7,11 +7,7 @@
} }
.header { .header {
display: flex; composes: editorHeader from '@common/assets/ui.module.css';
justify-content: space-between;
align-items: center;
padding-bottom: 16px;
border-bottom: 1px solid var(--border);
} }
.header h2 { .header h2 {
@ -22,19 +18,8 @@
} }
.addButton { .addButton {
padding: 8px 16px; composes: buttonPrimary from '@common/assets/ui.module.css';
background: var(--accent);
color: var(--bg);
border: none;
border-radius: 6px; border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: opacity 0.2s;
&:hover {
background: var(--accent-alt);
}
} }
.deleteConfirm { .deleteConfirm {
@ -53,37 +38,12 @@
} }
} }
.confirmButton,
.cancelButton {
padding: 4px 10px;
border: 1px solid transparent;
border-radius: var(--radius);
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: all var(--transition);
}
.confirmButton { .confirmButton {
background: var(--accent); composes: confirmButton from '@common/assets/ui.module.css';
color: var(--bg);
border-color: var(--accent);
&:hover {
background: var(--bg);
color: var(--accent);
}
} }
.cancelButton { .cancelButton {
background: transparent; composes: cancelButton from '@common/assets/ui.module.css';
color: var(--text-muted);
border-color: var(--border);
&:hover {
background: var(--bg-hover);
color: var(--text);
}
} }
.list { .list {
@ -95,24 +55,15 @@
} }
.empty { .empty {
color: var(--text-muted); composes: empty from '@common/assets/ui.module.css';
font-style: italic;
font-size: 14px;
} }
.characterCard { .characterCard {
background: var(--bg-secondary); composes: card from '@common/assets/ui.module.css';
border-radius: 8px;
padding: 20px;
display: flex;
flex-direction: column;
gap: 16px;
} }
.cardHeader { .cardHeader {
display: flex; composes: cardHeader from '@common/assets/ui.module.css';
align-items: center;
gap: 12px;
} }
.nameInput { .nameInput {
@ -133,29 +84,15 @@
} }
.deleteButton { .deleteButton {
composes: deleteButton from '@common/assets/ui.module.css';
width: 32px; width: 32px;
height: 32px; height: 32px;
display: flex;
align-items: center;
justify-content: center;
background: transparent;
border: 1px solid var(--border);
border-radius: 6px; border-radius: 6px;
color: var(--text-muted);
font-size: 20px; font-size: 20px;
cursor: pointer;
transition: all var(--transition);
&:hover {
background: var(--accent);
border-color: var(--accent);
color: var(--bg);
}
} }
.field { .field {
display: flex; composes: formGroup from '@common/assets/ui.module.css';
flex-direction: column;
gap: 8px; gap: 8px;
} }
@ -224,70 +161,23 @@
} }
.generateButton { .generateButton {
padding: 4px 10px; composes: buttonSmall from '@common/assets/ui.module.css';
background: var(--bg);
border: 1px solid var(--border);
border-radius: 4px;
font-size: 12px;
color: var(--text);
cursor: pointer;
transition: all var(--transition);
&:hover {
border-color: var(--accent);
color: var(--accent);
}
} }
.textarea { .textarea {
width: 100%; composes: textarea from '@common/assets/ui.module.css';
padding: 10px 12px; padding: 10px 12px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 6px; border-radius: 6px;
font-size: 14px;
color: var(--text);
font-family: inherit;
resize: vertical;
box-sizing: border-box;
&:focus {
outline: none;
border-color: var(--accent);
}
} }
.select { .select {
width: 100%; composes: select from '@common/assets/ui.module.css';
padding: 10px 12px; padding: 10px 12px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 6px; border-radius: 6px;
font-size: 14px;
color: var(--text);
font-family: inherit;
cursor: pointer;
&:focus {
outline: none;
border-color: var(--accent);
}
} }
.smallButton { .smallButton {
padding: 4px 10px; composes: buttonSmall from '@common/assets/ui.module.css';
background: var(--bg);
border: 1px solid var(--border);
border-radius: 4px;
font-size: 12px;
color: var(--text);
cursor: pointer;
transition: all 0.2s;
&:hover {
border-color: var(--accent);
color: var(--accent);
}
} }
.nicknames { .nicknames {
@ -303,35 +193,11 @@
} }
.badge { .badge {
display: inline-flex; composes: badge from '@common/assets/ui.module.css';
align-items: center;
gap: 6px;
padding: 4px 10px;
background: var(--bg-active);
border-radius: 16px;
font-size: 13px;
color: var(--text);
} }
.badgeRemove { .badgeRemove {
display: flex; composes: badgeRemove from '@common/assets/ui.module.css';
align-items: center;
justify-content: center;
width: 16px;
height: 16px;
padding: 0;
background: transparent;
border: none;
border-radius: 50%;
color: var(--text-muted);
cursor: pointer;
font-size: 14px;
line-height: 1;
&:hover {
background: var(--danger);
color: var(--bg);
}
} }
.relations { .relations {

View File

@ -7,11 +7,7 @@
} }
.header { .header {
display: flex; composes: editorHeader from '@common/assets/ui.module.css';
justify-content: space-between;
align-items: center;
padding-bottom: 16px;
border-bottom: 1px solid var(--border);
} }
.header h2 { .header h2 {
@ -22,19 +18,8 @@
} }
.addButton { .addButton {
padding: 8px 16px; composes: buttonPrimary from '@common/assets/ui.module.css';
background: var(--accent);
color: var(--bg);
border: none;
border-radius: 6px; border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: opacity 0.2s;
&:hover {
background: var(--accent-alt);
}
} }
.deleteConfirm { .deleteConfirm {
@ -53,37 +38,12 @@
} }
} }
.confirmButton,
.cancelButton {
padding: 4px 10px;
border: 1px solid transparent;
border-radius: var(--radius);
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: all var(--transition);
}
.confirmButton { .confirmButton {
background: var(--accent); composes: confirmButton from '@common/assets/ui.module.css';
color: var(--bg);
border-color: var(--accent);
&:hover {
background: var(--bg);
color: var(--accent);
}
} }
.cancelButton { .cancelButton {
background: transparent; composes: cancelButton from '@common/assets/ui.module.css';
color: var(--text-muted);
border-color: var(--border);
&:hover {
background: var(--bg-hover);
color: var(--text);
}
} }
.list { .list {
@ -95,24 +55,15 @@
} }
.empty { .empty {
color: var(--text-muted); composes: empty from '@common/assets/ui.module.css';
font-style: italic;
font-size: 14px;
} }
.locationCard { .locationCard {
background: var(--bg-secondary); composes: card from '@common/assets/ui.module.css';
border-radius: 8px;
padding: 20px;
display: flex;
flex-direction: column;
gap: 16px;
} }
.cardHeader { .cardHeader {
display: flex; composes: cardHeader from '@common/assets/ui.module.css';
align-items: center;
gap: 12px;
} }
.nameInput { .nameInput {
@ -133,29 +84,15 @@
} }
.deleteButton { .deleteButton {
composes: deleteButton from '@common/assets/ui.module.css';
width: 32px; width: 32px;
height: 32px; height: 32px;
display: flex;
align-items: center;
justify-content: center;
background: transparent;
border: 1px solid var(--border);
border-radius: 6px; border-radius: 6px;
color: var(--text-muted);
font-size: 20px; font-size: 20px;
cursor: pointer;
transition: all var(--transition);
&:hover {
background: var(--accent);
border-color: var(--accent);
color: var(--bg);
}
} }
.field { .field {
display: flex; composes: formGroup from '@common/assets/ui.module.css';
flex-direction: column;
gap: 8px; gap: 8px;
} }
@ -174,52 +111,17 @@
} }
.select { .select {
width: 100%; composes: select from '@common/assets/ui.module.css';
padding: 10px 12px; padding: 10px 12px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 6px; border-radius: 6px;
font-size: 14px;
color: var(--text);
font-family: inherit;
cursor: pointer;
&:focus {
outline: none;
border-color: var(--accent);
}
} }
.generateButton { .generateButton {
padding: 4px 10px; composes: buttonSmall from '@common/assets/ui.module.css';
background: var(--bg);
border: 1px solid var(--border);
border-radius: 4px;
font-size: 12px;
color: var(--text);
cursor: pointer;
transition: all var(--transition);
&:hover {
border-color: var(--accent);
color: var(--accent);
}
} }
.textarea { .textarea {
width: 100%; composes: textarea from '@common/assets/ui.module.css';
padding: 10px 12px; padding: 10px 12px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 6px; border-radius: 6px;
font-size: 14px;
color: var(--text);
font-family: inherit;
resize: vertical;
box-sizing: border-box;
&:focus {
outline: none;
border-color: var(--accent);
}
} }

View File

@ -7,11 +7,7 @@
} }
.header { .header {
display: flex; composes: editorHeader from '@common/assets/ui.module.css';
justify-content: space-between;
align-items: center;
padding-bottom: 16px;
border-bottom: 1px solid var(--border);
} }
.header h2 { .header h2 {
@ -44,19 +40,8 @@
} }
.addButton { .addButton {
padding: 8px 16px; composes: buttonPrimary from '@common/assets/ui.module.css';
background: var(--accent);
color: var(--bg);
border: none;
border-radius: 6px; border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: opacity 0.2s;
&:hover {
background: var(--accent-alt);
}
} }
.list { .list {
@ -68,25 +53,17 @@
} }
.empty { .empty {
color: var(--text-muted); composes: empty from '@common/assets/ui.module.css';
font-style: italic;
font-size: 14px;
} }
.entryCard { .entryCard {
background: var(--bg-secondary); composes: card from '@common/assets/ui.module.css';
border-radius: 8px;
padding: 20px;
display: flex;
flex-direction: column;
gap: 12px; gap: 12px;
} }
.cardHeader { .cardHeader {
display: flex; composes: cardHeader from '@common/assets/ui.module.css';
align-items: center;
justify-content: space-between; justify-content: space-between;
gap: 12px;
} }
.titleRow { .titleRow {
@ -131,49 +108,15 @@
} }
.moveButton { .moveButton {
width: 28px; composes: iconButton from '@common/assets/ui.module.css';
height: 28px;
display: flex;
align-items: center;
justify-content: center;
background: var(--bg); background: var(--bg);
border: 1px solid var(--border);
border-radius: 4px;
color: var(--text); color: var(--text);
font-size: 14px; font-size: 14px;
cursor: pointer;
transition: all var(--transition);
&:hover:not(:disabled) {
border-color: var(--accent);
color: var(--accent);
}
&:disabled {
opacity: 0.3;
cursor: not-allowed;
}
} }
.deleteButton { .deleteButton {
width: 28px; composes: deleteButton from '@common/assets/ui.module.css';
height: 28px;
display: flex;
align-items: center;
justify-content: center;
background: transparent;
border: 1px solid var(--border);
border-radius: 4px;
color: var(--text-muted);
font-size: 18px; font-size: 18px;
cursor: pointer;
transition: all var(--transition);
&:hover {
background: var(--danger);
border-color: var(--danger);
color: var(--bg);
}
} }
.content { .content {
@ -181,20 +124,7 @@
} }
.textarea { .textarea {
width: 100%; composes: textarea from '@common/assets/ui.module.css';
padding: 10px 12px; padding: 10px 12px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 6px; border-radius: 6px;
font-size: 14px;
color: var(--text);
font-family: inherit;
resize: vertical;
min-height: 80px;
box-sizing: border-box;
&:focus {
outline: none;
border-color: var(--accent);
}
} }

View File

@ -1,77 +1,3 @@
.overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.modal {
background: var(--bg);
border-radius: 8px;
width: 90%;
max-width: 960px;
height: 80vh;
display: flex;
flex-direction: column;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 20px;
border-bottom: 1px solid var(--border);
}
.title {
font-size: 18px;
font-weight: bold;
color: var(--text);
margin: 0;
}
.closeButton {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
font-size: 20px;
color: var(--text-muted);
background: transparent;
border: none;
border-radius: 4px;
cursor: pointer;
&:hover {
color: var(--text);
background: var(--bg-hover);
}
}
.body {
display: flex;
flex: 1;
overflow: hidden;
}
.sidebar {
display: flex;
flex-direction: column;
width: 160px;
flex-shrink: 0;
border-right: 1px solid var(--border);
padding: 8px;
gap: 2px;
}
.menuItem { .menuItem {
display: flex; display: flex;
align-items: center; align-items: center;
@ -98,25 +24,12 @@
} }
} }
.content {
flex: 1;
overflow-y: auto;
padding: 20px;
display: flex;
flex-direction: column;
}
.form { .form {
display: flex; composes: form from '@common/assets/ui.module.css';
flex-direction: column;
gap: 16px;
flex: 1;
} }
.formGroup { .formGroup {
display: flex; composes: formGroup from '@common/assets/ui.module.css';
flex-direction: column;
gap: 4px;
} }
.formGroupFill { .formGroupFill {
@ -124,9 +37,7 @@
} }
.label { .label {
display: block; composes: label from '@common/assets/ui.module.css';
margin-bottom: 4px;
font-weight: bold;
} }
.selectMultiline { .selectMultiline {
@ -143,54 +54,38 @@
padding-inline-start: 16px; padding-inline-start: 16px;
} }
.input, .input {
.select, composes: input from '@common/assets/ui.module.css';
.textarea { }
width: 100%;
padding: 8px; .select {
border-radius: 4px; composes: select from '@common/assets/ui.module.css';
border: 1px solid var(--border);
background: var(--bg);
color: var(--text);
} }
.textarea { .textarea {
composes: textarea from '@common/assets/ui.module.css';
resize: none; resize: none;
font-family: inherit;
font-size: inherit; font-size: inherit;
line-height: 1.5; line-height: 1.5;
flex: 1; flex: 1;
} min-height: unset;
.footer {
padding: 16px 20px;
border-top: 1px solid var(--border);
display: flex;
justify-content: flex-end;
gap: 8px;
} }
.button { .button {
padding: 8px 16px; composes: button from '@common/assets/ui.module.css';
border-radius: 4px;
cursor: pointer;
} }
.buttonSecondary { .buttonSecondary {
border: 1px solid var(--border); composes: buttonSecondary from '@common/assets/ui.module.css';
background: transparent;
color: var(--text);
} }
.buttonPrimary { .buttonPrimary {
border: none; composes: buttonPrimary from '@common/assets/ui.module.css';
background: var(--accent);
color: var(--accent-text); color: var(--accent-text);
} }
.inputRow { .inputRow {
display: flex; composes: inputRow from '@common/assets/ui.module.css';
gap: 8px;
} }
.inputRow .input { .inputRow .input {
@ -203,7 +98,7 @@
justify-content: center; justify-content: center;
padding: 8px; padding: 8px;
border: 1px solid var(--border); border: 1px solid var(--border);
border-radius: 4px; border-radius: var(--radius);
background: var(--bg); background: var(--bg);
color: var(--text); color: var(--text);
cursor: pointer; cursor: pointer;
@ -216,9 +111,7 @@
} }
.divider { .divider {
height: 1px; composes: divider from '@common/assets/ui.module.css';
background: var(--border);
margin: 16px 0;
} }
.tokenList { .tokenList {
@ -229,49 +122,21 @@
} }
.tokenItem { .tokenItem {
display: flex; composes: badge from '@common/assets/ui.module.css';
align-items: center;
gap: 4px;
padding: 4px 8px;
background: var(--bg-active);
border: 1px solid var(--border); border: 1px solid var(--border);
border-radius: 4px; border-radius: var(--radius);
color: var(--text);
} }
.tokenRemoveButton { .tokenRemoveButton {
background: none; composes: badgeRemove from '@common/assets/ui.module.css';
border: none;
cursor: pointer;
padding: 0 2px; padding: 0 2px;
font-size: 14px;
color: var(--text-muted);
} }
.emptyText { .emptyText {
color: var(--text-muted); composes: empty from '@common/assets/ui.module.css';
} }
@media (max-width: 600px) { @media (max-width: 600px) {
.body {
flex-direction: column;
}
.sidebar {
flex-direction: row;
width: 100%;
overflow-x: auto;
border-right: none;
border-bottom: 1px solid var(--border);
padding: 4px 8px;
flex-shrink: 0;
scrollbar-width: none;
}
.sidebar::-webkit-scrollbar {
display: none;
}
.menuItem { .menuItem {
flex: 1; flex: 1;
justify-content: center; justify-content: center;
@ -280,8 +145,4 @@
padding: 8px; padding: 8px;
font-size: 13px; font-size: 13px;
} }
.footer {
padding: 12px 16px;
}
} }

View File

@ -322,9 +322,8 @@ export const Menu = ({ visible }: { visible: boolean }) => {
<Settings size={16} /> Settings <Settings size={16} /> Settings
</button> </button>
</div> </div>
{isSettingsOpen.value && (
<SettingsModal onClose={isSettingsOpen.toggle} /> <SettingsModal open={isSettingsOpen.value} onClose={isSettingsOpen.setFalse} />
)}
</div> </div>
); );
}; };

View File

@ -1,6 +1,6 @@
import clsx from "clsx"; import clsx from "clsx";
import { X } from "lucide-preact";
import { useState } from "preact/hooks"; import { useState } from "preact/hooks";
import { Modal } from "@common/components/Modal";
import styles from "../assets/settings-modal.module.css"; import styles from "../assets/settings-modal.module.css";
import { BannedTokensSettings } from "./settings/banned-tokens"; import { BannedTokensSettings } from "./settings/banned-tokens";
import { ChatSystemInstructionSettings } from "./settings/chat-system-instruction"; import { ChatSystemInstructionSettings } from "./settings/chat-system-instruction";
@ -10,77 +10,50 @@ import { SystemInstructionSettings } from "./settings/system-instruction";
import { UserSettings } from "./settings/user"; import { UserSettings } from "./settings/user";
interface Props { interface Props {
open: boolean;
onClose: () => void; onClose: () => void;
} }
type Tab = "banned-tokens" | "system-instruction" | "chat-system-instruction" | "continue-prompt" | "connection" | "user"; type Tab = "banned-tokens" | "system-instruction" | "chat-system-instruction" | "continue-prompt" | "connection" | "user";
export const SettingsModal = ({ onClose }: Props) => { const TABS: { id: Tab; label: string }[] = [
{ id: "connection", label: "Connection" },
{ id: "user", label: "User" },
{ id: "system-instruction", label: "System Instruction" },
{ id: "continue-prompt", label: "Continue Prompt" },
{ id: "chat-system-instruction", label: "Chat System Instruction" },
{ id: "banned-tokens", label: "Banned Tokens" },
];
export const SettingsModal = ({ open, onClose }: Props) => {
const [activeTab, setActiveTab] = useState<Tab>("connection"); const [activeTab, setActiveTab] = useState<Tab>("connection");
return ( return (
<div class={styles.overlay} onClick={onClose}> <Modal
<div class={styles.modal} onClick={(e) => e.stopPropagation()}> open={open}
<div class={styles.header}> onClose={onClose}
<h2 class={styles.title}>Settings</h2> title="Settings"
<button class={styles.closeButton} onClick={onClose}> sidebar={TABS.map(({ id, label }) => (
<X size={20} />
</button>
</div>
<div class={styles.body}>
<nav class={styles.sidebar}>
<button <button
class={clsx(styles.menuItem, activeTab === "connection" && styles.active)} key={id}
onClick={() => setActiveTab("connection")} class={clsx(styles.menuItem, activeTab === id && styles.active)}
onClick={() => setActiveTab(id)}
> >
Connection {label}
</button> </button>
<button ))}
class={clsx(styles.menuItem, activeTab === "user" && styles.active)} footer={
onClick={() => setActiveTab("user")} <button onClick={onClose} class={clsx(styles.button, styles.buttonSecondary)}>
Done
</button>
}
> >
User
</button>
<button
class={clsx(styles.menuItem, activeTab === "system-instruction" && styles.active)}
onClick={() => setActiveTab("system-instruction")}
>
System Instruction
</button>
<button
class={clsx(styles.menuItem, activeTab === "continue-prompt" && styles.active)}
onClick={() => setActiveTab("continue-prompt")}
>
Continue Prompt
</button>
<button
class={clsx(styles.menuItem, activeTab === "chat-system-instruction" && styles.active)}
onClick={() => setActiveTab("chat-system-instruction")}
>
Chat System Instruction
</button>
<button
class={clsx(styles.menuItem, activeTab === "banned-tokens" && styles.active)}
onClick={() => setActiveTab("banned-tokens")}
>
Banned Tokens
</button>
</nav>
<div class={styles.content}>
{activeTab === "user" && <UserSettings />} {activeTab === "user" && <UserSettings />}
{activeTab === "banned-tokens" && <BannedTokensSettings />} {activeTab === "banned-tokens" && <BannedTokensSettings />}
{activeTab === "system-instruction" && <SystemInstructionSettings />} {activeTab === "system-instruction" && <SystemInstructionSettings />}
{activeTab === "chat-system-instruction" && <ChatSystemInstructionSettings />} {activeTab === "chat-system-instruction" && <ChatSystemInstructionSettings />}
{activeTab === "continue-prompt" && <ContinuePromptSettings />} {activeTab === "continue-prompt" && <ContinuePromptSettings />}
{activeTab === "connection" && <ConnectionSettings />} {activeTab === "connection" && <ConnectionSettings />}
</div> </Modal>
</div>
<div class={styles.footer}>
<button onClick={onClose} class={clsx(styles.button, styles.buttonSecondary)}>
Done
</button>
</div>
</div>
</div>
); );
}; };