// Copyright 2025 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { useCallback, useRef, useState } from 'react'; import type { Meta } from '@storybook/react'; import type { PropsType } from './AttachmentStatusIcon'; import { AttachmentStatusIcon } from './AttachmentStatusIcon'; import { fakeAttachment } from '../../test-both/helpers/fakeAttachment'; export default { title: 'Components/Conversation/AttachmentStatusIcon', argTypes: { isIncoming: { control: { type: 'select' }, options: [true, false] }, }, args: { attachment: fakeAttachment(), isIncoming: false, renderAttachmentDownloaded: () => { return
🔥🔥
; }, }, } satisfies Meta; export function Default(args: PropsType): JSX.Element { return (
); } export function NoAttachment(args: PropsType): JSX.Element { return (
); } export function NeedsDownload(args: PropsType): JSX.Element { return (
); } export function Downloading(args: PropsType): JSX.Element { return (
); } export function Interactive(args: PropsType): JSX.Element { const size = 10000000; const [attachment, setAttachment] = useState( fakeAttachment({ path: undefined, size }) ); const intervalRef = useRef(); const cancelAttachmentDownload = useCallback(() => { const newAttachment = { ...attachment, pending: false }; setAttachment(newAttachment); if (intervalRef.current) { clearInterval(intervalRef.current); intervalRef.current = undefined; } }, [attachment, setAttachment]); const kickOffAttachmentDownload = useCallback(() => { let { totalDownloaded } = attachment; totalDownloaded = (totalDownloaded ?? 0) + size / 20; const newAttachment = { ...attachment, totalDownloaded, pending: true }; setAttachment(newAttachment); intervalRef.current = setInterval(() => { totalDownloaded = (totalDownloaded ?? 0) + size / 20; setAttachment({ ...newAttachment, totalDownloaded }); if (totalDownloaded >= size && intervalRef.current) { setAttachment({ ...newAttachment, pending: false, path: 'something ' }); clearInterval(intervalRef.current); intervalRef.current = undefined; } }, 300); }, [attachment, setAttachment]); return (
); }