GameCult theme, steward-grouped project rooms, preview base override
Adds the gamecult-theme (brand palette, softer radii, Ubuntu/Montserrat/Plex Mono), makes it the default, hides the member drawer by default, defaults to bubble layout, groups rooms by org.gamecult.steward in the space nav (collapsed on phones), and lets CINNY_BASE set Vite's base for a sub-path preview build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1e6412ed5b
commit
a588ab82b3
13 changed files with 471 additions and 28 deletions
63
src/app/features/steward-groups/stewardGroups.test.ts
Normal file
63
src/app/features/steward-groups/stewardGroups.test.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { groupByStewards, parseSteward, StewardEntry } from './stewardGroups';
|
||||
|
||||
const room = (roomId: string, parentId = '!projects') => ({ roomId, parentId });
|
||||
const space = (roomId: string) => ({ roomId, space: true as const });
|
||||
|
||||
const base = {
|
||||
spaceId: '!top',
|
||||
isGroupOpen: () => true,
|
||||
keepVisible: () => false,
|
||||
};
|
||||
|
||||
const names = (out: StewardEntry<{ roomId: string }>[]) =>
|
||||
out.map((e) => (e.type === 'group' ? `G:${e.label}:${e.count}` : e.item.roomId));
|
||||
|
||||
describe('groupByStewards', () => {
|
||||
const stewards: Record<string, string> = { '!a': 'Void', '!b': 'Eureka', '!c': 'Void' };
|
||||
const stewardOf = (id: string) => stewards[id];
|
||||
|
||||
it('groups by steward, sorted by name, with unstewarded rooms first', () => {
|
||||
const out = groupByStewards([room('!a'), room('!x'), room('!b'), room('!c')], {
|
||||
...base,
|
||||
stewardOf,
|
||||
});
|
||||
expect(names(out)).toEqual(['!x', 'G:Eureka:1', '!b', 'G:Void:2', '!a', '!c']);
|
||||
});
|
||||
|
||||
it('collapsed groups hide rooms except kept-visible ones', () => {
|
||||
const out = groupByStewards([room('!a'), room('!b'), room('!c')], {
|
||||
...base,
|
||||
stewardOf,
|
||||
isGroupOpen: () => false,
|
||||
keepVisible: (id) => id === '!c',
|
||||
});
|
||||
expect(names(out)).toEqual(['G:Eureka:1', 'G:Void:2', '!c']);
|
||||
});
|
||||
|
||||
it('degrades to the original order when no room has steward state', () => {
|
||||
const out = groupByStewards([room('!1'), space('!s'), room('!2', '!s')], {
|
||||
...base,
|
||||
stewardOf: () => undefined,
|
||||
});
|
||||
expect(names(out)).toEqual(['!1', '!s', '!2']);
|
||||
});
|
||||
|
||||
it('does not merge runs separated by a space header', () => {
|
||||
const out = groupByStewards([room('!a'), space('!s'), room('!c', '!s')], {
|
||||
...base,
|
||||
stewardOf,
|
||||
});
|
||||
expect(out.filter((e) => e.type === 'group')).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseSteward', () => {
|
||||
it('accepts a string and rejects junk', () => {
|
||||
expect(parseSteward({ steward: ' Void ' })).toBe('Void');
|
||||
expect(parseSteward({ steward: 3 })).toBeUndefined();
|
||||
expect(parseSteward({ steward: ' ' })).toBeUndefined();
|
||||
expect(parseSteward(undefined)).toBeUndefined();
|
||||
expect(parseSteward(null)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
91
src/app/features/steward-groups/stewardGroups.ts
Normal file
91
src/app/features/steward-groups/stewardGroups.ts
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
* Splits runs of rooms that carry an `org.gamecult.steward` state event into
|
||||
* collapsible per-steward groups. Pure: the caller supplies the lookups, so the
|
||||
* grouping is testable without a Matrix client.
|
||||
*/
|
||||
export const STEWARD_EVENT_TYPE = 'org.gamecult.steward';
|
||||
|
||||
export type HierarchyLike = { roomId: string; parentId?: string; space?: true };
|
||||
|
||||
export type StewardEntry<T extends HierarchyLike> =
|
||||
| { type: 'item'; item: T }
|
||||
| { type: 'group'; id: string; label: string; open: boolean; count: number };
|
||||
|
||||
export const makeStewardGroupId = (spaceId: string, parentId: string, steward: string) =>
|
||||
`${spaceId}|${parentId}|steward:${steward}`;
|
||||
|
||||
export type StewardGroupOptions = {
|
||||
spaceId: string;
|
||||
/** steward name of a room, or undefined when the room has no (valid) steward state */
|
||||
stewardOf: (roomId: string) => string | undefined;
|
||||
isGroupOpen: (groupId: string) => boolean;
|
||||
/** rooms that stay visible inside a collapsed group (selected, unread, in a call) */
|
||||
keepVisible: (roomId: string) => boolean;
|
||||
};
|
||||
|
||||
const byLabel = (a: string, b: string) =>
|
||||
a.localeCompare(b, undefined, { sensitivity: 'base' }) || a.localeCompare(b);
|
||||
|
||||
export const groupByStewards = <T extends HierarchyLike>(
|
||||
items: T[],
|
||||
{ spaceId, stewardOf, isGroupOpen, keepVisible }: StewardGroupOptions
|
||||
): StewardEntry<T>[] => {
|
||||
const out: StewardEntry<T>[] = [];
|
||||
|
||||
const flush = (run: T[]) => {
|
||||
if (run.length === 0) return;
|
||||
const groups = new Map<string, T[]>();
|
||||
const loose: T[] = [];
|
||||
run.forEach((item) => {
|
||||
const steward = stewardOf(item.roomId);
|
||||
if (steward === undefined) {
|
||||
loose.push(item);
|
||||
return;
|
||||
}
|
||||
const list = groups.get(steward);
|
||||
if (list) list.push(item);
|
||||
else groups.set(steward, [item]);
|
||||
});
|
||||
|
||||
// No steward state anywhere in this run: leave the list exactly as Cinny built it.
|
||||
if (groups.size === 0) {
|
||||
run.forEach((item) => out.push({ type: 'item', item }));
|
||||
return;
|
||||
}
|
||||
|
||||
loose.forEach((item) => out.push({ type: 'item', item }));
|
||||
Array.from(groups.keys())
|
||||
.sort(byLabel)
|
||||
.forEach((steward) => {
|
||||
const rooms = groups.get(steward) ?? [];
|
||||
const id = makeStewardGroupId(spaceId, rooms[0].parentId ?? spaceId, steward);
|
||||
const open = isGroupOpen(id);
|
||||
out.push({ type: 'group', id, label: steward, open, count: rooms.length });
|
||||
rooms
|
||||
.filter((item) => open || keepVisible(item.roomId))
|
||||
.forEach((item) => out.push({ type: 'item', item }));
|
||||
});
|
||||
};
|
||||
|
||||
let run: T[] = [];
|
||||
items.forEach((item) => {
|
||||
if (item.space) {
|
||||
flush(run);
|
||||
run = [];
|
||||
out.push({ type: 'item', item });
|
||||
return;
|
||||
}
|
||||
run.push(item);
|
||||
});
|
||||
flush(run);
|
||||
return out;
|
||||
};
|
||||
|
||||
/** Reads `steward` from raw state event content; anything unusable is "no steward". */
|
||||
export const parseSteward = (content: unknown): string | undefined => {
|
||||
if (typeof content !== 'object' || content === null) return undefined;
|
||||
const { steward } = content as { steward?: unknown };
|
||||
if (typeof steward !== 'string') return undefined;
|
||||
const trimmed = steward.trim();
|
||||
return trimmed === '' ? undefined : trimmed;
|
||||
};
|
||||
71
src/app/features/steward-groups/useStewardGroups.ts
Normal file
71
src/app/features/steward-groups/useStewardGroups.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { MatrixClient, MatrixEvent, RoomStateEvent } from 'matrix-js-sdk';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
import { useAtom } from 'jotai';
|
||||
import { ScreenSize, useScreenSizeContext } from '../../hooks/useScreenSize';
|
||||
import {
|
||||
groupByStewards,
|
||||
HierarchyLike,
|
||||
parseSteward,
|
||||
StewardEntry,
|
||||
STEWARD_EVENT_TYPE,
|
||||
} from './stewardGroups';
|
||||
|
||||
// Explicit open/closed choices by group id. Absent = default: closed on phones, open elsewhere.
|
||||
const stewardGroupChoicesAtom = atomWithStorage<Record<string, boolean>>(
|
||||
'gamecultStewardGroupOpen',
|
||||
{}
|
||||
);
|
||||
|
||||
type Options<T> = {
|
||||
mx: MatrixClient;
|
||||
spaceId: string;
|
||||
items: T[];
|
||||
keepVisible: (roomId: string) => boolean;
|
||||
};
|
||||
|
||||
export const useStewardGroups = <T extends HierarchyLike>({
|
||||
mx,
|
||||
spaceId,
|
||||
items,
|
||||
keepVisible,
|
||||
}: Options<T>) => {
|
||||
const mobile = useScreenSizeContext() === ScreenSize.Mobile;
|
||||
const [choices, setChoices] = useAtom(stewardGroupChoicesAtom);
|
||||
const [stateVersion, setStateVersion] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const onState = (mEvent: MatrixEvent) => {
|
||||
if (mEvent.getType() === STEWARD_EVENT_TYPE) setStateVersion((v) => v + 1);
|
||||
};
|
||||
mx.on(RoomStateEvent.Events, onState);
|
||||
return () => {
|
||||
mx.removeListener(RoomStateEvent.Events, onState);
|
||||
};
|
||||
}, [mx]);
|
||||
|
||||
const stewardOf = useCallback(
|
||||
(roomId: string) =>
|
||||
// stateVersion is read so a late-arriving steward event re-derives this lookup
|
||||
stateVersion >= 0
|
||||
? parseSteward(
|
||||
mx.getRoom(roomId)?.currentState.getStateEvents(STEWARD_EVENT_TYPE, '')?.getContent()
|
||||
)
|
||||
: undefined,
|
||||
[mx, stateVersion]
|
||||
);
|
||||
|
||||
const isGroupOpen = useCallback((id: string) => choices[id] ?? !mobile, [choices, mobile]);
|
||||
|
||||
const entries: StewardEntry<T>[] = useMemo(
|
||||
() => groupByStewards(items, { spaceId, stewardOf, isGroupOpen, keepVisible }),
|
||||
[items, spaceId, stewardOf, isGroupOpen, keepVisible]
|
||||
);
|
||||
|
||||
const toggleGroup = useCallback(
|
||||
(id: string) => setChoices((prev) => ({ ...prev, [id]: !(prev[id] ?? !mobile) })),
|
||||
[setChoices, mobile]
|
||||
);
|
||||
|
||||
return { entries, toggleGroup };
|
||||
};
|
||||
Loading…
Reference in a new issue