Files
gerbeur/shared/community.ts
khannurien 51439f475d
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 51s
Build and Deploy Static Documentation Site / build-and-push (push) Successful in 26s
v4: the GeoCities marquee scrolls the community feed, what the site's members are doing — it crawled three canned lines, a welcome, "best viewed in Netscape Navigator" and "under construction", which said nothing of the site. The feed is a list any style may show (CommunityFeed.tsx), which GeoCities lays out along its marquee: who is online, the week's dumps, upvotes, comments and chat messages, linking to /community, its most upvoted dump, then the 12 latest things done in public, newest first, each ending on how long ago it was: a public dump posted, a public playlist created, a comment or an upvote on a public dump, someone joining and who invited them. Every name and title links to its page. A dump has one comment line and one upvote line at most, its latest, so that a thread or a popular dump doesn't fill the feed. GET /api/community/feed serves it, signed in only (community-service.ts): the events are read from the tables on each request, the week's figures are those /community already keeps, as of its last refresh. A signed-out visitor has no marquee. CommunityFeedProvider holds the feed around every page, so that it outlives the header each page renders anew, fetches it only while a component shows it, and fetches it again two seconds after the socket last told of a dump, a comment, a vote, a playlist, a rename, a deletion or a reconnection: the socket's messages don't carry a feed's lines, and the server's query stays the one place that decides what the feed holds. Someone joining comes with no message, and shows at the next of those. The crawl goes at 50 pixels a second however much the feed holds, Marquee.tsx measuring one copy for the stylesheet to work the loop's length out from, where a fixed 36 seconds would have sped up with every line. A loop shows what the feed held when it began: text that changed mid-crawl would jump, so what came meanwhile waits for the next loop, which also brings the times up to date. The next page's marquee carries on from where the last one's had got to, rather than from the start. The marquee was hidden from assistive technology as decoration; its first copy is now a labelled list of links, the second, which the seamless loop needs, hidden and out of the tab order. A link that takes the focus stops the crawl and the line scrolls to it, the pointer pauses it as before, and with reduced motion the line shows once, still, follows the feed as it changes and scrolls by hand. The sentences a notification also says, "posted", "upvoted", "commented on", share its translations. The tests' DOM gets an AnimationEvent before React loads (src/test/before-react.ts): finding none, React listened for the animation events under their WebKit names, and a test's "animationiteration" reached no handler.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 07:38:44 +00:00

118 lines
3.7 KiB
TypeScript

/**
* What the whole site did, told two ways. Over a period, one of the digests'
* cadences: its most upvoted dumps, who joined, the new public playlists and
* the totals, which the `/community` page shows as they were at the server's
* last refresh and the digests gather for each reader's own period. And as it
* happens: the community feed, the latest things its members did in public,
* which the GeoCities style's marquee scrolls.
*
* @module
*/
import type { Dump } from "./dump.ts";
import type { OwnedItem } from "./paths.ts";
import type { Playlist } from "./playlist.ts";
import type { PublicUser } from "./user.ts";
/**
* Returned by `GET /api/community?period=` to the `Community` page, and
* gathered by `community-service.ts`, which the digests read too.
*/
export interface CommunityStats {
/** The period covered, from `from` to `to`. */
from: Date;
to: Date;
/** The most upvoted public dumps posted in it, 10 at most. */
top: Dump[];
/** In sign-up order, each with `invitedByUsername` when someone invited them. */
members: PublicUser[];
/** The public playlists created in it, the fullest first, with `dumpCount`. */
playlists: Playlist[];
chatMessages: number;
/** Public dumps posted, upvotes cast and comments written in it. */
totals: { dumps: number; upvotes: number; comments: number };
}
/**
* Names a dump or a playlist in a {@link CommunityEvent}: its title, and what
* `dumpPath` or `playlistPath` builds its page's path from.
*/
export interface CommunityItem extends OwnedItem {
title: string;
}
/** What every {@link CommunityEvent} carries. */
interface CommunityEventBase {
/**
* The event's kind and what it is about, `dump_upvoted:<dump id>`: unique in
* a feed, where a dump has one event of each kind at most.
*/
id: string;
at: Date;
/** Who did it, by their current name. */
username: string;
}
/** A public dump was posted. A dump made public later keeps its date. */
export interface DumpPostedEvent extends CommunityEventBase {
type: "dump_posted";
dump: CommunityItem;
}
/** A public playlist was created. */
export interface PlaylistCreatedEvent extends CommunityEventBase {
type: "playlist_created";
playlist: CommunityItem;
}
/**
* A public dump got a comment. However many it got, the feed tells of its
* latest alone.
*/
export interface DumpCommentedEvent extends CommunityEventBase {
type: "dump_commented";
dump: CommunityItem;
/** For the `#comment-<id>` anchor on the dump's page. */
commentId: string;
}
/** A public dump got an upvote, told as {@link DumpCommentedEvent} is. */
export interface DumpUpvotedEvent extends CommunityEventBase {
type: "dump_upvoted";
dump: CommunityItem;
}
/** Someone joined the site: `username` is theirs. */
export interface UserJoinedEvent extends CommunityEventBase {
type: "user_joined";
invitedByUsername?: string;
}
/** One line of the community feed, told apart by `type`. */
export type CommunityEvent =
| DumpPostedEvent
| PlaylistCreatedEvent
| DumpCommentedEvent
| DumpUpvotedEvent
| UserJoinedEvent;
/**
* Returned by `GET /api/community/feed` to `CommunityFeedProvider`, which
* asks again as the socket tells of changes, and rendered by the
* `CommunityFeed` component with who is online, which the client knows from
* its socket. `community-service.ts` gathers it. Everything in it is public:
* every reader gets the same feed.
*/
export interface CommunityFeed {
/** The latest events, newest first, 12 at most. */
events: CommunityEvent[];
/**
* The last week's figures, as `/community` shows them: as of the server's
* last refresh.
*/
week: Pick<CommunityStats, "totals" | "chatMessages"> & {
/** The week's most upvoted dump, when one was upvoted. */
top?: CommunityItem;
};
}