diff --git a/ui/src/GameSpace/topbar/ActivityLog.svelte b/ui/src/GameSpace/topbar/ActivityLog.svelte index eb3badc..a92dc00 100644 --- a/ui/src/GameSpace/topbar/ActivityLog.svelte +++ b/ui/src/GameSpace/topbar/ActivityLog.svelte @@ -5,7 +5,13 @@ import { relativeTimeFormat, timeFormat } from '~/lib/util'; import { tooltip } from '~/shared/tooltip'; import TopBarDropButton from '../ui/TopBarDropButton.svelte'; - import type { GameSpaceSyn, AgentKey, LogType, Log } from '~/store'; + import { + type GameSpaceSyn, + type AgentKey, + type LogType, + type Log, + DEFAULT_NOTIFICATIONS_CONFIG, + } from '~/store'; import AgentAvatar from '~/shared/AgentAvatar.svelte'; export let gameSpace: GameSpaceSyn; @@ -15,93 +21,6 @@ $: notificationsConfigOverride = $state.notificationsConfigOverride; $: activityLog = $state.activityLog; - // let log: Log[] = [ - // { - // message: 'Ezequiel joined at slot 4', - // time: 1735041958600, - // seenBy: [], - // type: 'join', - // agentKey: '', - // }, - // { - // message: 'Ezequiel moved piece', - // time: 1735021958600, - // seenBy: [], - // type: 'move', - // agentKey: '', - // }, - // { - // message: 'Ezequiel moved piece', - // time: 1735020958600, - // seenBy: [], - // type: 'move', - // agentKey: '', - // }, - // { - // message: 'Ezequiel ended his turn', - // time: 1735011958600, - // seenBy: [], - // type: 'turn', - // agentKey: '', - // }, - // { - // message: 'Ezequiel moved piece', - // time: 1735020958600, - // seenBy: [], - // type: 'move', - // agentKey: '', - // }, - // { - // message: 'Ezequiel ended his turn', - // time: 1735011958600, - // seenBy: [], - // type: 'turn', - // agentKey: '', - // }, - // { - // message: 'Ezequiel moved piece', - // time: 1735020958600, - // seenBy: [], - // type: 'move', - // agentKey: '', - // }, - // { - // message: 'Ezequiel ended his turn', - // time: 1735011958600, - // seenBy: [], - // type: 'turn', - // agentKey: '', - // }, - // { - // message: 'Ezequiel moved piece', - // time: 1735020958600, - // seenBy: [], - // type: 'move', - // agentKey: '', - // }, - // { - // message: 'Ezequiel ended his turn', - // time: 1735011958600, - // seenBy: [], - // type: 'turn', - // agentKey: '', - // }, - // { - // message: 'Ezequiel moved piece', - // time: 1735020958600, - // seenBy: [], - // type: 'move', - // agentKey: '', - // }, - // { - // message: 'Ezequiel ended his turn', - // time: 1735011958600, - // seenBy: [], - // type: 'turn', - // agentKey: '', - // }, - // ]; - $: notificationsCount = activityLog.filter((l) => !l.seenBy.includes(agentKey)).length; const LOG_TYPES_ICONS: Record = { @@ -119,17 +38,17 @@ function markAsSeen() { gameSpace.change({ type: 'seen-activity-log' }); - // log = log.map((l) => ({ ...l, seenBy: [...l.seenBy, agentKey] })); } $: notificationIsActivatedForLogType = (logType: LogType) => - notificationsConfigOverride[agentKey]?.[logType] ?? notificationsConfigOverride[logType]; + notificationsConfigOverride[agentKey]?.[logType] ?? DEFAULT_NOTIFICATIONS_CONFIG[logType]; function setNotificationForLogType(logType: LogType, value: boolean) { - notificationsConfigOverride[agentKey] = { - ...notificationsConfigOverride[agentKey], + const newConfig = { + ...(notificationsConfigOverride[agentKey] || {}), [logType]: value, }; + gameSpace.change({ type: 'set-notifications-config-override', config: newConfig }); } diff --git a/ui/src/store/grammar.ts b/ui/src/store/grammar.ts index e01f0ef..588d6fa 100644 --- a/ui/src/store/grammar.ts +++ b/ui/src/store/grammar.ts @@ -7,7 +7,7 @@ import { colorSequence } from '~/lib/util'; import * as elements from '../GameSpace/elements'; import { LIBRARY } from './library'; -import type { GameSpace, GElement, LogType } from './types'; +import type { GameSpace, GElement, LogType, NotificationsConfig } from './types'; export type Delta = | { type: 'set-is-archived'; value: boolean } @@ -26,7 +26,8 @@ export type Delta = | { type: 'update-element'; element: Partial } | { type: 'remove-element'; uuid: string } | { type: 'add-log'; log: { message: string; type: LogType; pubKey?: string } } - | { type: 'seen-activity-log' }; + | { type: 'seen-activity-log' } + | { type: 'set-notifications-config-override'; config: Partial }; export function initialState(pubKey: string): GameSpace { return { @@ -209,6 +210,10 @@ export const applyDelta = (delta: Delta, $state: GameSpace, context: { pubKey: s case 'add-log': addLog(delta.log); break; + case 'set-notifications-config-override': { + $state.notificationsConfigOverride[context.pubKey] = delta.config; + break; + } } function getLabel(elType: string) { diff --git a/ui/src/store/index.ts b/ui/src/store/index.ts index fa9bbf3..19166b0 100644 --- a/ui/src/store/index.ts +++ b/ui/src/store/index.ts @@ -1,17 +1,6 @@ export { type Delta } from './grammar'; export { createRootStore, type RootStore, setContext, getContext } from './rootStore'; export { type GameSpaceSyn } from './gameSpaceStore'; -export type { - GameSpace, - LockConfig, - GElementBase, - GElement, - PlayerSlot, - AgentKey, - NotificationsConfig, - DEFAULT_NOTIFICATIONS_CONFIG, - Log, - LogType, -} from './types'; +export * from './types'; export { type LibraryElement, createElement, LIBRARY } from './library'; export * as presets from './presets'; diff --git a/ui/src/store/types.ts b/ui/src/store/types.ts index 6fdcb83..dba031c 100644 --- a/ui/src/store/types.ts +++ b/ui/src/store/types.ts @@ -19,7 +19,7 @@ export type GameSpace = { playersSlots: PlayerSlot[]; lastChangeAt: number; activityLog: Log[]; - notificationsConfigOverride: Record; + notificationsConfigOverride: Record>; }; export const DEFAULT_NOTIFICATIONS_CONFIG: NotificationsConfig = {