Loose-files note: gating is a tested function; a redaction refreshes it
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 4m37s
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 4m37s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
33e31a6102
commit
ed2205d6d6
3 changed files with 53 additions and 4 deletions
|
|
@ -14,7 +14,14 @@ import { markAsRead } from '../../utils/notifications';
|
|||
import { getBlobSafeMimeType } from '../../utils/mimeTypes';
|
||||
import { timeDayMonYear } from '../../utils/time';
|
||||
import { getMemberDisplayName } from '../../utils/room';
|
||||
import { Album, AlbumFile, TimelineEvent, lastEvent, looseFiles, looseNote } from './buildAlbums';
|
||||
import {
|
||||
Album,
|
||||
AlbumFile,
|
||||
TimelineEvent,
|
||||
lastEvent,
|
||||
looseFiles,
|
||||
looseNoteFor,
|
||||
} from './buildAlbums';
|
||||
import { folderOf, listFolder, pathLabel } from './albumFolders';
|
||||
import { FileReadBy } from './FileReadBy';
|
||||
import { ShareSet, useShareEnabled } from './ShareSet';
|
||||
|
|
@ -112,8 +119,10 @@ function useLooseFiles(room: Room): AlbumFile[] {
|
|||
useEffect(() => {
|
||||
const on = () => bump((n) => n + 1);
|
||||
room.on(RoomEvent.Timeline, on);
|
||||
room.on(RoomEvent.Redaction, on);
|
||||
return () => {
|
||||
room.off(RoomEvent.Timeline, on);
|
||||
room.off(RoomEvent.Redaction, on);
|
||||
};
|
||||
}, [room]);
|
||||
const events: TimelineEvent[] = room
|
||||
|
|
@ -143,6 +152,12 @@ export function AlbumView({ room, onTimeline }: AlbumViewProps) {
|
|||
const encrypted = room.hasEncryptionStateEvent();
|
||||
const canShare = useShareEnabled(room);
|
||||
const loose = useLooseFiles(room);
|
||||
const looseNote = looseNoteFor(loose, {
|
||||
open: !!open,
|
||||
encrypted,
|
||||
loading,
|
||||
error: !!error,
|
||||
});
|
||||
|
||||
let body: React.ReactNode;
|
||||
if (loading) body = <Text>Loading albums…</Text>;
|
||||
|
|
@ -232,9 +247,9 @@ export function AlbumView({ room, onTimeline }: AlbumViewProps) {
|
|||
<Scroll hideTrack visibility="Hover">
|
||||
<div className={css.Column}>
|
||||
{body}
|
||||
{!open && !encrypted && !loading && !error && loose.length > 0 && (
|
||||
{looseNote && (
|
||||
<Text size="T200" className={css.Dim}>
|
||||
{looseNote(loose)}
|
||||
{looseNote}
|
||||
</Text>
|
||||
)}
|
||||
{/* Stays mounted while an album is open, so a running send keeps its progress. */}
|
||||
|
|
|
|||
|
|
@ -175,3 +175,10 @@ export const looseNote = (files: AlbumFile[]): string => {
|
|||
files.length === 1 ? 'It is' : 'They are'
|
||||
} in the Timeline.`;
|
||||
};
|
||||
|
||||
/** Where the album view stands when it decides whether to show the loose-files note. */
|
||||
export type ViewState = { open: boolean; encrypted: boolean; loading: boolean; error: boolean };
|
||||
|
||||
/** The note for the list view only: never inside an open album, an encrypted zone, or a load that is not finished. */
|
||||
export const looseNoteFor = (files: AlbumFile[], view: ViewState): string =>
|
||||
view.open || view.encrypted || view.loading || view.error ? '' : looseNote(files);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { buildAlbums, looseFiles, looseNote, TimelineEvent } from './buildAlbums';
|
||||
import { buildAlbums, looseFiles, looseNote, looseNoteFor, TimelineEvent } from './buildAlbums';
|
||||
|
||||
// The Commons publisher as it posted before gamecult-ops #121: loose files (no album thread), a
|
||||
// flat `org.gamecult.publish.replaces` key, no info.sha256. The sender must see that, not a
|
||||
|
|
@ -62,6 +62,33 @@ describe('loose files from a poster that does not thread', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('where the loose-files note shows', () => {
|
||||
const loose = looseFiles([file('$a', 'notes.md')]);
|
||||
const list = { open: false, encrypted: false, loading: false, error: false };
|
||||
|
||||
it('on the album list, and only there', () => {
|
||||
expect(looseNoteFor(loose, list)).toContain('notes.md');
|
||||
expect(looseNoteFor(loose, { ...list, open: true })).toBe('');
|
||||
expect(looseNoteFor(loose, { ...list, encrypted: true })).toBe('');
|
||||
expect(looseNoteFor(loose, { ...list, loading: true })).toBe('');
|
||||
expect(looseNoteFor(loose, { ...list, error: true })).toBe('');
|
||||
});
|
||||
|
||||
it('says nothing when there are no loose files', () => {
|
||||
expect(looseNoteFor([], list)).toBe('');
|
||||
});
|
||||
|
||||
it('names m.notice and m.sticker posts as not files', () => {
|
||||
const notice = { ...text('$n', 'hi'), content: { msgtype: 'm.notice', body: 'hi' } };
|
||||
expect(looseFiles([notice])).toEqual([]);
|
||||
});
|
||||
|
||||
it('a file with no name reads as unnamed', () => {
|
||||
const bare: TimelineEvent = { ...file('$b', ''), content: { msgtype: 'm.file', body: '' } };
|
||||
expect(looseNote(looseFiles([bare]))).toContain('unnamed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('the old wire shape inside an album', () => {
|
||||
const root = text('$root', 'handoff/eureka');
|
||||
const albumOf = (replies: TimelineEvent[]) => buildAlbums([{ root, replies }], 'gamecult.org')[0];
|
||||
|
|
|
|||
Loading…
Reference in a new issue