UI: tab-bar navigation — drop the hamburger
CI / changes (pull_request) Successful in 1s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 39s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 59s
CI / changes (pull_request) Successful in 1s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 39s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 59s
Replace Menu.svelte (hamburger) everywhere with tab-bar navigation: - Settings hub (SettingsHub) from the lobby ⚙️ tab: Settings/Profile/ Friends/About as in-place tabs, back → lobby; the lobby ⚙️ badge counts incoming friend requests (invitations keep their own lobby section). - Comms hub (CommsHub) from the move-history 💬: Chat/Dictionary tabs, back → game; Dictionary only while the game is active. - Game menu items relocate into the open history: 🏁 leave / 📤 export in the header, 🤝 add-friend per opponent card, 💬 comms; unread chat is badged on the score bar + the 💬. - TapConfirm (tap → fading ✅ → tap) replaces the Skip/Hint press-and-hold popovers and drives the add-friend confirm. - Fix the move-history "jump": the slid board is inert and the stage can't scroll, so a swipe up genuinely closes the history. Remove Menu.svelte + HoldConfirm.svelte. Docs: UI_DESIGN, FUNCTIONAL(+ru), PRERELEASE. UI check/unit/build/bundle/e2e (Chromium+WebKit) all green.
This commit is contained in:
+14
-14
@@ -49,9 +49,9 @@ export const app = $state<{
|
||||
/** Draw grid lines between board cells; off (default) is a gapless checkerboard. */
|
||||
boardLines: boolean;
|
||||
localeLocked: boolean;
|
||||
/** Pending incoming friend requests + invitations, for the lobby badge. */
|
||||
/** Pending incoming friend requests, for the lobby ⚙️ badge and the Settings Friends tab. */
|
||||
notifications: number;
|
||||
/** Unread chat-message count per game id, for the in-game menu/hamburger badge. */
|
||||
/** Unread chat-message count per game id, for the in-game score-bar and 💬 badges. */
|
||||
chatUnread: Record<string, number>;
|
||||
}>({
|
||||
ready: false,
|
||||
@@ -139,9 +139,12 @@ function openStream(): void {
|
||||
reportOnline(); // a delivered event proves the gateway is reachable
|
||||
app.lastEvent = e;
|
||||
if (e.kind === 'chat_message' && e.message.senderId !== app.session?.userId) {
|
||||
// While the player is on that game's chat screen, neither toast nor bump the unread.
|
||||
const onChat = router.route.name === 'gameChat' && router.route.params.id === e.message.gameId;
|
||||
if (!onChat) {
|
||||
// While the player is in that game's comms hub (chat or dictionary tab), neither
|
||||
// toast nor bump the unread — the chat is a tap away and reloads on open.
|
||||
const inComms =
|
||||
(router.route.name === 'gameChat' || router.route.name === 'gameCheck') &&
|
||||
router.route.params.id === e.message.gameId;
|
||||
if (!inComms) {
|
||||
if (e.message.kind !== 'nudge') {
|
||||
const gid = e.message.gameId;
|
||||
app.chatUnread = { ...app.chatUnread, [gid]: (app.chatUnread[gid] ?? 0) + 1 };
|
||||
@@ -186,9 +189,10 @@ function scheduleReconnect(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* refreshNotifications recomputes the lobby badge count (incoming friend requests
|
||||
* plus open invitations). Authoritative poll, complementing the live 'notify' push.
|
||||
* Guests have no social surfaces, so it is a no-op for them.
|
||||
* refreshNotifications recomputes the badge count (incoming friend requests).
|
||||
* Authoritative poll, complementing the live 'notify' push. Game invitations have
|
||||
* their own lobby section, so they are not counted here. Guests have no social
|
||||
* surfaces, so it is a no-op for them.
|
||||
*/
|
||||
export async function refreshNotifications(): Promise<void> {
|
||||
if (!app.session || app.profile?.isGuest) {
|
||||
@@ -196,11 +200,7 @@ export async function refreshNotifications(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const [incoming, invitations] = await Promise.all([
|
||||
gateway.friendsIncoming(),
|
||||
gateway.invitationsList(),
|
||||
]);
|
||||
app.notifications = incoming.length + invitations.length;
|
||||
app.notifications = (await gateway.friendsIncoming()).length;
|
||||
} catch {
|
||||
// Best-effort; leave the previous count on a transient failure.
|
||||
}
|
||||
@@ -260,7 +260,7 @@ function syncTelegramChrome(): void {
|
||||
/**
|
||||
* syncTelegramSafeArea mirrors Telegram's content-safe-area top inset (the height its native
|
||||
* nav overlays the viewport in fullscreen) into the --tg-content-top CSS var and toggles a
|
||||
* `tg-fullscreen` class, so the header can drop below the nav and lift the menu into its
|
||||
* `tg-fullscreen` class, so the header can drop below the nav and centre the title in its
|
||||
* band. Called on launch and on Telegram's safe-area / fullscreen change events.
|
||||
*/
|
||||
function syncTelegramSafeArea(): void {
|
||||
|
||||
@@ -63,7 +63,6 @@ export const en = {
|
||||
'game.skip': 'Skip',
|
||||
'game.shuffle': 'Shuffle',
|
||||
'game.hint': 'Hint',
|
||||
'game.history': 'History',
|
||||
'game.chat': 'Chat',
|
||||
'game.checkWord': 'Check word',
|
||||
'game.dropGame': 'Drop game',
|
||||
@@ -83,7 +82,6 @@ export const en = {
|
||||
'game.wordIllegal': '“{word}” is not valid',
|
||||
'game.complain': 'Disagree',
|
||||
'game.complaintSent': 'Thanks, sent for review.',
|
||||
'game.confirm': 'Ok',
|
||||
'game.check': 'Check',
|
||||
'game.checkWait': 'Please wait a moment.',
|
||||
'game.noHintOptions': 'No options with your letters.',
|
||||
@@ -242,8 +240,7 @@ export const en = {
|
||||
|
||||
'game.exportGcg': 'Export GCG',
|
||||
'game.gcgActiveOnly': 'Available once the game is finished.',
|
||||
'game.requestSent': 'Request sent',
|
||||
'game.alreadyFriends': '✓ In friends',
|
||||
'game.addFriendShort': 'Add friend?',
|
||||
|
||||
'time.minutes': '{n} min',
|
||||
'time.hours': '{n} h',
|
||||
|
||||
@@ -64,7 +64,6 @@ export const ru: Record<MessageKey, string> = {
|
||||
'game.skip': 'Пас',
|
||||
'game.shuffle': 'Перемешать',
|
||||
'game.hint': 'Подсказка',
|
||||
'game.history': 'История',
|
||||
'game.chat': 'Чат',
|
||||
'game.checkWord': 'Проверить слово',
|
||||
'game.dropGame': 'Покинуть игру',
|
||||
@@ -84,7 +83,6 @@ export const ru: Record<MessageKey, string> = {
|
||||
'game.wordIllegal': '«{word}» недопустимо',
|
||||
'game.complain': 'Не согласен',
|
||||
'game.complaintSent': 'Спасибо, отправлено на проверку.',
|
||||
'game.confirm': 'Да',
|
||||
'game.check': 'Проверить',
|
||||
'game.checkWait': 'Секунду, пожалуйста.',
|
||||
'game.noHintOptions': 'Нет вариантов с вашим набором.',
|
||||
@@ -243,8 +241,7 @@ export const ru: Record<MessageKey, string> = {
|
||||
|
||||
'game.exportGcg': 'Экспорт GCG',
|
||||
'game.gcgActiveOnly': 'Доступно после завершения игры.',
|
||||
'game.requestSent': 'Запрос отправлен',
|
||||
'game.alreadyFriends': '✓ В друзьях',
|
||||
'game.addFriendShort': 'В друзья?',
|
||||
|
||||
'time.minutes': '{n} мин',
|
||||
'time.hours': '{n} ч',
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { createTapConfirm } from './tapconfirm';
|
||||
|
||||
describe('createTapConfirm', () => {
|
||||
beforeEach(() => vi.useFakeTimers());
|
||||
afterEach(() => vi.useRealTimers());
|
||||
|
||||
it('arms a window and reverts after the duration', () => {
|
||||
const changes: boolean[] = [];
|
||||
const c = createTapConfirm({ durationMs: 2000, onConfirm: () => {}, onChange: (x) => changes.push(x) });
|
||||
c.arm();
|
||||
expect(c.confirming).toBe(true);
|
||||
expect(changes).toEqual([true]);
|
||||
vi.advanceTimersByTime(1999);
|
||||
expect(c.confirming).toBe(true);
|
||||
vi.advanceTimersByTime(1);
|
||||
expect(c.confirming).toBe(false);
|
||||
expect(changes).toEqual([true, false]);
|
||||
});
|
||||
|
||||
it('confirms within the window exactly once and stops the revert timer', () => {
|
||||
const onConfirm = vi.fn();
|
||||
const c = createTapConfirm({ durationMs: 2000, onConfirm });
|
||||
c.arm();
|
||||
c.confirm();
|
||||
expect(onConfirm).toHaveBeenCalledTimes(1);
|
||||
expect(c.confirming).toBe(false);
|
||||
vi.advanceTimersByTime(5000); // the revert timer must not fire after a confirm
|
||||
expect(onConfirm).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('ignores confirm when the window is not open', () => {
|
||||
const onConfirm = vi.fn();
|
||||
const c = createTapConfirm({ durationMs: 2000, onConfirm });
|
||||
c.confirm();
|
||||
expect(onConfirm).not.toHaveBeenCalled();
|
||||
expect(c.confirming).toBe(false);
|
||||
});
|
||||
|
||||
it('treats arm as idempotent while already confirming', () => {
|
||||
const changes: boolean[] = [];
|
||||
const c = createTapConfirm({ durationMs: 2000, onConfirm: () => {}, onChange: (x) => changes.push(x) });
|
||||
c.arm();
|
||||
c.arm();
|
||||
expect(changes).toEqual([true]);
|
||||
});
|
||||
|
||||
it('cancel closes the window without confirming', () => {
|
||||
const onConfirm = vi.fn();
|
||||
const c = createTapConfirm({ durationMs: 2000, onConfirm });
|
||||
c.arm();
|
||||
c.cancel();
|
||||
expect(c.confirming).toBe(false);
|
||||
vi.advanceTimersByTime(5000);
|
||||
expect(onConfirm).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('dispose clears a pending timer without a revert callback', () => {
|
||||
const changes: boolean[] = [];
|
||||
const c = createTapConfirm({ durationMs: 2000, onConfirm: () => {}, onChange: (x) => changes.push(x) });
|
||||
c.arm();
|
||||
c.dispose();
|
||||
vi.advanceTimersByTime(5000);
|
||||
expect(changes).toEqual([true]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* tapconfirm holds the small state machine behind the "tap to confirm" controls: the
|
||||
* first tap arms a confirmation window of durationMs (during which the view shows a
|
||||
* fading ✅), a second tap within it confirms, and otherwise the window reverts. It is
|
||||
* framework agnostic — a view observes onChange and renders accordingly — so the timing
|
||||
* logic is unit-testable without a DOM. The pending timer is the only side effect.
|
||||
*/
|
||||
export interface TapConfirmOptions {
|
||||
/** Length of the confirmation window in milliseconds. */
|
||||
durationMs: number;
|
||||
/** Invoked once when a confirmation lands inside the window. */
|
||||
onConfirm: () => void;
|
||||
/** Invoked whenever the confirming flag flips, so a view can react. */
|
||||
onChange?: (confirming: boolean) => void;
|
||||
}
|
||||
|
||||
/** TapConfirmController drives a single "tap to confirm" control. */
|
||||
export interface TapConfirmController {
|
||||
/** Whether the confirmation window is currently open. */
|
||||
readonly confirming: boolean;
|
||||
/** Arm the confirmation window; a no-op while it is already open. */
|
||||
arm(): void;
|
||||
/** Confirm within the window: fires onConfirm once and closes the window. A no-op
|
||||
* while the window is closed. */
|
||||
confirm(): void;
|
||||
/** Close the window without confirming (e.g. the control was disabled). */
|
||||
cancel(): void;
|
||||
/** Clear any pending timer; the controller must not be reused afterwards. */
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* createTapConfirm builds a TapConfirmController whose confirmation window lasts
|
||||
* durationMs. onConfirm fires once per confirmed window; onChange (when given)
|
||||
* reports every flip of the confirming flag.
|
||||
*/
|
||||
export function createTapConfirm(opts: TapConfirmOptions): TapConfirmController {
|
||||
let confirming = false;
|
||||
let timer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
function clear(): void {
|
||||
if (timer !== null) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
}
|
||||
function set(next: boolean): void {
|
||||
if (confirming === next) return;
|
||||
confirming = next;
|
||||
opts.onChange?.(next);
|
||||
}
|
||||
return {
|
||||
get confirming() {
|
||||
return confirming;
|
||||
},
|
||||
arm() {
|
||||
if (confirming) return;
|
||||
set(true);
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
set(false);
|
||||
}, opts.durationMs);
|
||||
},
|
||||
confirm() {
|
||||
if (!confirming) return;
|
||||
clear();
|
||||
set(false);
|
||||
opts.onConfirm();
|
||||
},
|
||||
cancel() {
|
||||
if (!confirming) return;
|
||||
clear();
|
||||
set(false);
|
||||
},
|
||||
dispose() {
|
||||
clear();
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user