Skip to content

Commit

Permalink
Connected the notification config override
Browse files Browse the repository at this point in the history
  • Loading branch information
Zequez committed Dec 24, 2024
1 parent 437929a commit bfd3e0a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 107 deletions.
103 changes: 11 additions & 92 deletions ui/src/GameSpace/topbar/ActivityLog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<LogType, string> = {
Expand All @@ -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 });
}
</script>

Expand Down
9 changes: 7 additions & 2 deletions ui/src/store/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -26,7 +26,8 @@ export type Delta =
| { type: 'update-element'; element: Partial<GElement> }
| { 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<NotificationsConfig> };

export function initialState(pubKey: string): GameSpace {
return {
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 1 addition & 12 deletions ui/src/store/index.ts
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion ui/src/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type GameSpace = {
playersSlots: PlayerSlot[];
lastChangeAt: number;
activityLog: Log[];
notificationsConfigOverride: Record<AgentKey, NotificationsConfig>;
notificationsConfigOverride: Record<AgentKey, Partial<NotificationsConfig>>;
};

export const DEFAULT_NOTIFICATIONS_CONFIG: NotificationsConfig = {
Expand Down

0 comments on commit bfd3e0a

Please sign in to comment.