feat(island): media strip, media frame with expand badge, list row keep-end, offline freeze, upload tile and toast placement follow-ups
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
48166c17db
commit
d3137973ab
|
|
@ -1 +1,3 @@
|
||||||
|
export { useOfflineFreeze } from './use-offline-freeze';
|
||||||
export { useOnline } from './use-online';
|
export { useOnline } from './use-online';
|
||||||
|
export type { OfflineFreeze } from './types';
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
|
/** Button props that freeze a network action offline; empty while online. */
|
||||||
|
export type OfflineFreeze = { frozen?: true; frozenReason?: ReactNode };
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
|
import type { OfflineFreeze } from './types';
|
||||||
|
import { useOnline } from './use-online';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Freezes a network action while the device is offline: spread it on the action's Button, which
|
||||||
|
* stays visible at 40% and explains itself on tap, hover and focus. Online it adds nothing, so a
|
||||||
|
* button keeps its own `frozen` and `frozenReason`; combine them when it has its own:
|
||||||
|
* `frozen={offline.frozen || own}`.
|
||||||
|
*
|
||||||
|
* @param reason Why, from the translations: «برای این کار به اینترنت نیاز دارید.».
|
||||||
|
*/
|
||||||
|
export function useOfflineFreeze(reason: ReactNode): OfflineFreeze {
|
||||||
|
const isOnline = useOnline();
|
||||||
|
return isOnline ? {} : { frozen: true, frozenReason: reason };
|
||||||
|
}
|
||||||
|
|
@ -76,7 +76,8 @@ export type { SeparatorProps } from './atoms/separator';
|
||||||
export { Spinner, spinnerVariants } from './atoms/spinner';
|
export { Spinner, spinnerVariants } from './atoms/spinner';
|
||||||
export { useCountdown } from './hooks/use-countdown';
|
export { useCountdown } from './hooks/use-countdown';
|
||||||
export type { CountdownOptions } from './hooks/use-countdown';
|
export type { CountdownOptions } from './hooks/use-countdown';
|
||||||
export { useOnline } from './hooks/use-online';
|
export { useOfflineFreeze, useOnline } from './hooks/use-online';
|
||||||
|
export type { OfflineFreeze } from './hooks/use-online';
|
||||||
export { StateArt } from './atoms/state-art';
|
export { StateArt } from './atoms/state-art';
|
||||||
export type { StateArtProps, StateTone } from './atoms/state-art';
|
export type { StateArtProps, StateTone } from './atoms/state-art';
|
||||||
export type { SpinnerProps } from './atoms/spinner';
|
export type { SpinnerProps } from './atoms/spinner';
|
||||||
|
|
@ -185,6 +186,17 @@ export { LockedTeaser } from './molecules/locked-teaser';
|
||||||
export type { LockedTeaserProps } from './molecules/locked-teaser';
|
export type { LockedTeaserProps } from './molecules/locked-teaser';
|
||||||
export { MediaCarousel } from './molecules/media-carousel';
|
export { MediaCarousel } from './molecules/media-carousel';
|
||||||
export type { MediaCarouselProps, MediaItem } from './molecules/media-carousel';
|
export type { MediaCarouselProps, MediaItem } from './molecules/media-carousel';
|
||||||
|
export {
|
||||||
|
MediaStrip,
|
||||||
|
mediaStripAddVariants,
|
||||||
|
mediaStripTileVariants,
|
||||||
|
} from './molecules/media-strip';
|
||||||
|
export type {
|
||||||
|
MediaStripItem,
|
||||||
|
MediaStripProps,
|
||||||
|
MediaStripSize,
|
||||||
|
MediaStripStatus,
|
||||||
|
} from './molecules/media-strip';
|
||||||
export { Meter, meterBarVariants } from './molecules/meter';
|
export { Meter, meterBarVariants } from './molecules/meter';
|
||||||
export type { MeterProps, MeterTone } from './molecules/meter';
|
export type { MeterProps, MeterTone } from './molecules/meter';
|
||||||
export { Modal } from './molecules/modal';
|
export { Modal } from './molecules/modal';
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ export function ListRow(props: ListRowProps) {
|
||||||
icon,
|
icon,
|
||||||
iconTone,
|
iconTone,
|
||||||
end,
|
end,
|
||||||
|
keepEnd = false,
|
||||||
chevron,
|
chevron,
|
||||||
unread = false,
|
unread = false,
|
||||||
unreadLabel,
|
unreadLabel,
|
||||||
|
|
@ -114,6 +115,7 @@ export function ListRow(props: ListRowProps) {
|
||||||
alignItems="items-end"
|
alignItems="items-end"
|
||||||
gap="gap-1"
|
gap="gap-1"
|
||||||
className="flex-none"
|
className="flex-none"
|
||||||
|
data-keep={keepEnd || undefined}
|
||||||
>
|
>
|
||||||
{end}
|
{end}
|
||||||
</FlexBox>
|
</FlexBox>
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,11 @@ type ListRowBaseProps = {
|
||||||
iconTone?: ListRowIconTone;
|
iconTone?: ListRowIconTone;
|
||||||
/** The end column, stacked and end-aligned: an `Amount`, a `StatusBadge`, a caption. */
|
/** The end column, stacked and end-aligned: an `Amount`, a `StatusBadge`, a caption. */
|
||||||
end?: ReactNode;
|
end?: ReactNode;
|
||||||
|
/**
|
||||||
|
* The end column holds a live control (an unfollow button): it keeps full strength when the row
|
||||||
|
* is `dimmed`.
|
||||||
|
*/
|
||||||
|
keepEnd?: boolean;
|
||||||
/** The `chevron-left` at the end. On by itself for a link row; pass false to hide it. */
|
/** The `chevron-left` at the end. On by itself for a link row; pass false to hide it. */
|
||||||
chevron?: boolean;
|
chevron?: boolean;
|
||||||
/** Tinted with a dot at the inline start. */
|
/** Tinted with a dot at the inline start. */
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@ import { MAX_MEDIA } from './constants';
|
||||||
import type { MediaCarouselProps } from './types';
|
import type { MediaCarouselProps } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A post's images. One shows full width at its own ratio, letterboxed at 400px on
|
* A post's images, each whole (contained) in a 4:3 frame at most 420px tall on `surface-sunken`,
|
||||||
* `surface-sunken`; 2–4 swipe in 280px slides with dots and a «۱ / ۳» count, and from 480px wide
|
* with an expand badge at its bottom inline end (DS v6.1). One shows alone; 2–4 swipe with dots
|
||||||
* also move with ‹ › buttons on the image. Server-renderable:
|
* and a «۱ / ۳» count, and from 480px wide also move with ‹ › buttons on the image.
|
||||||
|
* Server-renderable:
|
||||||
* a single image ships no JavaScript, and only the swipe track is a client component, so every
|
* a single image ships no JavaScript, and only the swipe track is a client component, so every
|
||||||
* prop it takes is serializable except `onOpen`, which only a client caller can pass.
|
* prop it takes is serializable except `onOpen`, which only a client caller can pass.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { GridBox } from '../../../atoms/grid-box';
|
||||||
|
import { Icon } from '../../../atoms/icon';
|
||||||
|
import { mediaExpandVariants } from '../variants';
|
||||||
|
|
||||||
|
/** The expand mark on the frame (DS `lm-media__expand`); hidden from screen readers. */
|
||||||
|
export function MediaExpandBadge() {
|
||||||
|
return (
|
||||||
|
<GridBox
|
||||||
|
tag="span"
|
||||||
|
aria-hidden
|
||||||
|
justifyItems="justify-items-center"
|
||||||
|
alignItems="items-center"
|
||||||
|
className={mediaExpandVariants()}
|
||||||
|
>
|
||||||
|
<Icon name="expand" size={16} />
|
||||||
|
</GridBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
import NextLink from 'next/link';
|
import NextLink from 'next/link';
|
||||||
|
|
||||||
import { GridBox } from '../../../atoms/grid-box';
|
|
||||||
import { Element } from '../../../primitives/element';
|
import { Element } from '../../../primitives/element';
|
||||||
import { cn } from '../../../tools/cn';
|
import { cn } from '../../../tools/cn';
|
||||||
import type { MediaSlideProps } from '../types';
|
import type { MediaSlideProps } from '../types';
|
||||||
import { mediaImageVariants, mediaSlideVariants } from '../variants';
|
import { mediaImageVariants, mediaSlideVariants } from '../variants';
|
||||||
|
import { MediaExpandBadge } from './MediaExpandBadge';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One image, contained in its box. With `onOpen` the box is the button that opens the Lightbox;
|
* One image, contained in its 4:3 frame. With `onOpen` the frame is the button that opens the
|
||||||
* with `href` a hidden link covers it, so a tap opens the post while the image keeps its alt.
|
* Lightbox; with `href` a hidden link covers it, so a tap opens the post while the image keeps its
|
||||||
|
* alt. A single image carries the expand badge itself; the track draws one for all its slides.
|
||||||
*/
|
*/
|
||||||
export function MediaSlide({
|
export function MediaSlide({
|
||||||
item,
|
item,
|
||||||
|
|
@ -30,17 +31,16 @@ export function MediaSlide({
|
||||||
loading={index === 0 ? undefined : 'lazy'}
|
loading={index === 0 ? undefined : 'lazy'}
|
||||||
decoding="async"
|
decoding="async"
|
||||||
draggable={false}
|
draggable={false}
|
||||||
className={mediaImageVariants({ single })}
|
className={mediaImageVariants()}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
const badge = single && <MediaExpandBadge />;
|
||||||
|
|
||||||
if (onOpen) {
|
if (onOpen) {
|
||||||
return (
|
return (
|
||||||
<GridBox
|
<Element
|
||||||
tag="button"
|
tag="button"
|
||||||
type="button"
|
type="button"
|
||||||
justifyItems="justify-items-center"
|
|
||||||
alignItems="items-center"
|
|
||||||
onClick={() => onOpen(index)}
|
onClick={() => onOpen(index)}
|
||||||
aria-label={label ?? (item.alt || undefined)}
|
aria-label={label ?? (item.alt || undefined)}
|
||||||
className={cn(
|
className={cn(
|
||||||
|
|
@ -51,17 +51,15 @@ export function MediaSlide({
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{image}
|
{image}
|
||||||
</GridBox>
|
{badge}
|
||||||
|
</Element>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GridBox
|
<Element className={box}>
|
||||||
justifyItems="justify-items-center"
|
|
||||||
alignItems="items-center"
|
|
||||||
className={box}
|
|
||||||
>
|
|
||||||
{image}
|
{image}
|
||||||
|
{badge}
|
||||||
{href && (
|
{href && (
|
||||||
// The post's own link carries the keyboard path; this one is only a bigger tap area.
|
// The post's own link carries the keyboard path; this one is only a bigger tap area.
|
||||||
<Element
|
<Element
|
||||||
|
|
@ -73,6 +71,6 @@ export function MediaSlide({
|
||||||
className="absolute inset-0"
|
className="absolute inset-0"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</GridBox>
|
</Element>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,17 @@ import { Element } from '../../../primitives/element';
|
||||||
import { cn } from '../../../tools/cn';
|
import { cn } from '../../../tools/cn';
|
||||||
import type { MediaCarouselProps } from '../types';
|
import type { MediaCarouselProps } from '../types';
|
||||||
import { mediaDotVariants } from '../variants';
|
import { mediaDotVariants } from '../variants';
|
||||||
|
import { MediaExpandBadge } from './MediaExpandBadge';
|
||||||
import { MediaNavButton } from './MediaNavButton';
|
import { MediaNavButton } from './MediaNavButton';
|
||||||
import { MediaSlide } from './MediaSlide';
|
import { MediaSlide } from './MediaSlide';
|
||||||
|
|
||||||
const isRtl = (node: HTMLElement) => getComputedStyle(node).direction === 'rtl';
|
const isRtl = (node: HTMLElement) => getComputedStyle(node).direction === 'rtl';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2–4 images in a native swipe (scroll snap), with a «۱ / ۳» count and a dot per image. From 480px
|
* 2–4 images in a native swipe (scroll snap) of 4:3 frames, with a «۱ / ۳» count, the expand badge
|
||||||
* wide, ‹ › buttons on the image move it too, and ← → on a focused slide. Moving never opens the
|
* and a dot per image. From 480px wide, ‹ › buttons on the image move it too, and ← → on a focused
|
||||||
* Lightbox: only a tap on an image does. The only client part of a post: it follows the scroll to
|
* slide. Moving never opens the Lightbox: only a tap on an image does. The only client part of a
|
||||||
* light the current dot and count.
|
* post: it follows the scroll to light the current dot and count.
|
||||||
*/
|
*/
|
||||||
export function MediaTrack({
|
export function MediaTrack({
|
||||||
items,
|
items,
|
||||||
|
|
@ -130,6 +131,7 @@ export function MediaTrack({
|
||||||
{number(current + 1)} / {number(count)}
|
{number(current + 1)} / {number(count)}
|
||||||
</Element>
|
</Element>
|
||||||
</Typography>
|
</Typography>
|
||||||
|
<MediaExpandBadge />
|
||||||
</Element>
|
</Element>
|
||||||
<FlexBox aria-hidden justifyContent="justify-center" className="gap-1.5">
|
<FlexBox aria-hidden justifyContent="justify-center" className="gap-1.5">
|
||||||
{items.map((item, index) => (
|
{items.map((item, index) => (
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
export type MediaItem = {
|
export type MediaItem = {
|
||||||
src: string;
|
src: string;
|
||||||
/** Natural size in px, so a single image reserves its box at its own ratio before it loads. */
|
/** Natural size in px: the browser's ratio hint while it loads; the 4:3 frame sets the box. */
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
/** Describes the image; `''` only when it adds nothing to the caption. */
|
/** Describes the image; `''` only when it adds nothing to the caption. */
|
||||||
|
|
@ -38,7 +38,7 @@ export type MediaCarouselProps = {
|
||||||
export type MediaSlideProps = {
|
export type MediaSlideProps = {
|
||||||
item: MediaItem;
|
item: MediaItem;
|
||||||
index: number;
|
index: number;
|
||||||
/** Alone at its own ratio (max 400px) rather than a 280px slide in the track. */
|
/** Alone in its own rounded frame, with its own expand badge, rather than a slide in the track. */
|
||||||
single: boolean;
|
single: boolean;
|
||||||
/** The button's accessible name; see `slideLabels`. */
|
/** The button's accessible name; see `slideLabels`. */
|
||||||
label?: string;
|
label?: string;
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,34 @@
|
||||||
import { cva } from 'class-variance-authority';
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
/** The image's box: letterboxed on `surface-sunken`, the track's ground when it swipes. */
|
/**
|
||||||
export const mediaSlideVariants = cva('relative', {
|
* The image's frame (DS v6.1): 4:3 and at most 420px tall, whatever the image's own ratio, so a
|
||||||
variants: {
|
* card's height never depends on its picture. Alone it is rounded on `surface-sunken`; in the
|
||||||
single: {
|
* track the track draws that ground and the corners.
|
||||||
true: 'w-full overflow-hidden rounded-md bg-surface-sunken',
|
*/
|
||||||
false: 'h-70 max-h-100 w-full flex-none snap-center snap-always',
|
export const mediaSlideVariants = cva(
|
||||||
|
'relative block aspect-4/3 max-h-105 w-full',
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
single: {
|
||||||
|
true: 'overflow-hidden rounded-md bg-surface-sunken',
|
||||||
|
false: 'flex-none snap-center snap-always',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
);
|
||||||
|
|
||||||
/** Contained, never cropped: the Lightbox shows the image whole anyway. */
|
/** The whole image, contained and centred in the frame, never cropped. */
|
||||||
export const mediaImageVariants = cva('block object-contain', {
|
export const mediaImageVariants = cva(
|
||||||
variants: {
|
'absolute inset-0 block size-full object-contain',
|
||||||
single: {
|
);
|
||||||
true: 'h-auto max-h-100 w-full',
|
|
||||||
false: 'h-auto max-h-full w-auto max-w-full',
|
/**
|
||||||
},
|
* The 28px expand badge at the frame's bottom inline end: says a tap opens the image full size.
|
||||||
},
|
* Decorative and click-through; the image's own button or link carries the action.
|
||||||
});
|
*/
|
||||||
|
export const mediaExpandVariants = cva(
|
||||||
|
'pointer-events-none absolute end-2 bottom-2 size-7 rounded-full bg-scrim-chip text-text-on-action',
|
||||||
|
);
|
||||||
|
|
||||||
/** The current image's dot stretches into an 18px pill. */
|
/** The current image's dot stretches into an 18px pill. */
|
||||||
export const mediaDotVariants = cva(
|
export const mediaDotVariants = cva(
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,125 @@
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { GridBox } from '../../atoms/grid-box';
|
||||||
|
import { Icon } from '../../atoms/icon';
|
||||||
|
import { Spinner } from '../../atoms/spinner';
|
||||||
|
import { Typography } from '../../atoms/typography';
|
||||||
|
import { Element } from '../../primitives/element';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import type { MediaStripItem, MediaStripProps } from './types';
|
||||||
|
import { mediaStripAddVariants, mediaStripTileVariants } from './variants';
|
||||||
|
|
||||||
|
const IMAGE_CLASS = 'block size-full object-cover';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A form's picked images (DS MediaStrip), such as the post composer's: thumbnails in the order
|
||||||
|
* they were added, each with a 28px ✕; one uploading sits under a light veil with a spinner, a
|
||||||
|
* failed one has a danger frame and, with `onRetry`, sends again on tap. A dashed «افزودن» tile
|
||||||
|
* ends the strip until `max`. It wraps; 76px thumbnails, 96px at `lg`.
|
||||||
|
*/
|
||||||
|
export function MediaStrip({
|
||||||
|
items,
|
||||||
|
label,
|
||||||
|
onRemove,
|
||||||
|
onRetry,
|
||||||
|
addLabel,
|
||||||
|
onAdd,
|
||||||
|
max = 4,
|
||||||
|
size = 'md',
|
||||||
|
disabled = false,
|
||||||
|
className,
|
||||||
|
}: MediaStripProps) {
|
||||||
|
const canAdd =
|
||||||
|
onAdd != null && addLabel != null && !disabled && items.length < max;
|
||||||
|
if (items.length === 0 && !canAdd) return null;
|
||||||
|
|
||||||
|
const image = (item: MediaStripItem) => (
|
||||||
|
<Element
|
||||||
|
tag="img"
|
||||||
|
src={item.src}
|
||||||
|
alt={item.status === 'busy' ? (item.busyLabel ?? item.alt) : item.alt}
|
||||||
|
className={IMAGE_CLASS}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlexBox
|
||||||
|
tag="ul"
|
||||||
|
aria-label={label}
|
||||||
|
wrap="flex-wrap"
|
||||||
|
gap="gap-2"
|
||||||
|
className={className}
|
||||||
|
>
|
||||||
|
{items.map((item) => {
|
||||||
|
const status = item.status ?? 'ready';
|
||||||
|
const retry =
|
||||||
|
status === 'error' && onRetry && item.retryLabel ? onRetry : null;
|
||||||
|
return (
|
||||||
|
<Element
|
||||||
|
key={item.key}
|
||||||
|
tag="li"
|
||||||
|
aria-busy={status === 'busy' || undefined}
|
||||||
|
className={mediaStripTileVariants({ size, status })}
|
||||||
|
>
|
||||||
|
{retry ? (
|
||||||
|
<Element
|
||||||
|
tag="button"
|
||||||
|
type="button"
|
||||||
|
onClick={() => retry(item.key)}
|
||||||
|
disabled={disabled}
|
||||||
|
aria-label={item.retryLabel}
|
||||||
|
className="block size-full cursor-pointer focus-visible:focus-ring disabled:cursor-not-allowed"
|
||||||
|
>
|
||||||
|
{image(item)}
|
||||||
|
</Element>
|
||||||
|
) : (
|
||||||
|
image(item)
|
||||||
|
)}
|
||||||
|
{status === 'busy' && (
|
||||||
|
<GridBox
|
||||||
|
justifyItems="justify-items-center"
|
||||||
|
alignItems="items-center"
|
||||||
|
className="absolute inset-0 bg-surface/60 text-text-primary"
|
||||||
|
>
|
||||||
|
<Spinner />
|
||||||
|
</GridBox>
|
||||||
|
)}
|
||||||
|
<GridBox
|
||||||
|
tag="button"
|
||||||
|
type="button"
|
||||||
|
onClick={() => onRemove(item.key)}
|
||||||
|
disabled={disabled}
|
||||||
|
aria-label={item.removeLabel}
|
||||||
|
justifyItems="justify-items-center"
|
||||||
|
alignItems="items-center"
|
||||||
|
className="absolute end-1 top-1 z-1 size-7 cursor-pointer rounded-full bg-scrim-chip text-text-inverse focus-visible:focus-ring disabled:frozen"
|
||||||
|
>
|
||||||
|
<Icon name="close" size={16} />
|
||||||
|
</GridBox>
|
||||||
|
</Element>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{canAdd && (
|
||||||
|
<Element tag="li">
|
||||||
|
<GridBox
|
||||||
|
tag="button"
|
||||||
|
type="button"
|
||||||
|
onClick={onAdd}
|
||||||
|
justifyItems="justify-items-center"
|
||||||
|
alignContent="content-center"
|
||||||
|
className={cn(mediaStripAddVariants({ size }), 'gap-0.5')}
|
||||||
|
>
|
||||||
|
<Icon name="plus" size={20} />
|
||||||
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
variant="micro"
|
||||||
|
color="inherit"
|
||||||
|
className="text-[0.75rem] leading-4 font-semibold"
|
||||||
|
>
|
||||||
|
{addLabel}
|
||||||
|
</Typography>
|
||||||
|
</GridBox>
|
||||||
|
</Element>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
export { MediaStrip } from './MediaStrip';
|
||||||
|
export type {
|
||||||
|
MediaStripItem,
|
||||||
|
MediaStripProps,
|
||||||
|
MediaStripSize,
|
||||||
|
MediaStripStatus,
|
||||||
|
} from './types';
|
||||||
|
export { mediaStripAddVariants, mediaStripTileVariants } from './variants';
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
import type { VariantProps } from 'class-variance-authority';
|
||||||
|
|
||||||
|
import type { mediaStripTileVariants } from './variants';
|
||||||
|
|
||||||
|
/** ready: picked and stored. busy: uploading (a light veil and a spinner). error: failed. */
|
||||||
|
export type MediaStripStatus = 'ready' | 'busy' | 'error';
|
||||||
|
|
||||||
|
export type MediaStripSize = NonNullable<
|
||||||
|
VariantProps<typeof mediaStripTileVariants>['size']
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type MediaStripItem = {
|
||||||
|
/** Stable while the item is in the strip. */
|
||||||
|
key: string;
|
||||||
|
/** What the thumbnail shows: a local preview or the stored file's address. */
|
||||||
|
src: string;
|
||||||
|
/** The image's accessible name, such as «تصویر ۲». */
|
||||||
|
alt: string;
|
||||||
|
/** `ready` by default. */
|
||||||
|
status?: MediaStripStatus;
|
||||||
|
/** The ✕'s accessible name, such as «حذف تصویر ۲». */
|
||||||
|
removeLabel: string;
|
||||||
|
/** busy: what screen readers hear instead of `alt`, such as «در حال آپلود تصویر ۲: ۴۰٪». */
|
||||||
|
busyLabel?: string;
|
||||||
|
/** error: with `onRetry`, the thumbnail sends it again on tap, named so: «آپلود دوباره تصویر ۲». */
|
||||||
|
retryLabel?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type MediaStripProps = {
|
||||||
|
/** In the order they were added. */
|
||||||
|
items: readonly MediaStripItem[];
|
||||||
|
/** The list's accessible name, such as «تصاویر پست». */
|
||||||
|
label: string;
|
||||||
|
onRemove: (key: string) => void;
|
||||||
|
/** A failed item with a `retryLabel` sends again on tap. */
|
||||||
|
onRetry?: (key: string) => void;
|
||||||
|
/** The dashed add tile's text, «افزودن»; the tile shows with `onAdd`, below `max`. */
|
||||||
|
addLabel?: string;
|
||||||
|
onAdd?: () => void;
|
||||||
|
/** At this many the add tile leaves the strip; 4 by default. */
|
||||||
|
max?: number;
|
||||||
|
/** md: 76px thumbnails (mobile). lg: 96px (the desktop composer). */
|
||||||
|
size?: MediaStripSize;
|
||||||
|
/** While the form is sending: the add tile leaves, and ✕ and retry do nothing. */
|
||||||
|
disabled?: boolean;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One thumbnail (DS MediaStrip `lm-thumb`): a radius-md square on sunken surface with a hairline;
|
||||||
|
* a failed one has a 2px danger frame.
|
||||||
|
*/
|
||||||
|
export const mediaStripTileVariants = cva(
|
||||||
|
'relative flex-none overflow-hidden rounded-md bg-surface-sunken',
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
size: {
|
||||||
|
md: 'size-19',
|
||||||
|
lg: 'size-24',
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
ready: 'border border-border-subtle',
|
||||||
|
busy: 'border border-border-subtle',
|
||||||
|
error: 'border-2 border-danger',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { size: 'md', status: 'ready' },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
/** The add tile (DS `lm-thumb--add`): dashed, on surface, the plus over «افزودن» in 12/16/600. */
|
||||||
|
export const mediaStripAddVariants = cva(
|
||||||
|
'cursor-pointer rounded-md border-[1.5px] border-dashed border-border-default bg-surface text-text-secondary transition-colors duration-120 ease-standard hover:bg-surface-hover focus-visible:focus-ring',
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
size: {
|
||||||
|
md: 'size-19',
|
||||||
|
lg: 'size-24',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { size: 'md' },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
@ -1,140 +0,0 @@
|
||||||
'use client';
|
|
||||||
|
|
||||||
import { Button } from '@lumina/island/atoms/button';
|
|
||||||
import { Element } from '@lumina/island/primitives/element';
|
|
||||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
|
||||||
import { Separator } from '@lumina/island/atoms/separator';
|
|
||||||
import { Typography } from '@lumina/island/atoms/typography';
|
|
||||||
import { Card } from '@lumina/island/molecules/card';
|
|
||||||
import { EmptyState } from '@lumina/island/molecules/empty-state';
|
|
||||||
import { ErrorState } from '@lumina/island/molecules/error-state';
|
|
||||||
import { cn } from '@lumina/island/tools/cn';
|
|
||||||
import { date, number } from '@lumina/tools/format';
|
|
||||||
import { useId } from 'react';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
|
|
||||||
import { useSubscribersPart } from '../../../../../../../features/overview';
|
|
||||||
import type { SubscriberListProps } from './types';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* طرحهای اشتراک › مشترکان (Creator Dashboard ۲.۱): the active count in the header, then each
|
|
||||||
* running subscription by @username only, with its plan, start and end; newest start first, 20 at
|
|
||||||
* a time. Rows aren't tappable, and there is no filter, search or action, until Epic 6. With none,
|
|
||||||
* one quiet line (۲.۴).
|
|
||||||
*/
|
|
||||||
export function SubscriberList({ layout }: SubscriberListProps) {
|
|
||||||
const { t } = useTranslation(['dashboard', 'common', 'errors']);
|
|
||||||
const model = useSubscribersPart();
|
|
||||||
const headingId = useId();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card
|
|
||||||
tag="section"
|
|
||||||
aria-labelledby={headingId}
|
|
||||||
padding={layout === 'desktop' ? 'lg' : 'md'}
|
|
||||||
>
|
|
||||||
<FlexBox direction="flex-col">
|
|
||||||
<FlexBox
|
|
||||||
alignItems="items-baseline"
|
|
||||||
justifyContent="justify-between"
|
|
||||||
gap="gap-3"
|
|
||||||
className="pb-0.5"
|
|
||||||
>
|
|
||||||
<Typography tag="h2" id={headingId} variant="heading-sm">
|
|
||||||
{t('subscribers.title')}
|
|
||||||
</Typography>
|
|
||||||
<Typography tag="span" variant="caption" color="secondary">
|
|
||||||
{t('subscribers.active')}{' '}
|
|
||||||
<Typography
|
|
||||||
tag="span"
|
|
||||||
variant="body-lg"
|
|
||||||
className="font-semibold tabular-nums"
|
|
||||||
>
|
|
||||||
{number(model.activeCount)}
|
|
||||||
</Typography>
|
|
||||||
</Typography>
|
|
||||||
</FlexBox>
|
|
||||||
{model.rows.length === 0 ? (
|
|
||||||
<EmptyState
|
|
||||||
title={t('subscribers.empty')}
|
|
||||||
icon="users"
|
|
||||||
size="inline"
|
|
||||||
className="pt-2"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<FlexBox tag="ul" direction="flex-col">
|
|
||||||
{model.rows.map((row, index) => (
|
|
||||||
<FlexBox
|
|
||||||
key={row.id}
|
|
||||||
tag="li"
|
|
||||||
direction="flex-col"
|
|
||||||
className={cn(
|
|
||||||
'gap-0.5 py-2.5',
|
|
||||||
index > 0 && 'border-t border-border-subtle',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<FlexBox
|
|
||||||
alignItems="items-center"
|
|
||||||
justifyContent="justify-between"
|
|
||||||
gap="gap-3"
|
|
||||||
>
|
|
||||||
<Element
|
|
||||||
tag="bdi"
|
|
||||||
dir="ltr"
|
|
||||||
className="truncate font-semibold"
|
|
||||||
>
|
|
||||||
@{row.username ?? '—'}
|
|
||||||
</Element>
|
|
||||||
{row.billingPeriod && (
|
|
||||||
<Typography
|
|
||||||
tag="span"
|
|
||||||
variant="body-sm"
|
|
||||||
className="flex-none"
|
|
||||||
>
|
|
||||||
{t(`common:billing-periods.${row.billingPeriod}`)}
|
|
||||||
</Typography>
|
|
||||||
)}
|
|
||||||
</FlexBox>
|
|
||||||
<Typography variant="caption" color="secondary">
|
|
||||||
{row.startsAt &&
|
|
||||||
t('subscribers.start', {
|
|
||||||
date: date(row.startsAt, { time: false }),
|
|
||||||
})}
|
|
||||||
{row.startsAt && row.endsAt && <Separator />}
|
|
||||||
{row.endsAt &&
|
|
||||||
t('subscribers.end', {
|
|
||||||
date: date(row.endsAt, { time: false }),
|
|
||||||
})}
|
|
||||||
</Typography>
|
|
||||||
</FlexBox>
|
|
||||||
))}
|
|
||||||
</FlexBox>
|
|
||||||
)}
|
|
||||||
{model.loadMoreError ? (
|
|
||||||
<ErrorState
|
|
||||||
kind={model.loadMoreError}
|
|
||||||
size="inline"
|
|
||||||
title={t(`errors:fallback.${model.loadMoreError}.title`)}
|
|
||||||
description={t('subscribers.more-failed')}
|
|
||||||
onRetry={model.loadMore}
|
|
||||||
retryLabel={t('errors:fallback.retry')}
|
|
||||||
retryingLabel={t('errors:fallback.retrying')}
|
|
||||||
retrying={model.isLoadingMore}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
model.hasMore && (
|
|
||||||
<Button
|
|
||||||
variant="secondary"
|
|
||||||
block
|
|
||||||
onClick={model.loadMore}
|
|
||||||
isLoading={model.isLoadingMore}
|
|
||||||
className="mt-2"
|
|
||||||
>
|
|
||||||
{t('subscribers.more')}
|
|
||||||
</Button>
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
</FlexBox>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
|
||||||
import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton';
|
|
||||||
import { Card } from '@lumina/island/molecules/card';
|
|
||||||
|
|
||||||
import type { SubscriberListSkeletonProps } from './types';
|
|
||||||
|
|
||||||
/** مشترکان before it arrives: its header and three rows of two lines. */
|
|
||||||
export function SubscriberListSkeleton({
|
|
||||||
layout,
|
|
||||||
label,
|
|
||||||
delayed,
|
|
||||||
}: SubscriberListSkeletonProps) {
|
|
||||||
return (
|
|
||||||
<SkeletonRegion label={label} delayed={delayed}>
|
|
||||||
<Card padding={layout === 'desktop' ? 'lg' : 'md'}>
|
|
||||||
<FlexBox direction="flex-col">
|
|
||||||
<FlexBox justifyContent="justify-between" className="pb-1">
|
|
||||||
<Skeleton width="25%" />
|
|
||||||
<Skeleton width="30%" />
|
|
||||||
</FlexBox>
|
|
||||||
{[0, 1, 2].map((row) => (
|
|
||||||
<FlexBox
|
|
||||||
key={row}
|
|
||||||
direction="flex-col"
|
|
||||||
gap="gap-2"
|
|
||||||
className="py-3"
|
|
||||||
>
|
|
||||||
<FlexBox justifyContent="justify-between">
|
|
||||||
<Skeleton width="35%" />
|
|
||||||
<Skeleton width="18%" />
|
|
||||||
</FlexBox>
|
|
||||||
<Skeleton width="60%" />
|
|
||||||
</FlexBox>
|
|
||||||
))}
|
|
||||||
</FlexBox>
|
|
||||||
</Card>
|
|
||||||
</SkeletonRegion>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
export { SubscriberList } from './SubscriberList';
|
|
||||||
export { SubscriberListSkeleton } from './SubscriberListSkeleton';
|
|
||||||
export type { SubscriberListProps, SubscriberListSkeletonProps } from './types';
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
export type SubscriberListProps = {
|
|
||||||
layout: 'mobile' | 'desktop';
|
|
||||||
};
|
|
||||||
|
|
||||||
export type SubscriberListSkeletonProps = SubscriberListProps & {
|
|
||||||
/** Hidden status text: «در حال بارگذاری مشترکان…». */
|
|
||||||
label: string;
|
|
||||||
/** Fades in after 300ms, so a fast route never flashes grey. loading.tsx only. */
|
|
||||||
delayed?: boolean;
|
|
||||||
};
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
export { useSubscribersPart } from './use-subscribers-part';
|
|
||||||
export type { SubscribersPartModel } from './types';
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
import type { LoadMoreErrorKind } from '../../../../shared/utils';
|
|
||||||
import type { SubscriberPayload } from '../../repositories/creator-subscribers';
|
|
||||||
|
|
||||||
export type SubscribersPartModel = {
|
|
||||||
activeCount: number;
|
|
||||||
rows: SubscriberPayload[];
|
|
||||||
hasMore: boolean;
|
|
||||||
loadMore: () => void;
|
|
||||||
isLoadingMore: boolean;
|
|
||||||
loadMoreError: LoadMoreErrorKind | null;
|
|
||||||
};
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
import { useSuspenseInfiniteQuery } from '@tanstack/react-query';
|
|
||||||
|
|
||||||
import { firstOfEach, loadMoreErrorKind } from '../../../../shared/utils';
|
|
||||||
import {
|
|
||||||
creatorSubscribersRepository,
|
|
||||||
subscriberKeys,
|
|
||||||
} from '../../repositories/creator-subscribers';
|
|
||||||
import type { SubscribersPartModel } from './types';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* طرحهای اشتراک › مشترکان (Creator Dashboard ۲.۱): the active count and the running
|
|
||||||
* subscriptions, newest start first, 20 at a time. No filters, search or actions until Epic 6.
|
|
||||||
*/
|
|
||||||
export function useSubscribersPart(): SubscribersPartModel {
|
|
||||||
const list = useSuspenseInfiniteQuery({
|
|
||||||
queryKey: subscriberKeys.list(),
|
|
||||||
queryFn: ({ pageParam, signal }) =>
|
|
||||||
creatorSubscribersRepository.list({ page: pageParam }, { signal }),
|
|
||||||
initialPageParam: 1,
|
|
||||||
getNextPageParam: (last) => (last.hasMore ? last.page + 1 : undefined),
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
activeCount: list.data.pages[0].activeCount,
|
|
||||||
rows: firstOfEach(
|
|
||||||
list.data.pages.flatMap((page) => page.items),
|
|
||||||
(row) => row.id,
|
|
||||||
),
|
|
||||||
hasMore: list.hasNextPage,
|
|
||||||
loadMore: () => {
|
|
||||||
if (!list.isFetching) void list.fetchNextPage();
|
|
||||||
},
|
|
||||||
isLoadingMore: list.isFetchingNextPage,
|
|
||||||
loadMoreError: list.isFetchNextPageError
|
|
||||||
? loadMoreErrorKind(list.error)
|
|
||||||
: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
export const CREATOR_SUBSCRIBERS_ENDPOINT = '/subscriptions/me/subscribers';
|
|
||||||
|
|
||||||
export const subscriberKeys = {
|
|
||||||
all: ['overview', 'subscribers'] as const,
|
|
||||||
list: () => [...subscriberKeys.all, 'list'] as const,
|
|
||||||
};
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
import { overviewHttp } from '../../http';
|
|
||||||
import { CREATOR_SUBSCRIBERS_ENDPOINT } from './constants';
|
|
||||||
import { toListSubscribersQueryDto, toSubscribersPagePayload } from './mappers';
|
|
||||||
import type {
|
|
||||||
ListSubscribersArgs,
|
|
||||||
SubscribersPagePayload,
|
|
||||||
SubscribersPageResponseDto,
|
|
||||||
} from './types';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The signed-in creator's running subscriptions, newest start first, 20 a page (Creator Dashboard
|
|
||||||
* ۲.۱). Creator session only: an investor gets 403.
|
|
||||||
*/
|
|
||||||
export const creatorSubscribersRepository = {
|
|
||||||
async list(
|
|
||||||
args: ListSubscribersArgs = {},
|
|
||||||
{ signal }: { signal?: AbortSignal } = {},
|
|
||||||
): Promise<SubscribersPagePayload> {
|
|
||||||
const response = await overviewHttp.get<SubscribersPageResponseDto>(
|
|
||||||
CREATOR_SUBSCRIBERS_ENDPOINT,
|
|
||||||
{ params: toListSubscribersQueryDto(args), signal },
|
|
||||||
);
|
|
||||||
return toSubscribersPagePayload(response);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
export { subscriberKeys } from './constants';
|
|
||||||
export { creatorSubscribersRepository } from './creator-subscribers';
|
|
||||||
export type {
|
|
||||||
ListSubscribersArgs,
|
|
||||||
SubscriberPayload,
|
|
||||||
SubscribersPagePayload,
|
|
||||||
} from './types';
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
import type {
|
|
||||||
ListSubscribersArgs,
|
|
||||||
ListSubscribersQueryDto,
|
|
||||||
SubscribersPagePayload,
|
|
||||||
SubscribersPageResponseDto,
|
|
||||||
} from './types';
|
|
||||||
|
|
||||||
export function toListSubscribersQueryDto(
|
|
||||||
args: ListSubscribersArgs,
|
|
||||||
): ListSubscribersQueryDto {
|
|
||||||
return { page: args.page ?? 1 };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function toSubscribersPagePayload(
|
|
||||||
dto: SubscribersPageResponseDto,
|
|
||||||
): SubscribersPagePayload {
|
|
||||||
return {
|
|
||||||
activeCount: dto.activeCount,
|
|
||||||
items: dto.items.map((item) => ({
|
|
||||||
id: item.id,
|
|
||||||
username: item.username,
|
|
||||||
billingPeriod: item.billingPeriod,
|
|
||||||
startsAt: item.startsAt,
|
|
||||||
endsAt: item.endsAt,
|
|
||||||
})),
|
|
||||||
page: dto.page,
|
|
||||||
hasMore: dto.hasMore,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
import type { BillingPeriod } from '../../../../shared/constants';
|
|
||||||
|
|
||||||
export type ListSubscribersArgs = { page?: number };
|
|
||||||
export type ListSubscribersQueryDto = { page: number };
|
|
||||||
|
|
||||||
/** `SubscriptionService.listSubscribers`'s row. */
|
|
||||||
export type SubscriberResponseDto = {
|
|
||||||
id: string;
|
|
||||||
username: string | null;
|
|
||||||
billingPeriod: BillingPeriod | null;
|
|
||||||
startsAt: string | null;
|
|
||||||
endsAt: string | null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type SubscribersPageResponseDto = {
|
|
||||||
activeCount: number;
|
|
||||||
items: SubscriberResponseDto[];
|
|
||||||
page: number;
|
|
||||||
hasMore: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** A running subscription to the creator: the investor by @username only, never a phone or name. */
|
|
||||||
export type SubscriberPayload = {
|
|
||||||
id: string;
|
|
||||||
username: string | null;
|
|
||||||
billingPeriod: BillingPeriod | null;
|
|
||||||
/** The current period. */
|
|
||||||
startsAt: string | null;
|
|
||||||
endsAt: string | null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type SubscribersPagePayload = {
|
|
||||||
/** مشترکان فعال: every running subscription, not this page's. */
|
|
||||||
activeCount: number;
|
|
||||||
items: SubscriberPayload[];
|
|
||||||
page: number;
|
|
||||||
hasMore: boolean;
|
|
||||||
};
|
|
||||||
Loading…
Reference in New Issue