Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(new-channels): add simple persistence for drafts (#1843)

teoa88d47e62cdc
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsx
index 87d7be4670..3c81daeff3 100644
--- a/js/app/packages/channel/Channel/Channel.tsx
+++ b/js/app/packages/channel/Channel/Channel.tsx
@@ -34,12 +34,16 @@ import type { DateValue } from '@core/util/date';
import { buildChannelMessageListMeta } from './message-list-meta';
import { ScrollToBottomOverlay } from './ScrollToBottomOverlay';
import { ChannelThread } from '../Thread';
-import { ChannelInput } from '../Input';
+import { ChannelInput, createInputAttachmentTracker } from '../Input';
import { createChannelMessageActions } from './create-channel-message-actions';
import { createActivityTracker } from '@channel/activity-tracker';
import { useChannelActivity } from '@core/context/channels';
import { createChannelDragState } from './create-channel-drag-state';
import { ChannelDropZone } from './ChannelDropZone';
+import {
+ makeAttachmentTrackerPersistenceKey,
+ makeInputValuePersistenceKey,
+} from '@channel/Input/utils/persistence';
type ChannelProps = {
channelId: string;
@@ -93,8 +97,15 @@ export function Channel(props: ChannelProps) {
buildChannelMessageListMeta(messages(), activityTracker.isNewMessage)
);
+ const attachmentTracker = createInputAttachmentTracker({
+ persistenceKey: makeAttachmentTrackerPersistenceKey({
+ channelId: props.channelId,
+ }),
+ });
+
const dragState = createChannelDragState({
channelId: props.channelId,
+ attachmentTracker,
});
const getMessageActions = createChannelMessageActions({
@@ -163,7 +174,10 @@ export function Channel(props: ChannelProps) {
isDraggingOverChannel: dragState.isDraggingOverChannel(),
isValidChannelDrag: dragState.isValidChannelDrag(),
}}
- attachmentTracker={dragState.tracker}
+ attachmentTracker={attachmentTracker}
+ persistenceKey={makeInputValuePersistenceKey({
+ channelId: props.channelId,
+ })}
onReady={(handle) => {
dragState.setAttachFilesToChannel(handle.attachFiles);
}}
diff --git a/js/app/packages/channel/Channel/create-channel-drag-state.ts b/js/app/packages/channel/Channel/create-channel-drag-state.ts
index 7d4acac6f8..c9e5403b3f 100644
--- a/js/app/packages/channel/Channel/create-channel-drag-state.ts
+++ b/js/app/packages/channel/Channel/create-channel-drag-state.ts
@@ -5,10 +5,10 @@ import { createEntityDropZone } from './create-entity-drop-zone';
type CreateChannelDragStateOptions = {
channelId: string;
+ attachmentTracker: InputAttachmentTracker;
};
export type ChannelDragState = {
- tracker: InputAttachmentTracker;
entityDropZone: ReturnType<typeof createEntityDropZone>;
isDraggingOverChannel: Accessor<boolean>;
isValidChannelDrag: Accessor<boolean>;
@@ -33,7 +33,6 @@ export function createChannelDragState(
let attachFilesToChannel: ((files: File[]) => Promise<void>) | undefined;
return {
- tracker,
entityDropZone,
isDraggingOverChannel: () =>
isDraggingOverChannel() || entityDropZone.isDraggingOver(),
diff --git a/js/app/packages/channel/Input/ChannelInput.tsx b/js/app/packages/channel/Input/ChannelInput.tsx
index a5fffd4ac8..4197fd93b6 100644
--- a/js/app/packages/channel/Input/ChannelInput.tsx
+++ b/js/app/packages/channel/Input/ChannelInput.tsx
@@ -12,15 +12,15 @@ import type {
InputAttachmentTracker,
InputCallbacks,
InputData,
- InputDraftAdapter,
InputHandle,
+ InputPersistenceKey,
} from './types';
import { applyInlineFormat, applyNodeFormat } from './utils/formatting';
type ChannelInputProps = InputCallbacks & {
input: InputData;
markdownNamespace?: string;
- draft?: InputDraftAdapter;
+ persistenceKey?: InputPersistenceKey;
attachmentTracker?: InputAttachmentTracker;
onReady?: (handle: InputHandle) => void;
};
@@ -48,14 +48,15 @@ export function ChannelInput(props: ChannelInputProps) {
},
});
},
+ clearInput: () => markdownEditor.controls.clear(),
callbacks: {
onChange: props.onChange,
onSend: props.onSend,
onToggleFormatRibbon: props.onToggleFormatRibbon,
- onCloseDraft: props.onCloseDraft,
+ onClose: props.onClose,
onRemoveAttachment: props.onRemoveAttachment,
},
- draft: props.draft,
+ persistenceKey: props.persistenceKey,
});
const markdownEditor = createConfiguredChannelMarkdownEditor({
@@ -112,7 +113,7 @@ export function ChannelInput(props: ChannelInputProps) {
<MarkdownShell
config={markdownEditor}
placeholder={inputState.view().placeholder}
- initialValue={props.input.value}
+ initialValue={inputState.view().value}
autofocus={!isMobile()}
class="text-sm mobile:text-base"
/>
diff --git a/js/app/packages/channel/Input/PrimaryActions.tsx b/js/app/packages/channel/Input/PrimaryActions.tsx
index 7b86cfdc54..1794e53f42 100644
--- a/js/app/packages/channel/Input/PrimaryActions.tsx
+++ b/js/app/packages/channel/Input/PrimaryActions.tsx
@@ -86,7 +86,7 @@ export function PrimaryActions(props: JSX.HTMLAttributes<HTMLDivElement>) {
<Show when={isReplyInput(input())}>
<InputActionButton
label="Delete reply"
- onClick={() => commands.closeDraft()}
+ onClick={() => commands.close()}
>
{renderIcon(TrashIcon, 'size-5')}
</InputActionButton>
diff --git a/js/app/packages/channel/Input/Root.tsx b/js/app/packages/channel/Input/Root.tsx
index ec09565646..1393c4f687 100644
--- a/js/app/packages/channel/Input/Root.tsx
+++ b/js/app/packages/channel/Input/Root.tsx
@@ -7,7 +7,7 @@ const NoopInputCommands: InputCommands = {
send: async () => false,
attachFiles: async () => {},
toggleFormatRibbon: () => {},
- closeDraft: () => {},
+ close: () => {},
removeAttachment: () => {},
};
diff --git a/js/app/packages/channel/Input/attachment-tracker.ts b/js/app/packages/channel/Input/attachment-tracker.ts
index f554d14b32..148cbc42d0 100644
--- a/js/app/packages/channel/Input/attachment-tracker.ts
+++ b/js/app/packages/channel/Input/attachment-tracker.ts
@@ -1,5 +1,6 @@
import { createMemo, createSignal, type Accessor } from 'solid-js';
import type { InputAttachmentData } from './types';
+import { makePersisted } from '@solid-primitives/storage';
export type InputAttachmentTracker = {
attachments: Accessor<InputAttachmentData[]>;
@@ -12,6 +13,7 @@ export type InputAttachmentTracker = {
};
type CreateInputAttachmentTrackerOptions = {
+ persistenceKey?: string;
initialAttachments?: InputAttachmentData[];
maxAttachments?: number;
};
@@ -19,9 +21,14 @@ type CreateInputAttachmentTrackerOptions = {
export function createInputAttachmentTracker(
options: CreateInputAttachmentTrackerOptions = {}
): InputAttachmentTracker {
- const [attachments, setAttachments] = createSignal<InputAttachmentData[]>(
+ const raw = createSignal<InputAttachmentData[]>(
options.initialAttachments ?? []
);
+
+ const [attachments, setAttachments] = options.persistenceKey
+ ? makePersisted(raw, { name: options.persistenceKey })
+ : raw;
+
const maxAttachments = options.maxAttachments ?? 10;
const hasPending = createMemo(() =>
diff --git a/js/app/packages/channel/Input/create-input-commands.ts b/js/app/packages/channel/Input/create-input-commands.ts
index 8135b33580..08f562d7a2 100644
--- a/js/app/packages/channel/Input/create-input-commands.ts
+++ b/js/app/packages/channel/Input/create-input-commands.ts
@@ -4,7 +4,6 @@ import type {
InputCallbacks,
InputCommands,
InputData,
- InputDraftAdapter,
InputSnapshot,
} from './types';
@@ -17,7 +16,6 @@ type CreateInputCommandsDeps = {
removeTrackedAttachment: (id: string) => void;
attachFiles?: (files: File[]) => Promise<void> | void;
callbacks?: InputCallbacks;
- draft?: InputDraftAdapter;
};
export function createInputCommands(
@@ -27,7 +25,6 @@ export function createInputCommands(
deps.removeTrackedAttachment(attachment.id);
const current = deps.snapshot();
void deps.callbacks?.onRemoveAttachment?.(attachment, current);
- void deps.draft?.save?.(current);
};
return {
@@ -40,7 +37,6 @@ export function createInputCommands(
try {
await deps.callbacks.onSend(current);
deps.reset();
- deps.draft?.clear?.();
return true;
} finally {
deps.setIsSending(false);
@@ -57,11 +53,10 @@ export function createInputCommands(
return next;
});
},
- closeDraft: () => {
+ close: () => {
const current = deps.snapshot();
deps.reset();
- deps.callbacks?.onCloseDraft?.(current);
- deps.draft?.clear?.();
+ deps.callbacks?.onClose?.(current);
},
removeAttachment,
};
diff --git a/js/app/packages/channel/Input/create-input-state.ts b/js/app/packages/channel/Input/create-input-state.ts
index 6b1570a8dd..a3759f7aa9 100644
--- a/js/app/packages/channel/Input/create-input-state.ts
+++ b/js/app/packages/channel/Input/create-input-state.ts
@@ -7,7 +7,7 @@ import type {
InputCallbacks,
InputCommands,
InputData,
- InputDraftAdapter,
+ InputPersistenceKey,
InputSnapshot,
} from './types';
@@ -16,8 +16,9 @@ type CreateInputStateOptions = {
mentions: Accessor<ItemMention[]>;
attachmentTracker: InputAttachmentTracker;
attachFiles?: (files: File[]) => Promise<void> | void;
+ clearInput?: () => void;
callbacks?: InputCallbacks;
- draft?: InputDraftAdapter;
+ persistenceKey?: InputPersistenceKey;
};
export type InputState = {
@@ -35,7 +36,7 @@ export function createInputState(options: CreateInputStateOptions): InputState {
mentions: options.mentions,
attachmentTracker: options.attachmentTracker,
callbacks: options.callbacks,
- draft: options.draft,
+ persistenceKey: options.persistenceKey,
});
const commands = createInputCommands({
@@ -43,12 +44,14 @@ export function createInputState(options: CreateInputStateOptions): InputState {
snapshot: view.snapshot,
setIsSending: view.setIsSending,
setShowFormatRibbon: view.setShowFormatRibbon,
- reset: view.reset,
+ reset: () => {
+ view.reset();
+ options.clearInput?.();
+ },
removeTrackedAttachment: (id) =>
options.attachmentTracker.removeAttachment(id),
attachFiles: options.attachFiles,
callbacks: options.callbacks,
- draft: options.draft,
});
return {
@@ -57,6 +60,9 @@ export function createInputState(options: CreateInputStateOptions): InputState {
commands,
setValue: view.setValue,
setIsDraggedOver: view.setIsDraggedOver,
- reset: view.reset,
+ reset: () => {
+ view.reset();
+ options.clearInput?.();
+ },
};
}
diff --git a/js/app/packages/channel/Input/create-input-view.ts b/js/app/packages/channel/Input/create-input-view.ts
index 10514700d9..beab021184 100644
--- a/js/app/packages/channel/Input/create-input-view.ts
+++ b/js/app/packages/channel/Input/create-input-view.ts
@@ -1,4 +1,5 @@
import type { ItemMention } from '@core/component/LexicalMarkdown/plugins';
+import { makePersisted } from '@solid-primitives/storage';
import {
createEffect,
createMemo,
@@ -10,7 +11,7 @@ import type {
InputAttachmentTracker,
InputCallbacks,
InputData,
- InputDraftAdapter,
+ InputPersistenceKey,
InputSnapshot,
} from './types';
@@ -19,7 +20,7 @@ type CreateInputViewOptions = {
mentions: Accessor<ItemMention[]>;
attachmentTracker: InputAttachmentTracker;
callbacks?: InputCallbacks;
- draft?: InputDraftAdapter;
+ persistenceKey?: InputPersistenceKey;
};
export type InputView = {
@@ -36,9 +37,14 @@ export type InputView = {
};
export function createInputView(options: CreateInputViewOptions): InputView {
- const [value, setValueSignal] = createSignal(
- options.initialInput.value ?? ''
+ const rawValue = createSignal<string | undefined>(
+ options.initialInput.value || undefined
);
+ const [persistedValue, setValueSignal] = options.persistenceKey
+ ? makePersisted(rawValue, { name: options.persistenceKey })
+ : rawValue;
+ const value = () => persistedValue() ?? '';
+
const [showFormatRibbon, setShowFormatRibbon] = createSignal(
!!options.initialInput.showFormatRibbon
);
@@ -65,19 +71,18 @@ export function createInputView(options: CreateInputViewOptions): InputView {
on(
snapshot,
(current) => {
- void options.callbacks?.onChange?.(current);
- void options.draft?.save?.(current);
+ options.callbacks?.onChange?.(current);
},
{ defer: true }
)
);
const setValue = (nextValue: string) => {
- setValueSignal(nextValue);
+ setValueSignal(nextValue || undefined);
};
const reset = () => {
- setValueSignal('');
+ setValue('');
options.attachmentTracker.clearAttachments();
};
diff --git a/js/app/packages/channel/Input/index.ts b/js/app/packages/channel/Input/index.ts
index 2c49c39924..a1974b212b 100644
--- a/js/app/packages/channel/Input/index.ts
+++ b/js/app/packages/channel/Input/index.ts
@@ -30,9 +30,9 @@ export type {
InputAttachmentKind,
InputSnapshot,
InputCallbacks,
- InputDraftAdapter,
InputCommands,
InputHandle,
InputActionEvent,
InputAttachmentTracker,
+ InputPersistenceKey,
} from './types';
diff --git a/js/app/packages/channel/Input/tests/create-input-commands.test.ts b/js/app/packages/channel/Input/tests/create-input-commands.test.ts
new file mode 100644
index 0000000000..a2f55306f1
--- /dev/null
+++ b/js/app/packages/channel/Input/tests/create-input-commands.test.ts
@@ -0,0 +1,37 @@
+import { describe, expect, it, vi } from 'vitest';
+import { createInputCommands } from '../create-input-commands';
+import type { InputSnapshot } from '../types';
+
+describe('createInputCommands', () => {
+ it('resets before invoking onClose', () => {
+ const events: string[] = [];
+ const snapshot: InputSnapshot = {
+ value: 'reply',
+ mentions: [],
+ attachments: [],
+ };
+
+ const commands = createInputCommands({
+ view: () => ({
+ mode: 'reply',
+ hasPendingAttachments: false,
+ }),
+ snapshot: () => snapshot,
+ setIsSending: vi.fn(),
+ setShowFormatRibbon: vi.fn(),
+ reset: () => {
+ events.push('reset');
+ },
+ removeTrackedAttachment: vi.fn(),
+ callbacks: {
+ onClose: () => {
+ events.push('onClose');
+ },
+ },
+ });
+
+ commands.close();
+
+ expect(events).toEqual(['reset', 'onClose']);
+ });
+});
diff --git a/js/app/packages/channel/Input/tests/create-input-view.test.ts b/js/app/packages/channel/Input/tests/create-input-view.test.ts
new file mode 100644
index 0000000000..b3b01da244
--- /dev/null
+++ b/js/app/packages/channel/Input/tests/create-input-view.test.ts
@@ -0,0 +1,91 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import { createRoot } from 'solid-js';
+import { beforeEach, describe, expect, it } from 'vitest';
+import { createInputAttachmentTracker } from '../attachment-tracker';
+import { createInputView } from '../create-input-view';
+import { makeInputValuePersistenceKey } from '../utils/persistence';
+
+describe('createInputView', () => {
+ beforeEach(() => {
+ localStorage.clear();
+ });
+
+ it('rehydrates the persisted input value for the same key', () => {
+ const persistenceKey = makeInputValuePersistenceKey({
+ channelId: 'channel-1',
+ });
+
+ createRoot((dispose) => {
+ const view = createInputView({
+ initialInput: {
+ mode: 'channel',
+ value: '',
+ },
+ mentions: () => [],
+ attachmentTracker: createInputAttachmentTracker(),
+ persistenceKey,
+ });
+
+ view.setValue('persisted value');
+ expect(view.value()).toBe('persisted value');
+ dispose();
+ });
+
+ createRoot((dispose) => {
+ const view = createInputView({
+ initialInput: {
+ mode: 'channel',
+ value: '',
+ },
+ mentions: () => [],
+ attachmentTracker: createInputAttachmentTracker(),
+ persistenceKey,
+ });
+
+ expect(view.value()).toBe('persisted value');
+ dispose();
+ });
+ });
+
+ it('removes the persisted value when the input becomes empty', () => {
+ const persistenceKey = makeInputValuePersistenceKey({
+ channelId: 'channel-1',
+ });
+
+ createRoot((dispose) => {
+ const view = createInputView({
+ initialInput: {
+ mode: 'channel',
+ value: '',
+ },
+ mentions: () => [],
+ attachmentTracker: createInputAttachmentTracker(),
+ persistenceKey,
+ });
+
+ view.setValue('persisted value');
+ view.setValue('');
+ dispose();
+ });
+
+ expect(localStorage.getItem(persistenceKey)).toBeNull();
+
+ createRoot((dispose) => {
+ const view = createInputView({
+ initialInput: {
+ mode: 'channel',
+ value: '',
+ },
+ mentions: () => [],
+ attachmentTracker: createInputAttachmentTracker(),
+ persistenceKey,
+ });
+
+ expect(view.value()).toBe('');
+ dispose();
+ });
+ });
+});
diff --git a/js/app/packages/channel/Input/tests/input-slots.test.tsx b/js/app/packages/channel/Input/tests/input-slots.test.tsx
index f2b94689dc..c226aae33a 100644
--- a/js/app/packages/channel/Input/tests/input-slots.test.tsx
+++ b/js/app/packages/channel/Input/tests/input-slots.test.tsx
@@ -52,8 +52,13 @@ vi.mock('@core/component/VideoPreview', () => ({
}));
vi.mock('@core/component/LexicalMarkdown/builder/MarkdownShell', () => ({
- MarkdownShell: (props: { placeholder?: string }) => (
- <div data-testid="markdown-shell">{props.placeholder}</div>
+ MarkdownShell: (props: { placeholder?: string; initialValue?: string }) => (
+ <div
+ data-testid="markdown-shell"
+ data-initial-value={props.initialValue ?? ''}
+ >
+ {props.placeholder}
+ </div>
),
}));
@@ -125,7 +130,7 @@ describe('Input slots', () => {
const user = userEvent.setup();
const onSend = vi.fn();
const onToggleFormatRibbon = vi.fn();
- const onCloseDraft = vi.fn();
+ const onClose = vi.fn();
render(() =>
(() => {
@@ -134,7 +139,7 @@ describe('Input slots', () => {
input={{ ...baseInput, mode: 'reply' }}
onSend={onSend}
onToggleFormatRibbon={onToggleFormatRibbon}
- onCloseDraft={onCloseDraft}
+ onClose={onClose}
/>
);
})()
@@ -150,7 +155,7 @@ describe('Input slots', () => {
expect(clickSpy).toHaveBeenCalledOnce();
clickSpy.mockRestore();
expect(onToggleFormatRibbon).toHaveBeenCalledOnce();
- expect(onCloseDraft).toHaveBeenCalledOnce();
+ expect(onClose).toHaveBeenCalledOnce();
expect(onSend.mock.calls[0]?.[0]?.value).toBe('');
});
diff --git a/js/app/packages/channel/Input/types.ts b/js/app/packages/channel/Input/types.ts
index 2df80d6420..7fb2b6a3cb 100644
--- a/js/app/packages/channel/Input/types.ts
+++ b/js/app/packages/channel/Input/types.ts
@@ -1,6 +1,7 @@
import type { ItemMention } from '@core/component/LexicalMarkdown/plugins';
import type { EntityIconSelector } from '@core/component/EntityIcon';
import type { InputAttachmentTracker as Tracker } from './attachment-tracker';
+import type { PersistenceKey } from '@queries/persistence';
export type InputAttachmentKind = 'video' | 'image' | 'document';
@@ -12,6 +13,8 @@ export type InputAttachmentData = {
pending?: boolean;
};
+export type InputPersistenceKey = PersistenceKey;
+
type InputDataBase = {
id?: string;
placeholder?: string;
@@ -43,23 +46,18 @@ export type InputCallbacks = {
onChange?: (snapshot: InputSnapshot) => void | Promise<void>;
onSend?: (snapshot: InputSnapshot) => void | Promise<void>;
onToggleFormatRibbon?: (open: boolean) => void | Promise<void>;
- onCloseDraft?: (snapshot: InputSnapshot) => void | Promise<void>;
+ onClose?: (snapshot: InputSnapshot) => void | Promise<void>;
onRemoveAttachment?: (
attachment: InputAttachmentData,
snapshot: InputSnapshot
) => void | Promise<void>;
};
-export type InputDraftAdapter = {
- save?: (snapshot: InputSnapshot) => void | Promise<void>;
- clear?: () => void | Promise<void>;
-};
-
export type InputCommands = {
send: () => Promise<boolean>;
attachFiles: (files: File[]) => Promise<void>;
toggleFormatRibbon: () => void;
- closeDraft: () => void;
+ close: () => void;
removeAttachment: (attachment: InputAttachmentData) => void;
};
diff --git a/js/app/packages/channel/Input/utils/persistence.ts b/js/app/packages/channel/Input/utils/persistence.ts
new file mode 100644
index 0000000000..081cd2b233
--- /dev/null
+++ b/js/app/packages/channel/Input/utils/persistence.ts
@@ -0,0 +1,36 @@
+import {
+ createPersistenceKey,
+ type PersistenceKey,
+} from '@queries/persistence';
+
+type PersistenceProps = {
+ channelId: string;
+ threadId?: string;
+};
+
+const ATTACHMENT_TRACKER_PREFIX = 'attachment-tracker';
+const ATTACHMENT_TRACKER_VERSION = 0;
+const INPUT_VALUE_PREFIX = 'input-value';
+const INPUT_VALUE_VERSION = 0;
+
+function makeScopedPersistenceName(prefix: string, props: PersistenceProps) {
+ return `${prefix}-channel:${props.channelId}${props.threadId ? `-thread:${props.threadId}` : ''}`;
+}
+
+export function makeAttachmentTrackerPersistenceKey(
+ props: PersistenceProps
+): PersistenceKey {
+ return createPersistenceKey(
+ makeScopedPersistenceName(ATTACHMENT_TRACKER_PREFIX, props),
+ ATTACHMENT_TRACKER_VERSION
+ );
+}
+
+export function makeInputValuePersistenceKey(
+ props: PersistenceProps
+): PersistenceKey {
+ return createPersistenceKey(
+ makeScopedPersistenceName(INPUT_VALUE_PREFIX, props),
+ INPUT_VALUE_VERSION
+ );
+}
diff --git a/js/app/packages/channel/Thread/ChannelThread.tsx b/js/app/packages/channel/Thread/ChannelThread.tsx
index cf58c0bf49..f7dbfa3bc6 100644
--- a/js/app/packages/channel/Thread/ChannelThread.tsx
+++ b/js/app/packages/channel/Thread/ChannelThread.tsx
@@ -108,6 +108,7 @@ export function ChannelThread(props: ThreadProps) {
/>
</Show>
<Thread.ReplyInput
+ channelId={props.channelId()}
messageId={props.data().id}
replyInputState={props.replyInputState}
setReplyInputState={props.setReplyInputState}
diff --git a/js/app/packages/channel/Thread/ThreadReplyInput.tsx b/js/app/packages/channel/Thread/ThreadReplyInput.tsx
index 04fe3c91fc..7db38be9ef 100644
--- a/js/app/packages/channel/Thread/ThreadReplyInput.tsx
+++ b/js/app/packages/channel/Thread/ThreadReplyInput.tsx
@@ -4,8 +4,13 @@ import type { InputSnapshot } from '../Input';
import { createEntityDropZone } from '../Channel/create-entity-drop-zone';
import { replyInputOffsetX } from './utils/thread-rail-geometry';
import { ThreadReplyInputConnector } from './ThreadReplyInputConnector';
+import {
+ makeAttachmentTrackerPersistenceKey,
+ makeInputValuePersistenceKey,
+} from '@channel/Input/utils/persistence';
type ThreadReplyInputProps = {
+ channelId: string;
messageId: string;
replyInputState: Accessor<InputSnapshot | undefined>;
setReplyInputState: Setter<InputSnapshot | undefined>;
@@ -14,6 +19,10 @@ type ThreadReplyInputProps = {
export function ThreadReplyInput(props: ThreadReplyInputProps) {
const tracker = createInputAttachmentTracker({
+ persistenceKey: makeAttachmentTrackerPersistenceKey({
+ channelId: props.channelId,
+ threadId: props.messageId,
+ }),
initialAttachments: props.replyInputState()?.attachments,
});
@@ -40,9 +49,13 @@ export function ThreadReplyInput(props: ThreadReplyInputProps) {
mode: 'reply',
}}
attachmentTracker={tracker}
+ persistenceKey={makeInputValuePersistenceKey({
+ channelId: props.channelId,
+ threadId: props.messageId,
+ })}
markdownNamespace={`thread-reply-input-${props.messageId}-markdown`}
onChange={(snapshot) => void props.setReplyInputState(snapshot)}
- onCloseDraft={() => {
+ onClose={() => {
props.setReplyInputState(undefined);
props.setIsReplying(false);
}}
diff --git a/js/app/packages/queries/persistence.ts b/js/app/packages/queries/persistence.ts
index 0c34d879b6..64897b1ed2 100644
--- a/js/app/packages/queries/persistence.ts
+++ b/js/app/packages/queries/persistence.ts
@@ -12,7 +12,7 @@ import {
parsedDurationToMilliseconds,
} from '@core/util/dateSearch/dateParser';
-type PersistenceKey = `${string}-persist-v${number}`;
+export type PersistenceKey = `${string}-persist-v${number}`;
/** Builds a versioned persistence key for IDB database naming. */
export function createPersistenceKey(