@estiva-app/ui 0.105.0 → 0.107.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,8 +62,10 @@ import { ConversationCard } from '@estiva-app/ui'
62
62
  - **Edit opens your box**: `editor` draws your **CommentBox** edit form; call `done` when it saves or cancels. To open it again after a refused save, hold `editing` yourself.
63
63
  - **Resolve opens the dialog**: **ResolveDialog**, then `onResolve(note)`. Answer `false` when it was refused, and pass `resolveRefused` (why, in plain words); the dialog stays and says it.
64
64
  - **Delete asks first**: **ConfirmDialog**, then `onDelete()`. Answer `false` when it was refused, and pass `deleteRefused` (why, in plain words): the question stays and says it, as Resolve's does.
65
+ - **A reaction answers**: `reactions.onToggle` returns the relay's answer, `{ accepted: false, reason }` with the reason as it came. The card says "Not reacted: *why*." under the reactions in `@estiva-app/conversation`'s plain words, until the next reaction on it or until it goes; only the latest reaction's answer is said. Hold no refusal of your own.
65
66
  - **A refusal is said only in the question it answered.** Keep it in your own state and never clear it: a question opened again says nothing until its own press is refused.
66
67
  - **Deleted** keeps its `about`: what it was on stays above "This comment was deleted.", for the replies under it.
68
+ - **Not shown** (`unseen`): a comment the read did not return, with no deletion by its author (SPEC §6.5). Drawn as **Deleted**, in its own words: "This comment can’t be shown." Never say it was deleted: it may only be outside the read.
67
69
  - `time` is your words for it ("11:08 AM"); `at` is the moment (ms), from which the card says the exact date and time on hover. Never a tooltip of your own round `time`.
68
70
  - A press on the card is `onClick` (its thread opens); a press on a button, a link or anything marked `data-interactive` inside it is not.
69
71
  - The strip shows while the card is pointed at or has focus, and holds while its reactions or its menu are open. A head long enough to reach it (a narrow card, a time in words, "(edited)") fades out 8px before it; nothing in the head moves.
@@ -76,6 +78,7 @@ import { ConversationCard } from '@estiva-app/ui'
76
78
  | A card that opens on a press is a Tab stop: reaching it shows its actions, Enter or Space opens it | a `tabIndex` and a key handler | |
77
79
  | Asks before it deletes | a confirm dialog | |
78
80
  | Says a refusal only in the question it answered | clearing it when the question closes | |
81
+ | Says why a reaction was refused, in the words every app says, until the next reaction or until the card goes | a refusal state, or words for the relay's reasons | |
79
82
  | Says the exact date and time under the pointer, from `at` | a tooltip round the time | |
80
83
  | Opens the Resolve dialog, and closes it once resolved | a dialog and its open state | |
81
84
  | Says it is resolved, with who and the note, and hides nothing of it | a resolved line or chip of your own | |
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite'
2
2
  import { useState } from 'react'
3
3
  import { userEvent, within } from 'storybook/test'
4
4
  import { ConversationCard, type ConversationCardProps } from './ConversationCard'
5
- import { AT, Column, EditBox, Files, LONG, Mentions, ONE, SOME, THREE, TWO, WithBlock, WithCard, WORDS, YOU, useReactions } from './conversation.examples'
5
+ import { AT, Column, EditBox, Files, LONG, Mentions, ONE, RELAY_SAYS, SOME, THREE, TWO, WithBlock, WithCard, WORDS, YOU, useReactions, type RelaySays } from './conversation.examples'
6
6
  import { RichText } from './RichText'
7
7
  import { MenuItem } from './Menu'
8
8
  import type { ReactionCount } from './ReactionRow'
@@ -47,6 +47,14 @@ function Live({ start, resolvedAt, deletable = true, ...props }: ConversationCar
47
47
  )
48
48
  }
49
49
 
50
+ type CardWithRefusal = ConversationCardProps & { refusal: RelaySays }
51
+
52
+ /** A card whose every reaction the relay refuses, for `refusal`. */
53
+ function RefusingReactions({ refusal, ...props }: CardWithRefusal) {
54
+ const reacting = useReactions(SOME)
55
+ return <ConversationCard {...props} reactions={{ ...reacting, onToggle: () => new Promise((resolve) => setTimeout(() => resolve({ accepted: false, reason: RELAY_SAYS[refusal] }), 400)) }} />
56
+ }
57
+
50
58
  /** Someone's comment. */
51
59
  export const Comment: Story = { render: (args) => <Live {...args} /> }
52
60
 
@@ -88,6 +96,9 @@ export const DeletedOnAPart: Story = {
88
96
  render: (args) => <Live {...args} deleted about={<QuotedLine words="the words this comment was on" />} replies={{ count: 2, faces: [TWO, THREE], last: '11:40 AM' }} />,
89
97
  }
90
98
 
99
+ /** Not read, and nothing says it was deleted: drawn as a deleted one, never said to be deleted (SPEC §6.5, Miky, 6 November). */
100
+ export const NotShown: Story = { name: 'Not shown', render: (args) => <Live {...args} unseen replies={{ count: 1, faces: [TWO], last: '11:40 AM' }} /> }
101
+
91
102
  /** Pictures and files under the words. */
92
103
  export const WithFiles: Story = { name: 'Files', render: (args) => <Live {...args} files={<Files />} /> }
93
104
 
@@ -146,14 +157,30 @@ export const Selected: Story = { render: (args) => <Live {...args} selected repl
146
157
  /** Being edited, in the kit's box. */
147
158
  export const Editing: Story = { render: (args) => <Live {...args} author={YOU} own editing /> }
148
159
 
149
- /** An edit that was refused: the box opens again, and says why. */
150
- export const EditRefused: Story = {
160
+ /** An edit that was refused: Save, and the box says why. Pick what the relay said in the controls. */
161
+ export const EditRefused: StoryObj<CardWithRefusal> = {
151
162
  name: 'Edit refused',
152
- render: (args) => <ConversationCard {...args} author={YOU} own editing editor={(done) => <EditBox text={WORDS} done={done} refuse />} />,
163
+ args: { refusal: 'Too long' },
164
+ argTypes: { refusal: { control: 'select', options: Object.keys(RELAY_SAYS) } },
165
+ render: ({ refusal, ...args }) => <ConversationCard {...args} author={YOU} own editing editor={(done) => <EditBox text={WORDS} done={done} refuse={refusal} />} />,
166
+ play: async ({ canvasElement }) => {
167
+ await userEvent.click(within(canvasElement).getByRole('button', { name: 'Save' }))
168
+ },
153
169
  }
154
170
 
155
- /** A reaction that was refused: said under the reactions. */
156
- export const ReactionRefused: Story = { name: 'Reaction refused', render: (args) => <Live {...args} start={SOME} reactionRefused="try again in a moment" /> }
171
+ /**
172
+ * A reaction that was refused: said under the reactions until the next reaction here, or until the card goes. Pick
173
+ * what the relay said in the controls; the story presses a reaction.
174
+ */
175
+ export const ReactionRefused: StoryObj<CardWithRefusal> = {
176
+ name: 'Reaction refused',
177
+ args: { refusal: 'Deleted, or no longer yours to write beside' },
178
+ argTypes: { refusal: { control: 'select', options: Object.keys(RELAY_SAYS) } },
179
+ render: ({ refusal, ...args }) => <RefusingReactions {...args} refusal={refusal} />,
180
+ play: async ({ canvasElement }) => {
181
+ await userEvent.click(within(canvasElement).getByRole('button', { name: 'Makes sense, 2' }))
182
+ },
183
+ }
157
184
 
158
185
  /** Nothing can be changed: no strip, reactions only shown. */
159
186
  export const ReadOnly: Story = { name: 'Read-only', render: (args) => <Live {...args} readOnly start={SOME} replies={{ count: 2, faces: [TWO, THREE], last: '12:02 PM' }} /> }
@@ -1,7 +1,7 @@
1
1
  // @vitest-environment jsdom
2
2
  import { useState } from 'react'
3
3
  import { afterEach, describe, expect, it, vi } from 'vitest'
4
- import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
4
+ import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
5
5
  import userEvent from '@testing-library/user-event'
6
6
  import { ConversationCard, ReplyCard } from './ConversationCard'
7
7
  import { PinnedComment } from './PinnedComment'
@@ -142,6 +142,28 @@ describe('ConversationCard', () => {
142
142
  expect(screen.getByText('3 replies')).toBeTruthy()
143
143
  })
144
144
 
145
+ // SPEC §6.5's "not returned" (Miky, 6 November): never said to be deleted, and closed as a deleted one is.
146
+ it('says a comment that was not read can’t be shown, never that it was deleted, and offers nothing on it', () => {
147
+ render(
148
+ <ConversationCard author={ONE} time="11:08 AM" unseen own onDelete={() => {}} onReply={() => {}} onResolve={() => {}} replies={{ count: 1 }}>
149
+ Words
150
+ </ConversationCard>,
151
+ )
152
+ expect(screen.getByText('This comment can’t be shown.')).toBeTruthy()
153
+ expect(screen.queryByText('This comment was deleted.')).toBeNull()
154
+ expect(screen.queryByText('Words')).toBeNull()
155
+ expect(screen.queryByRole('button', { name: 'More actions' })).toBeNull()
156
+ expect(screen.queryByRole('button', { name: /resolve/i })).toBeNull()
157
+ expect(screen.getByText('1 reply')).toBeTruthy()
158
+ })
159
+
160
+ it('a thread whose comment was not read pins "can’t be shown" above its replies, not the comment’s words', () => {
161
+ render(<PinnedComment author={ONE} time="Today at 11:08 AM" words="The comment" unseen />)
162
+ expect(screen.getByText('This comment can’t be shown.')).toBeTruthy()
163
+ expect(screen.queryByText('The comment')).toBeNull()
164
+ expect(screen.queryByText('This comment was deleted.')).toBeNull()
165
+ })
166
+
145
167
  // Leaf's column kept it, and now every app does (Katerina, 3 November): the replies still talk about that place.
146
168
  it('a deleted comment still says what it was on, above "This comment was deleted."', () => {
147
169
  render(
@@ -179,6 +201,68 @@ describe('ConversationCard', () => {
179
201
  })
180
202
  })
181
203
 
204
+ describe('a refused reaction (ONE-4)', () => {
205
+ const OPTIONS = [{ emoji: '👍', label: 'Makes sense' }]
206
+ const row = (onToggle: (emoji: string) => Promise<{ accepted: true } | { accepted: false; reason: unknown }>) => ({
207
+ reactions: [{ emoji: '👍', by: ['a', 'b'] }],
208
+ options: OPTIONS,
209
+ nameOf: () => 'Someone',
210
+ onToggle,
211
+ })
212
+ const settle = () => act(async () => {
213
+ for (let i = 0; i < 5; i++) await Promise.resolve()
214
+ })
215
+
216
+ it('says why in plain words under the reactions, never the relay’s', async () => {
217
+ render(
218
+ <ConversationCard author={ONE} time="11:08 AM" reactions={row(async () => ({ accepted: false, reason: 'invalid: reaction target event not found' }))}>
219
+ Words
220
+ </ConversationCard>,
221
+ )
222
+ fireEvent.click(screen.getByRole('button', { name: 'Makes sense, 2' }))
223
+ await settle()
224
+ expect(screen.getByText('Not reacted: this message was deleted, or you can no longer write here.')).toBeTruthy()
225
+ expect(screen.queryByText(/invalid:/)).toBeNull()
226
+ })
227
+
228
+ it('is gone on the next reaction, and a reply’s works the same', async () => {
229
+ const answers: ((a: { accepted: true } | { accepted: false; reason: unknown }) => void)[] = []
230
+ const onToggle = () => new Promise<{ accepted: true } | { accepted: false; reason: unknown }>((resolve) => answers.push(resolve))
231
+ render(
232
+ <ReplyCard author={ONE} time="11:40 AM" reactions={row(onToggle)}>
233
+ A reply
234
+ </ReplyCard>,
235
+ )
236
+ fireEvent.click(screen.getByRole('button', { name: 'Makes sense, 2' }))
237
+ answers[0]({ accepted: false, reason: 'rate-limited: slow down' })
238
+ await settle()
239
+ expect(screen.getByText('Not reacted: too many at once, try again in a moment.')).toBeTruthy()
240
+ fireEvent.click(screen.getByRole('button', { name: 'Makes sense, 2' }))
241
+ expect(screen.queryByText(/Not reacted/)).toBeNull()
242
+ answers[1]({ accepted: true })
243
+ await settle()
244
+ expect(screen.queryByText(/Not reacted/)).toBeNull()
245
+ })
246
+
247
+ it('says only the latest reaction’s answer: an earlier refusal arriving late does not replace it', async () => {
248
+ const answers: ((a: { accepted: true } | { accepted: false; reason: unknown }) => void)[] = []
249
+ const onToggle = () => new Promise<{ accepted: true } | { accepted: false; reason: unknown }>((resolve) => answers.push(resolve))
250
+ render(
251
+ <ConversationCard author={ONE} time="11:08 AM" reactions={row(onToggle)}>
252
+ Words
253
+ </ConversationCard>,
254
+ )
255
+ fireEvent.click(screen.getByRole('button', { name: 'Makes sense, 2' }))
256
+ fireEvent.click(screen.getByRole('button', { name: 'Makes sense, 2' }))
257
+ answers[1]({ accepted: false, reason: 'rate-limited: slow down' })
258
+ await settle()
259
+ answers[0]({ accepted: false, reason: 'invalid: reaction target event not found' })
260
+ await settle()
261
+ expect(screen.getByText('Not reacted: too many at once, try again in a moment.')).toBeTruthy()
262
+ expect(screen.queryByText(/this message was deleted/)).toBeNull()
263
+ })
264
+ })
265
+
182
266
  describe('ReplyCard', () => {
183
267
  it('asks before it deletes your reply', async () => {
184
268
  const user = userEvent.setup()
@@ -1,4 +1,5 @@
1
1
  import { useContext, useLayoutEffect, useRef, useState, type ReactNode, type RefObject } from 'react'
2
+ import { refusalReason } from '@estiva-app/conversation'
2
3
  import { IconArrowNarrowRight, IconCircleCheck, IconDotsVertical } from '@tabler/icons-react'
3
4
  import { Avatar } from './Avatar'
4
5
  import { Card } from './Card'
@@ -15,6 +16,7 @@ import { ReactionRow, type ReactionRowProps } from './ReactionRow'
15
16
  import { RepliesRow, type RepliesRowProps } from './RepliesRow'
16
17
  import { ResolveDialog } from './ResolveDialog'
17
18
  import { exactTime, InConversationItem, InThreadCard, momentOf, SHOWN_CLASSES, useFaceLine } from './threadCard'
19
+ import { goneWords } from './PinnedComment'
18
20
  import { ToolbarButton } from './Toolbar'
19
21
  import { WithTooltip } from './Tooltip'
20
22
  import { UnreadDot } from './UnreadDot'
@@ -47,10 +49,11 @@ export interface ConversationEntryProps {
47
49
  about?: ReactNode
48
50
  /** Pictures and files: `AttachmentCard`s, laid out under the words. */
49
51
  files?: ReactNode
50
- /** Its reactions: the kit's `ReactionRow`. With `onToggle`, the strip offers React too. */
52
+ /**
53
+ * Its reactions: the kit's `ReactionRow`. With `onToggle`, the strip offers React too; when `onToggle` answers with a
54
+ * refusal, "Not reacted: <why>." is said under the reactions until the next reaction here, or until the card goes.
55
+ */
51
56
  reactions?: ReactionRowProps
52
- /** Why the last reaction was refused, in plain words: said under the reactions. */
53
- reactionRefused?: string
54
57
  /** Not read yet: the dot, or the urgent mark with `urgent`, and the card's edge in the theme's colour. */
55
58
  isNew?: boolean
56
59
  urgent?: boolean
@@ -94,6 +97,11 @@ export interface ConversationEntryProps {
94
97
  export interface ConversationCardProps extends ConversationEntryProps {
95
98
  /** Deleted: "This comment was deleted.", and its replies stay. */
96
99
  deleted?: boolean
100
+ /**
101
+ * Not read, and nothing says it was deleted (SPEC §6.5's "not returned"): "This comment can't be shown.", drawn as
102
+ * a deleted one is, and its replies stay (Miky, 6 November, ONE-9).
103
+ */
104
+ unseen?: boolean
97
105
  /** Its thread: how many replied, their faces, the last time, and whether one is new. Opening it is `onReply` or `onClick`. */
98
106
  replies?: Omit<RepliesRowProps, 'urgent'>
99
107
  /** Reply: offered on the strip. */
@@ -253,6 +261,34 @@ function Words({ children }: { children: ReactNode }) {
253
261
  )
254
262
  }
255
263
 
264
+ /**
265
+ * The card holds why its last reaction was refused, so it lasts the same in every app: said from the answer until the
266
+ * next reaction here, or until the card goes. Only the latest reaction's answer is said.
267
+ */
268
+ function useReactionRefusal(reactions: ReactionRowProps | undefined): { row: ReactionRowProps | undefined; refused: string | undefined } {
269
+ const [refused, setRefused] = useState<string>()
270
+ const latest = useRef(0)
271
+ const toggle = reactions?.onToggle
272
+ if (!reactions || !toggle) return { row: reactions, refused }
273
+ const onToggle = (emoji: string) => {
274
+ const mine = ++latest.current
275
+ setRefused(undefined)
276
+ const say = (reason: unknown) => {
277
+ if (mine === latest.current) setRefused(refusalReason(reason))
278
+ }
279
+ const answer = toggle(emoji)
280
+ if (!answer) return
281
+ return answer.then((said) => {
282
+ if (said && !said.accepted) say(said.reason)
283
+ return said
284
+ }, (reason: unknown) => {
285
+ say(reason)
286
+ return { accepted: false as const, reason }
287
+ })
288
+ }
289
+ return { row: { ...reactions, onToggle }, refused }
290
+ }
291
+
256
292
  function Reactions({ reactions, refused, readOnly }: { reactions?: ReactionRowProps; refused?: string; readOnly: boolean }) {
257
293
  if ((!reactions || reactions.reactions.length === 0) && !refused) return null
258
294
  return (
@@ -347,7 +383,9 @@ function useEditing(editing: boolean | undefined, onEditingChange: ((editing: bo
347
383
  * The same card in every app, each in its own colours (the record that makes one conversation). Peek's, moved.
348
384
  */
349
385
  export function ConversationCard(props: ConversationCardProps) {
350
- const { author, about, files, reactions, reactionRefused, isNew = false, urgent = false, own = false, editor, deleted = false, replies, onReply, resolved, noun = 'comment', onResolve, resolveHint, resolveRefused, onReopen, selected, onClick, onDelete, deleteNote, deleteRefused, menu, menuAfter, menuLabel, editLabel, deleteLabel, moreLabel = 'More actions', className, children } = props
386
+ const { author, about, files, reactions, isNew = false, urgent = false, own = false, editor, deleted: isDeleted = false, unseen = false, replies, onReply, resolved, noun = 'comment', onResolve, resolveHint, resolveRefused, onReopen, selected, onClick, onDelete, deleteNote, deleteRefused, menu, menuAfter, menuLabel, editLabel, deleteLabel, moreLabel = 'More actions', className, children } = props
387
+ // Not shown is drawn as deleted, in its own words.
388
+ const deleted = isDeleted || unseen
351
389
  const readOnly = (props.readOnly ?? false) || deleted
352
390
  const inThreadCard = useContext(InThreadCard)
353
391
 
@@ -378,7 +416,8 @@ export function ConversationCard(props: ConversationCardProps) {
378
416
  const showStrip = hovered && !isEditing && !readOnly
379
417
  const strip = useRef<HTMLDivElement>(null)
380
418
  const wordsEnd = useClearOfStrip(root, strip, showStrip)
381
- const react = reactions?.onToggle
419
+ const { row: reactionRow, refused: reactionRefused } = useReactionRefusal(reactions)
420
+ const react = reactionRow?.onToggle
382
421
  // Read-only with no replies, there is nothing to open: no box to write in, no thread to read (Peek's way, Katerina, 1 November).
383
422
  const press = onClick ?? (readOnly && !replies?.count ? undefined : item?.toggle)
384
423
  const reply = onReply ?? item?.show
@@ -431,7 +470,7 @@ export function ConversationCard(props: ConversationCardProps) {
431
470
  {/* What it was on stays, where the words start: its replies still talk about that place (Leaf's; Katerina, 3 November: every app). */}
432
471
  {!!about && <div className="relative w-full pl-8 pr-2">{about}</div>}
433
472
  {/* 4px under it, as the words sit under it on a comment that is there. */}
434
- <p className={cn('w-full pb-2 pl-8 pr-2 text-caption italic text-text-muted', !!about && 'pt-1')}>This comment was deleted.</p>
473
+ <p className={cn('w-full pb-2 pl-8 pr-2 text-caption italic text-text-muted', !!about && 'pt-1')}>{goneWords(isDeleted)}</p>
435
474
  </>
436
475
  ) : (
437
476
  <>
@@ -459,7 +498,7 @@ export function ConversationCard(props: ConversationCardProps) {
459
498
  {!deleted && files && (
460
499
  <div className="relative flex w-full flex-wrap items-start gap-2 pb-2 pl-8 pr-2">{files}</div>
461
500
  )}
462
- <Reactions reactions={reactions} refused={reactionRefused} readOnly={readOnly} />
501
+ <Reactions reactions={reactionRow} refused={reactionRefused} readOnly={readOnly} />
463
502
  {resolved?.note && (
464
503
  // Who resolved it and the note, above the way into the replies; the check by the time says "Resolved" (Katerina, 1 November).
465
504
  <div className="relative w-full pb-1">
@@ -543,7 +582,8 @@ export function ConversationCard(props: ConversationCardProps) {
543
582
  * when it has one. Peek's, moved with the conversation.
544
583
  */
545
584
  export function ReplyCard(props: ReplyCardProps) {
546
- const { id, author, about, files, reactions, reactionRefused, isNew = false, urgent = false, own = false, editor, onDelete, deleteNote, deleteRefused, menu, menuAfter, menuLabel, editLabel, deleteLabel, moreLabel = 'More actions', noun = 'reply', className, children } = props
585
+ const { id, author, about, files, isNew = false, urgent = false, own = false, editor, onDelete, deleteNote, deleteRefused, menu, menuAfter, menuLabel, editLabel, deleteLabel, moreLabel = 'More actions', noun = 'reply', className, children } = props
586
+ const { row: reactions, refused: reactionRefused } = useReactionRefusal(props.reactions)
547
587
  const readOnly = props.readOnly ?? false
548
588
  const [hovered, setHovered] = useState(false)
549
589
  const [menuOpen, setMenuOpen] = useState(false)
@@ -16,18 +16,26 @@ export interface PinnedCommentProps {
16
16
  words: ReactNode
17
17
  /** It was deleted; its replies stay. */
18
18
  deleted?: boolean
19
+ /** It wasn't read, and nothing says it was deleted: "This comment can't be shown.", and its replies stay (ONE-9). */
20
+ unseen?: boolean
19
21
  }
20
22
 
23
+ /** What stands in a comment's place when it is gone: deleted, or not shown (SPEC §6.5). */
24
+ export const goneWords = (deleted: boolean) => (deleted ? 'This comment was deleted.' : 'This comment can’t be shown.')
25
+
26
+ /** The box's `closed` under that thread, deleted or not shown, the same in every app: the line above already says why. */
27
+ export const GONE_CLOSED = 'This thread takes no new replies.'
28
+
21
29
  /**
22
30
  * The comment a thread answers, pinned at the top of the replies column: who, when, and its first line, on a raised
23
31
  * card. Peek's pinned message, moved with the conversation.
24
32
  */
25
- export function PinnedComment({ author, time, at: given, words, deleted = false }: PinnedCommentProps) {
33
+ export function PinnedComment({ author, time, at: given, words, deleted = false, unseen = false }: PinnedCommentProps) {
26
34
  const at = momentOf(given)
27
35
  return (
28
36
  <Card fill="elevated" clip>
29
- {deleted ? (
30
- <p className="p-2 text-caption italic text-text-muted">This comment was deleted.</p>
37
+ {deleted || unseen ? (
38
+ <p className="p-2 text-caption italic text-text-muted">{goneWords(deleted)}</p>
31
39
  ) : (
32
40
  <div className="flex flex-col p-2">
33
41
  <div className="flex items-center gap-2">
@@ -92,11 +92,17 @@ export interface ReactionRowProps {
92
92
  nameOf: (id: string) => string
93
93
  /** Who is looking: their pills are lit, and "who reacted" says "you". */
94
94
  viewer?: string
95
- /** Your reaction on or off. Absent, the row only shows (read-only, signed out). */
96
- onToggle?: (emoji: string) => void
95
+ /**
96
+ * Your reaction on or off. Absent, the row only shows (read-only, signed out). In a `ConversationCard`, answering
97
+ * with what the relay said lets the card say why a refused one did not go through.
98
+ */
99
+ onToggle?: (emoji: string) => void | Promise<ReactionAnswer | void>
97
100
  className?: string
98
101
  }
99
102
 
103
+ /** What the relay said about a reaction; `reason` as it came, said in plain words by the card. */
104
+ export type ReactionAnswer = { accepted: true } | { accepted: false; reason: unknown }
105
+
100
106
  export function ReactionRow({ reactions, options, nameOf, viewer, onToggle, className }: ReactionRowProps) {
101
107
  const shown = reactions.filter((r) => r.by.length > 0)
102
108
  if (shown.length === 0) return null
@@ -6,6 +6,7 @@ import { ConversationCard, ReplyCard } from './ConversationCard'
6
6
  import { ConversationLayout } from './ConversationLayout'
7
7
  import { ONE, SHORT, SOME, THREE, TWO, WORDS, WriteBox, YOU, useReactions } from './conversation.examples'
8
8
  import { MembersPill } from './MembersPill'
9
+ import { GONE_CLOSED } from './PinnedComment'
9
10
  import { useSeenOnScreen } from './seenOnScreen'
10
11
  import { showInConversation } from './showInConversation'
11
12
  import { Thread } from './Thread'
@@ -154,7 +155,19 @@ export const StartDeleted: Story = {
154
155
  name: 'Comment deleted',
155
156
  render: () => (
156
157
  <Side>
157
- <Thread start={{ ...START, deleted: true }} onClose={() => {}} notice={<WriteBox closed="The comment was deleted, so its thread takes no new replies." />}>
158
+ <Thread start={{ ...START, deleted: true }} onClose={() => {}} notice={<WriteBox closed={GONE_CLOSED} />}>
159
+ <Replies />
160
+ </Thread>
161
+ </Side>
162
+ ),
163
+ }
164
+
165
+ /** The comment was not read, and nothing says it was deleted: its replies stay, and no new one can be written. */
166
+ export const StartNotShown: Story = {
167
+ name: 'Comment not shown',
168
+ render: () => (
169
+ <Side>
170
+ <Thread start={{ ...START, unseen: true }} onClose={() => {}} notice={<WriteBox closed={GONE_CLOSED} />}>
158
171
  <Replies />
159
172
  </Thread>
160
173
  </Side>
package/src/Thread.tsx CHANGED
@@ -163,7 +163,7 @@ export function Thread({
163
163
  >
164
164
  {start && (
165
165
  <div className={cn('px-4 pb-2 pt-4', SHOWN_CLASSES)} data-thread-start={start.id}>
166
- <PinnedComment author={start.author} time={start.time} at={start.at} words={start.words} deleted={start.deleted} />
166
+ <PinnedComment author={start.author} time={start.time} at={start.at} words={start.words} deleted={start.deleted} unseen={start.unseen} />
167
167
  </div>
168
168
  )}
169
169
  <Divider look="section" label="Replies" className="px-4 py-2" />
@@ -99,25 +99,54 @@ export function WithBlock() {
99
99
  )
100
100
  }
101
101
 
102
+ /**
103
+ * What the relay (or Estiva ID, or the network) says for each cause of a refusal, as an app hands it over raw. The kit
104
+ * says each in `@estiva-app/conversation`'s plain words; a story picks one to show its sentence.
105
+ */
106
+ export const RELAY_SAYS = {
107
+ 'Too long': 'invalid: content exceeds maximum size of 262144 bytes',
108
+ 'Deleted, or no longer yours to write beside': 'invalid: edit target not found or not editable by you',
109
+ 'No longer a member': 'restricted: not a channel member',
110
+ Archived: 'restricted: channel is archived',
111
+ 'Too many at once': 'rate-limited: slow down',
112
+ 'Wrong clock': 'invalid: event timestamp too far in the future',
113
+ 'Signed out': 'auth-required: authentication required',
114
+ 'Anything else': 'error: internal error',
115
+ } as const
116
+ export type RelaySays = keyof typeof RELAY_SAYS
117
+
118
+ /** What the server says when it refuses a file, as protocol's upload hands it over. */
119
+ export const SERVER_SAYS = {
120
+ 'Too large': 'upload failed: 413 {"error":"file too large: 11534336 bytes (max 10485760)"}',
121
+ 'Not a type it takes': 'upload failed: 415 unsupported content type',
122
+ 'Could not be read': 'upload failed: 422 invalid image metadata',
123
+ 'Too many at once': 'upload failed: 429 rate limit exceeded',
124
+ 'Signed out': 'upload failed: 401 authentication failed',
125
+ 'No longer a member': 'upload failed: 403 forbidden',
126
+ 'Anything else': 'upload failed: 500 internal error',
127
+ } as const
128
+ export type ServerSays = keyof typeof SERVER_SAYS
129
+
102
130
  const saved = (): Promise<SendAnswer> => new Promise((resolve) => setTimeout(() => resolve({ accepted: true }), 400))
103
- const refused = (): Promise<SendAnswer> => new Promise((resolve) => setTimeout(() => resolve({ accepted: false, reason: 'try again in a moment' }), 600))
131
+ const refused = (reason: string): Promise<SendAnswer> => new Promise((resolve) => setTimeout(() => resolve({ accepted: false, reason }), 600))
104
132
  const asBody = (text: string): JSONContent => ({ type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text }] }] })
105
133
 
106
- /** The box a comment is edited in: the kit's CommentBox, as an app hands it to the card. */
107
- export function EditBox({ text, done, refuse = false }: { text: string; done: () => void; refuse?: boolean }) {
134
+ /** The box a comment is edited in: the kit's CommentBox, as an app hands it to the card. `refuse`: why the relay says no. */
135
+ export function EditBox({ text, done, refuse }: { text: string; done: () => void; refuse?: RelaySays }) {
136
+ const answer = () => (refuse ? refused(RELAY_SAYS[refuse]) : saved())
108
137
  return (
109
138
  <CommentBox
110
139
  people={[]}
111
140
  label="Edit"
112
141
  placeholder={null}
113
- send={refuse ? refused : saved}
142
+ send={answer}
114
143
  edit={{
115
144
  body: asBody(text),
116
145
  onCancel: done,
117
146
  onSave: async () => {
118
- const answer = await (refuse ? refused() : saved())
119
- if (answer.accepted) done()
120
- return answer
147
+ const said = await answer()
148
+ if (said.accepted) done()
149
+ return said
121
150
  },
122
151
  }}
123
152
  />
package/src/index.ts CHANGED
@@ -151,7 +151,7 @@ export { QuotedLine, type QuotedLineProps } from './QuotedLine'
151
151
  export { ReactionHorizon, type ReactionHorizonProps } from './ReactionHorizon'
152
152
  export { RepliesRow, type RepliesRowProps } from './RepliesRow'
153
153
  export { ResolveDialog, type ResolveDialogProps } from './ResolveDialog'
154
- export { PinnedComment, type PinnedCommentProps } from './PinnedComment'
154
+ export { PinnedComment, goneWords, GONE_CLOSED, type PinnedCommentProps } from './PinnedComment'
155
155
  export { ArchiveDialog, type ArchiveDialogProps } from './ArchiveDialog'
156
156
  export { ArchivedNotice, type ArchivedNoticeProps } from './ArchivedNotice'
157
157
  export { DeletedNotice, type DeletedNoticeProps } from './DeletedNotice'
@@ -48,20 +48,20 @@ describe('the registry builds', () => {
48
48
  expect(registry.entries.map((one) => one.name).sort()).toEqual(values.map((one) => one.name).sort())
49
49
  })
50
50
 
51
- it('counts 245 names over 125 files: 162 components, 76 helpers and 7 hooks (DeletedNotice and NoAccessNotice, the cards on a deleted file and on one you cannot open (ALO-4), on 3 November; useFormBusy, whether a Form around it is sending, read by the editor’s DocumentField from the main entry, in the review of 2 November; useLeftAt, sendsInLayout, useSeenOnScreen, showInConversation and showInConversationWhenDrawn, where a conversation scrolls, what was seen and a link landing on a comment, moved from Peek for every app, on 2 November; useRememberedOpen, the fold a section remembers, read by the app, and NAV_TREE_PENDING_MS and isPlainClick, Peek’s Folder timer and plain-click check, moved in, on 2 November; FormDialog, MoveDialog and ArchiveDialog, the dialogs Peek wired by hand, on 2 November; ConversationPlace, the line saying where a comment was said, and DocumentField, a rich-text field of a form, moved from Peek, on 2 November; ArchivedNotice, the card on an archived file, from Peek, Ship and Leaf, on 31 October; caretOnOpen, the box at a thread’s foot taking the caret when a ConversationLayout opens it, without scrolling, on 31 October; the conversation from Peek for every app, with PageHeader and PinnedComment, on 31 October, and ResolutionNote and ResolutionHistory gone with the resolved looks not picked, on 1 November; useSidebarFold, a folded sidebar kept folded in every app, on 31 October; cardShapeMemory, a card’s last shape on this device, lifted from Peek and Ship for Leaf, and ReferenceCards and useReferenceCards gone with their deprecated page, in the widget review, on 30 October; inTheBox, a card or part in a box being written in, on the files’ fill and in words, on 29 October; archivedLine, the line on an archived file in every app (PEEKM-2), on 23 October; keepCommentBoxWarm, a box built ahead, exported as 0.84.0 promised (PEEKM-1), on 21 October;linkedFrom and linkStateFrom, one card for a file in every app (5ebf2756), on 21 October; ComposeBox, ComposeKeys and COMPOSE_EDITOR_CLASSES gone into CommentBox’s own frame (one box), on 21 October; LinkPlaces with linkPlaceAt and staysChip, a link in a document drawn where it sits (WBD-4), on 20 October; DocumentEditor, one document editor for every app, and PersonReference, `@` in a document (WBD-3), on 20 October; toggleTableHeaderRow, a table’s header row on and off (LEAF-12), on 19 October;EntryShell, the screen while nobody is signed in, moved from Peek (AUT-3), on 17 October; CommentBox with commentBoxRows, and ReactionRow with AddReactionButton and whoReacted, the shared comment box and reaction row (COMM-2), on 17 October; the link widgets — LinkChip, LinkRow, LinkCard, CardUnder, PartCard, LinkPreview and their parts, with useCanHover, chosenOf, loadingShapeOf and unavailableMemory — from the Widgets 2 prototype, on 16 October; InlineText, a title or the line under it edited where it stands (SUM-4), on 16 October; ComposeBox with ComposeKeys and its classes, CommentHighlights with its five helpers, and keepSelection and releaseSelection, from the Leaf prototype (LEAF-4), on 16 October;NavTree, NavTreeSection, the composer triggers and UnreadDot joined on 2 October; BlockHandle and EditorBlockHandle (RIC-18) on 2 October, moveBlock and blockDropCursor, the drop in the gutter, on 5 October, MembersPill and MembersDialog, moved from Peek (SHI-31), on 6 October, ShowMore on 7 October, AppProvider on 8 October, and KindIcon, thingKindOf and PastedImages with its two helpers, moved from Peek, on 8 October; CodeBlockColours, the coloured code block of the editor, on 9 October; Checklist, Callout, isChecklistTick and calloutLook (RIC-19) on 13 October; EditorTableControls and its four actions (RIC-21) on 13 October; ReferenceCards, useReferenceCards and its three helpers, the card a chip in a document asks for, on 14 October; LinkChips and its two helpers, a URL in a document read as its chip, on 14 October; ReferenceMenu, ReferenceMenuView and three helpers, the menu of a chip while writing, on 14 October; PastedMarkdown, markdown pasted as the blocks it spells (LEAF-10), on 15 October; turnIntoRows, turnListInto and turnQuoteInto, the block menu’s Turn into for a list and a quote (LEAF-11), on 15 October)', () => {
51
+ it('counts 247 names over 125 files: 162 components, 78 helpers and 7 hooks (goneWords and GONE_CLOSED, what stands in a gone comment’s place and under its thread in every app (ONE-9), on 6 November; DeletedNotice and NoAccessNotice, the cards on a deleted file and on one you cannot open (ALO-4), on 3 November; useFormBusy, whether a Form around it is sending, read by the editor’s DocumentField from the main entry, in the review of 2 November; useLeftAt, sendsInLayout, useSeenOnScreen, showInConversation and showInConversationWhenDrawn, where a conversation scrolls, what was seen and a link landing on a comment, moved from Peek for every app, on 2 November; useRememberedOpen, the fold a section remembers, read by the app, and NAV_TREE_PENDING_MS and isPlainClick, Peek’s Folder timer and plain-click check, moved in, on 2 November; FormDialog, MoveDialog and ArchiveDialog, the dialogs Peek wired by hand, on 2 November; ConversationPlace, the line saying where a comment was said, and DocumentField, a rich-text field of a form, moved from Peek, on 2 November; ArchivedNotice, the card on an archived file, from Peek, Ship and Leaf, on 31 October; caretOnOpen, the box at a thread’s foot taking the caret when a ConversationLayout opens it, without scrolling, on 31 October; the conversation from Peek for every app, with PageHeader and PinnedComment, on 31 October, and ResolutionNote and ResolutionHistory gone with the resolved looks not picked, on 1 November; useSidebarFold, a folded sidebar kept folded in every app, on 31 October; cardShapeMemory, a card’s last shape on this device, lifted from Peek and Ship for Leaf, and ReferenceCards and useReferenceCards gone with their deprecated page, in the widget review, on 30 October; inTheBox, a card or part in a box being written in, on the files’ fill and in words, on 29 October; archivedLine, the line on an archived file in every app (PEEKM-2), on 23 October; keepCommentBoxWarm, a box built ahead, exported as 0.84.0 promised (PEEKM-1), on 21 October;linkedFrom and linkStateFrom, one card for a file in every app (5ebf2756), on 21 October; ComposeBox, ComposeKeys and COMPOSE_EDITOR_CLASSES gone into CommentBox’s own frame (one box), on 21 October; LinkPlaces with linkPlaceAt and staysChip, a link in a document drawn where it sits (WBD-4), on 20 October; DocumentEditor, one document editor for every app, and PersonReference, `@` in a document (WBD-3), on 20 October; toggleTableHeaderRow, a table’s header row on and off (LEAF-12), on 19 October;EntryShell, the screen while nobody is signed in, moved from Peek (AUT-3), on 17 October; CommentBox with commentBoxRows, and ReactionRow with AddReactionButton and whoReacted, the shared comment box and reaction row (COMM-2), on 17 October; the link widgets — LinkChip, LinkRow, LinkCard, CardUnder, PartCard, LinkPreview and their parts, with useCanHover, chosenOf, loadingShapeOf and unavailableMemory — from the Widgets 2 prototype, on 16 October; InlineText, a title or the line under it edited where it stands (SUM-4), on 16 October; ComposeBox with ComposeKeys and its classes, CommentHighlights with its five helpers, and keepSelection and releaseSelection, from the Leaf prototype (LEAF-4), on 16 October;NavTree, NavTreeSection, the composer triggers and UnreadDot joined on 2 October; BlockHandle and EditorBlockHandle (RIC-18) on 2 October, moveBlock and blockDropCursor, the drop in the gutter, on 5 October, MembersPill and MembersDialog, moved from Peek (SHI-31), on 6 October, ShowMore on 7 October, AppProvider on 8 October, and KindIcon, thingKindOf and PastedImages with its two helpers, moved from Peek, on 8 October; CodeBlockColours, the coloured code block of the editor, on 9 October; Checklist, Callout, isChecklistTick and calloutLook (RIC-19) on 13 October; EditorTableControls and its four actions (RIC-21) on 13 October; ReferenceCards, useReferenceCards and its three helpers, the card a chip in a document asks for, on 14 October; LinkChips and its two helpers, a URL in a document read as its chip, on 14 October; ReferenceMenu, ReferenceMenuView and three helpers, the menu of a chip while writing, on 14 October; PastedMarkdown, markdown pasted as the blocks it spells (LEAF-10), on 15 October; turnIntoRows, turnListInto and turnQuoteInto, the block menu’s Turn into for a list and a quote (LEAF-11), on 15 October)', () => {
52
52
  // The reconciliation GATES.md §24 explains. If this changes, that changes.
53
53
  // The `EDITOR_EXTENSIONS` count as components by their names; they are
54
54
  // editor extensions, documented on SelectionToolbar's, BlockNodes' and
55
55
  // ComposerTriggers' pages.
56
56
  const kinds = registry.entries.reduce<Record<string, number>>((all, one) => ({ ...all, [one.kind]: (all[one.kind] ?? 0) + 1 }), {})
57
- expect(kinds).toEqual({ component: 162, helper: 76, hook: 7 })
57
+ expect(kinds).toEqual({ component: 162, helper: 78, hook: 7 })
58
58
  expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(125)
59
59
  })
60
60
 
61
61
  it('gives every entry a purpose, from its own page or from the comment above it', () => {
62
62
  expect(registry.entries.filter((one) => one.purpose.trim() === '')).toEqual([])
63
63
  expect(registry.entries.filter((one) => one.purposeFrom === 'page').length).toBe(112)
64
- expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(133)
64
+ expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(135)
65
65
  })
66
66
 
67
67
  it('takes a name with a page of its own from the page, and a name without one from the code', () => {