feat(market): channel, posts, composer, home feed and following
The creator's channel and post pages, the post composer, the investor's home feed and the following tab, in bull and bear. - Channel and post page start from the server's read and re-read in the browser for the creator or a subscriber; locked posts show a gate only once the viewer and their standing are known, frozen for another creator. - Composer: text and up to four images uploaded as picked, free or premium, a device draft that keeps stored file URLs, 15-minute edit of a published post; on desktop a dialog over the page through bear's @modal intercept. - Owner actions: preview as a visitor or subscriber, edit, delete (dialogs locked while sending), close a prediction with the outcome the API recorded. - Follow and unfollow run in tap order; the home feed dates posts from its last read; paged lists read past pages with nothing to show. - Cache stays true after mutations: a delete re-reads the channel's offset pages, a new post resets them, and a post page delete navigates without a stale refresh. - Navigation: bottom nav, mobile top bar, desktop header and publish menu; the preview chrome only for the creator's own post. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
88384fa72d
commit
7949eb0d64
|
|
@ -0,0 +1,27 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { DesktopHeader } from '@lumina/market/app/navigation';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
|
||||
/** The composer before it arrives, under the real header. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<FlexBox direction="flex-col" className="min-h-dvh bg-bg-page">
|
||||
<DesktopHeader />
|
||||
<FlexBox
|
||||
tag="main"
|
||||
justifyContent="justify-center"
|
||||
className="px-8 py-10"
|
||||
>
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
delayed
|
||||
label={i18n.t('content:composer.loading')}
|
||||
className="w-full max-w-content"
|
||||
/>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import { DesktopHeader } from '@lumina/market/app/navigation';
|
||||
import { PostComposer } from '@lumina/market/app/screens/(flow)/compose/post/organisms/post-composer';
|
||||
import { POST_ID_PATTERN } from '@lumina/market/features/post';
|
||||
import type { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
|
||||
type EditPostPageProps = { params: Promise<{ id: string }> };
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
title: i18n.t('content:composer.edit-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/** Editing a published post, in its first 15 minutes; in the browser only. */
|
||||
export default async function EditPostPage({ params }: EditPostPageProps) {
|
||||
const { id } = await params;
|
||||
// The API answers a malformed id with a 500, not a 404.
|
||||
if (!POST_ID_PATTERN.test(id)) notFound();
|
||||
return (
|
||||
<FlexBox direction="flex-col" className="min-h-dvh bg-bg-page">
|
||||
<DesktopHeader />
|
||||
<FlexBox
|
||||
tag="main"
|
||||
justifyContent="justify-center"
|
||||
className="px-8 py-10"
|
||||
>
|
||||
<AuthGuard
|
||||
role="creator"
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
label={i18n.t('content:composer.loading')}
|
||||
className="w-full max-w-content"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<PostComposer layout="desktop" postId={id} />
|
||||
</AuthGuard>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { DesktopHeader } from '@lumina/market/app/navigation';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
/** The composer before it arrives, under the real header. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<FlexBox direction="flex-col" className="min-h-dvh bg-bg-page">
|
||||
<DesktopHeader />
|
||||
<FlexBox
|
||||
tag="main"
|
||||
justifyContent="justify-center"
|
||||
className="px-8 py-10"
|
||||
>
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
delayed
|
||||
label={i18n.t('content:composer.loading')}
|
||||
className="w-full max-w-content"
|
||||
/>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import { DesktopHeader } from '@lumina/market/app/navigation';
|
||||
import { PostComposer } from '@lumina/market/app/screens/(flow)/compose/post/organisms/post-composer';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
title: i18n.t('content:composer.new-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/** A new post (C4 ۷.۳): the 640px composer under the header, in the browser only. */
|
||||
export default function ComposePostPage() {
|
||||
return (
|
||||
<FlexBox direction="flex-col" className="min-h-dvh bg-bg-page">
|
||||
<DesktopHeader />
|
||||
<FlexBox
|
||||
tag="main"
|
||||
justifyContent="justify-center"
|
||||
className="px-8 py-10"
|
||||
>
|
||||
<AuthGuard
|
||||
role="creator"
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
label={i18n.t('content:composer.loading')}
|
||||
className="w-full max-w-content"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<PostComposer layout="desktop" />
|
||||
</AuthGuard>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import { HomeFeedSkeleton } from '@lumina/market/app/screens/(main)/organisms/home-feed';
|
||||
|
||||
import { i18n } from '../../../i18n';
|
||||
import { HomeTemplate } from './templates/home-template';
|
||||
|
||||
/** خانه before it arrives: the heading, then three post skeletons in the 640 column (S1-03). */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<HomeTemplate>
|
||||
<HomeFeedSkeleton
|
||||
layout="desktop"
|
||||
delayed
|
||||
label={i18n.t('home:feed.loading')}
|
||||
/>
|
||||
</HomeTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
import { PartBoundary } from '@lumina/market/app/error-boundaries';
|
||||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
import {
|
||||
EXAMPLE_CHANNEL_USERNAME,
|
||||
HomeFeed,
|
||||
HomeFeedSkeleton,
|
||||
HomeGuard,
|
||||
} from '@lumina/market/app/screens/(main)/organisms/home-feed';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { displayUrl } from '../../../configs';
|
||||
import { i18n } from '../../../i18n';
|
||||
import { HomeTemplate } from './templates/home-template';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return { title: i18n.t('home:meta.title'), robots: { index: false } };
|
||||
}
|
||||
|
||||
/**
|
||||
* خانه, `/`: the investor's feed of the creators they follow. The server sends only the frame and
|
||||
* the feed's skeleton, the same for every visitor; the feed loads in the browser with the session.
|
||||
* A guest goes to login, which returns here, and a creator to their own channel. A failed feed
|
||||
* shows in a card in the column, as the desktop boards draw a state there (S3, S2-Desktop).
|
||||
*/
|
||||
export default function HomePage() {
|
||||
const skeleton = (
|
||||
<HomeFeedSkeleton layout="desktop" label={i18n.t('home:feed.loading')} />
|
||||
);
|
||||
return (
|
||||
<HomeTemplate>
|
||||
<PartBoundary name="home-feed" framed>
|
||||
<HomeGuard fallback={skeleton}>
|
||||
<Suspense fallback={skeleton}>
|
||||
<HomeFeed
|
||||
layout="desktop"
|
||||
exampleChannelUrl={displayUrl(
|
||||
ROUTES.channel(EXAMPLE_CHANNEL_USERNAME),
|
||||
)}
|
||||
/>
|
||||
</Suspense>
|
||||
</HomeGuard>
|
||||
</PartBoundary>
|
||||
</HomeTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import type { HomeTemplateProps } from './types';
|
||||
|
||||
/**
|
||||
* خانه's frame on desktop, shared by the page and its loading: one 640 column under the header,
|
||||
* with no side content (U7 ۶.۱, Main C), the h2 «خانه» at its top as on mobile, then the feed.
|
||||
* The header comes from the main layout, خانه on.
|
||||
*/
|
||||
export function HomeTemplate({ children }: HomeTemplateProps) {
|
||||
const t = i18n.getFixedT(null, 'home');
|
||||
return (
|
||||
<FlexBox tag="main" justifyContent="justify-center" className="px-8 py-10">
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
gap="gap-4"
|
||||
className="w-full max-w-content"
|
||||
>
|
||||
<Typography tag="h2" variant="heading-sm">
|
||||
{t('heading')}
|
||||
</Typography>
|
||||
{children}
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { HomeTemplate } from './HomeTemplate';
|
||||
export type { HomeTemplateProps } from './types';
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import type { ReactNode } from 'react';
|
||||
|
||||
export type HomeTemplateProps = {
|
||||
/** The feed, or its skeleton. */
|
||||
children: ReactNode;
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Locked until a creator finishes registration step 5 (0016), as on the full page; the guard
|
||||
// renders the dialog as is.
|
||||
export { OnboardingGuard as default } from '@lumina/market/app/guards/onboarding-guard';
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import {
|
||||
PostComposerDialog,
|
||||
PostComposerDialogSkeleton,
|
||||
} from '@lumina/market/app/screens/(flow)/compose/post/organisms/post-composer';
|
||||
|
||||
/**
|
||||
* A new post opened from a main page (C4 ۷.۳): the 640px composer dialog over that page, the URL
|
||||
* /compose/post; a direct load of that URL gets the full page instead. In the browser only: the
|
||||
* dialog's skeleton until the viewer is known, then the composer for a creator, or the no-access
|
||||
* state in the dialog for anyone else.
|
||||
*/
|
||||
export default function ComposePostDialog() {
|
||||
return (
|
||||
<AuthGuard fallback={<PostComposerDialogSkeleton />}>
|
||||
<PostComposerDialog />
|
||||
</AuthGuard>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
/**
|
||||
* Empties the `@modal` slot on the channel. A slot keeps its last page through a soft navigation
|
||||
* to a route it has none for, so without this the «پست جدید» dialog would stay open over the
|
||||
* channel it lands on after publishing. Only this route: a catch-all here would also match every
|
||||
* path without a page, and a soft navigation there would keep the old page under the new URL.
|
||||
*/
|
||||
export default function ChannelModal() {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
/** No dialog: what the `@modal` slot shows on a direct load and on every page that opens none. */
|
||||
export default function ModalDefault() {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* Empties the `@modal` slot on خانه. A slot keeps its last page through a soft navigation to a
|
||||
* route it has none for, so without this the «پست جدید» dialog would stay open over خانه when it
|
||||
* closes there (the composer's fallback with no history behind it) or when a link leads home while
|
||||
* it is open. Only this route: a catch-all here would also match every path without a page, and a
|
||||
* soft navigation there would keep the old page under the new URL.
|
||||
*/
|
||||
export default function HomeModal() {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
/** The channel before it arrives: the header panel, then a post, in the 640 column. */
|
||||
export default function Loading() {
|
||||
const t = i18n.getFixedT(null, 'channel');
|
||||
return (
|
||||
<FlexBox tag="main" justifyContent="justify-center" className="px-8 py-10">
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
gap="gap-4"
|
||||
className="w-full max-w-content"
|
||||
>
|
||||
<Card padding="lg">
|
||||
<SkeletonPreset preset="header" framed delayed label={t('loading')} />
|
||||
</Card>
|
||||
<SkeletonPreset preset="post-media" delayed label={t('feed.loading')} />
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { ChannelNotFound } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-not-found';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { displayUrl } from '../../../../configs';
|
||||
|
||||
export const metadata: Metadata = { robots: { index: false } };
|
||||
|
||||
/** No channel at this address, or not any more. */
|
||||
export default function ChannelNotFoundPage() {
|
||||
return (
|
||||
<FlexBox tag="main" justifyContent="justify-center" className="px-8 py-10">
|
||||
<FlexBox direction="flex-col" className="w-full max-w-content">
|
||||
<ChannelNotFound layout="desktop" siteHost={displayUrl('')} />
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
import {
|
||||
channelMetadata,
|
||||
getChannel,
|
||||
getRequestTime,
|
||||
readOnServer,
|
||||
} from '@lumina/market/server';
|
||||
import { toChannelUsername } from '@lumina/market/shared/utils';
|
||||
import type { Metadata } from 'next';
|
||||
import { notFound, permanentRedirect } from 'next/navigation';
|
||||
|
||||
import { displayUrl } from '../../../../configs';
|
||||
import { i18n } from '../../../../i18n';
|
||||
import { ChannelTemplate } from './templates/channel-template';
|
||||
|
||||
type ChannelPageProps = { params: Promise<{ username: string }> };
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: ChannelPageProps): Promise<Metadata> {
|
||||
const username = toChannelUsername((await params).username);
|
||||
if (!username) return { robots: { index: false } };
|
||||
const channel = await readOnServer(() => getChannel(username));
|
||||
if (channel.status !== 'ok') return { robots: { index: false } };
|
||||
if (channel.data.suspended) {
|
||||
return {
|
||||
title: i18n.t('channel:meta.unavailable-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
return channelMetadata({
|
||||
channel: channel.data,
|
||||
title: i18n.t('channel:meta.title', { username }),
|
||||
description: i18n.t('channel:meta.description', { username }),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A creator's channel, `/@username`. The same server render for every visitor: the header, the
|
||||
* track record and the first posts; subscribe, follow and the locked posts' gates load in the
|
||||
* browser. Any other spelling of the username redirects to the one the API stores.
|
||||
*/
|
||||
export default async function ChannelPage({ params }: ChannelPageProps) {
|
||||
const segment = (await params).username;
|
||||
const username = toChannelUsername(segment);
|
||||
if (!username) notFound();
|
||||
if (username !== segment) permanentRedirect(ROUTES.channel(username));
|
||||
const channel = await readOnServer(() => getChannel(username));
|
||||
if (channel.status !== 'ok') notFound();
|
||||
|
||||
return (
|
||||
<ChannelTemplate
|
||||
channel={channel.data}
|
||||
channelUrl={displayUrl(ROUTES.channel(username))}
|
||||
now={getRequestTime()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../../i18n';
|
||||
|
||||
/**
|
||||
* The post before it arrives, in the 640 column (C4b ۱.۵): the channel bar's panel with the author
|
||||
* row and the subscribe and follow row, then the post with its media. No lock is guessed meanwhile.
|
||||
*/
|
||||
export default function Loading() {
|
||||
const t = i18n.getFixedT(null, 'channel');
|
||||
return (
|
||||
<FlexBox tag="main" justifyContent="justify-center" className="px-8 py-10">
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
gap="gap-4"
|
||||
className="w-full max-w-content"
|
||||
>
|
||||
<Card padding="lg">
|
||||
<SkeletonRegion delayed label={t('loading')}>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
gap="gap-3"
|
||||
className="min-h-touch-target"
|
||||
>
|
||||
<Skeleton shape="circle" className="size-10" />
|
||||
<Skeleton className="h-4 w-32" />
|
||||
</FlexBox>
|
||||
<FlexBox gap="gap-2">
|
||||
<Skeleton shape="pill" className="h-control-md flex-1" />
|
||||
<Skeleton shape="pill" className="h-control-md w-32" />
|
||||
</FlexBox>
|
||||
</SkeletonRegion>
|
||||
</Card>
|
||||
<SkeletonPreset preset="post-media" delayed label={t('post.loading')} />
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
import { POST_ID_PATTERN } from '@lumina/market/features/post';
|
||||
import {
|
||||
getChannel,
|
||||
getRequestTime,
|
||||
getPost,
|
||||
postMetadata,
|
||||
readOnServer,
|
||||
} from '@lumina/market/server';
|
||||
import { toChannelUsername } from '@lumina/market/shared/utils';
|
||||
import type { Metadata } from 'next';
|
||||
import { notFound, permanentRedirect } from 'next/navigation';
|
||||
|
||||
import { displayUrl } from '../../../../../../configs';
|
||||
import { i18n } from '../../../../../../i18n';
|
||||
import { PostTemplate } from './templates/post-template';
|
||||
|
||||
type PostPageProps = { params: Promise<{ username: string; id: string }> };
|
||||
|
||||
/** The channel and the post, read together; a post that isn't this channel's is missing. */
|
||||
async function readPostPage(username: string, id: string) {
|
||||
const [channel, post] = await Promise.all([
|
||||
readOnServer(() => getChannel(username)),
|
||||
POST_ID_PATTERN.test(id)
|
||||
? readOnServer(() => getPost(id))
|
||||
: ({ status: 'not-found' } as const),
|
||||
]);
|
||||
if (channel.status !== 'ok') return null;
|
||||
const found =
|
||||
post.status === 'ok' && post.data.creatorId === channel.data.creatorId
|
||||
? post.data
|
||||
: null;
|
||||
return { channel: channel.data, post: found };
|
||||
}
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: PostPageProps): Promise<Metadata> {
|
||||
const { username: segment, id } = await params;
|
||||
const username = toChannelUsername(segment);
|
||||
const page = username ? await readPostPage(username, id) : null;
|
||||
if (!page?.post || page.channel.suspended) {
|
||||
return {
|
||||
title: i18n.t('channel:meta.post-missing-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
return postMetadata({
|
||||
channel: page.channel,
|
||||
post: page.post,
|
||||
fallbackTitle: i18n.t('channel:meta.post-title', {
|
||||
username: page.channel.username,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* One post, `/@username/posts/[id]`: where every shared link lands. The server renders it as every
|
||||
* visitor sees it; a subscriber's or the creator's premium post opens in the browser. A deleted
|
||||
* or unknown post keeps the channel's frame and leads back to the channel.
|
||||
*/
|
||||
export default async function PostPage({ params }: PostPageProps) {
|
||||
const { username: segment, id } = await params;
|
||||
const username = toChannelUsername(segment);
|
||||
if (!username) notFound();
|
||||
if (username !== segment) permanentRedirect(ROUTES.post(username, id));
|
||||
const page = await readPostPage(username, id);
|
||||
if (!page) notFound();
|
||||
|
||||
return (
|
||||
<PostTemplate
|
||||
channel={page.channel}
|
||||
post={page.post}
|
||||
channelUrl={displayUrl(ROUTES.channel(username))}
|
||||
now={getRequestTime()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { PartBoundary } from '@lumina/market/app/error-boundaries';
|
||||
import { ChannelActions } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-actions';
|
||||
import { ChannelUnavailable } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-unavailable';
|
||||
import { PostChannelBar } from '@lumina/market/app/screens/(main)/channels/[username]/posts/[id]/organisms/post-channel-bar';
|
||||
import { PostMissing } from '@lumina/market/app/screens/(main)/channels/[username]/posts/[id]/organisms/post-missing';
|
||||
import { PostView } from '@lumina/market/app/screens/(main)/channels/[username]/posts/[id]/organisms/post-view';
|
||||
|
||||
import { i18n } from '../../../../../../../../i18n';
|
||||
import type { PostTemplateProps } from './types';
|
||||
|
||||
/**
|
||||
* The post on desktop, in the 640 column: the creator with subscribe and follow, then the post in
|
||||
* full. The action area loads in the browser.
|
||||
*/
|
||||
export function PostTemplate({
|
||||
channel,
|
||||
post,
|
||||
channelUrl,
|
||||
now,
|
||||
}: PostTemplateProps) {
|
||||
const t = i18n.getFixedT(null, 'channel');
|
||||
|
||||
return (
|
||||
<FlexBox tag="main" justifyContent="justify-center" className="px-8 py-10">
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
gap="gap-4"
|
||||
className="w-full max-w-content"
|
||||
>
|
||||
{channel.suspended ? (
|
||||
<ChannelUnavailable context="post" />
|
||||
) : post ? (
|
||||
<>
|
||||
<PostChannelBar
|
||||
channel={channel}
|
||||
layout="desktop"
|
||||
verifiedLabel={t('header.verified')}
|
||||
actions={
|
||||
<PartBoundary name="post-channel-actions">
|
||||
<ChannelActions
|
||||
creatorId={channel.creatorId}
|
||||
username={channel.username}
|
||||
channelUrl={channelUrl}
|
||||
layout="desktop"
|
||||
/>
|
||||
</PartBoundary>
|
||||
}
|
||||
/>
|
||||
<PostView
|
||||
post={post}
|
||||
username={channel.username}
|
||||
avatarUrl={channel.avatarUrl}
|
||||
now={now}
|
||||
layout="desktop"
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<PostMissing username={channel.username} />
|
||||
)}
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { PostTemplate } from './PostTemplate';
|
||||
export type { PostTemplateProps } from './types';
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import type { PublicCreatorPayload } from '@lumina/market/features/channel';
|
||||
import type { PostPayload } from '@lumina/market/features/post';
|
||||
|
||||
export type PostTemplateProps = {
|
||||
channel: PublicCreatorPayload;
|
||||
/** `null`: deleted, unknown, or another channel's. */
|
||||
post: PostPayload | null;
|
||||
/** «lumina.ir/@sara_gold», for the guest's login prompt. */
|
||||
channelUrl: string;
|
||||
/** The render's time: the post's time counts from it. */
|
||||
now: string;
|
||||
};
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { PartBoundary } from '@lumina/market/app/error-boundaries';
|
||||
import { ChannelActions } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-actions';
|
||||
import { ChannelFeed } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-feed/server';
|
||||
import {
|
||||
ChannelHeader,
|
||||
channelHeaderLabels,
|
||||
} from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-header';
|
||||
import { ChannelShare } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-share';
|
||||
import { ChannelStats } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-stats/server';
|
||||
import { ChannelUnavailable } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-unavailable';
|
||||
import { creatorStatsLabels } from '@lumina/market/shared/labels';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../../../../i18n';
|
||||
import type { ChannelTemplateProps } from './types';
|
||||
|
||||
/**
|
||||
* The channel on desktop: one 640px column, no side rail. The header panel renders at once; the
|
||||
* track record and the feed stream in reading order, each in its own boundary, and the action
|
||||
* area loads in the browser.
|
||||
*/
|
||||
export function ChannelTemplate({
|
||||
channel,
|
||||
channelUrl,
|
||||
now,
|
||||
}: ChannelTemplateProps) {
|
||||
const t = i18n.getFixedT(null, 'channel');
|
||||
|
||||
// Suspension outranks everything: no header, posts or actions, for anyone (U6 ۵.۳).
|
||||
if (channel.suspended) {
|
||||
return (
|
||||
<FlexBox
|
||||
tag="main"
|
||||
justifyContent="justify-center"
|
||||
className="px-8 py-10"
|
||||
>
|
||||
<FlexBox direction="flex-col" className="w-full max-w-content">
|
||||
<ChannelUnavailable
|
||||
context="channel"
|
||||
channel={channel}
|
||||
channelUrl={channelUrl}
|
||||
layout="desktop"
|
||||
/>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<FlexBox tag="main" justifyContent="justify-center" className="px-8 py-10">
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
gap="gap-4"
|
||||
className="w-full max-w-content"
|
||||
>
|
||||
<ChannelHeader
|
||||
channel={channel}
|
||||
channelUrl={channelUrl}
|
||||
layout="desktop"
|
||||
share={
|
||||
<ChannelShare
|
||||
creatorId={channel.creatorId}
|
||||
username={channel.username}
|
||||
channelUrl={channelUrl}
|
||||
layout="desktop"
|
||||
/>
|
||||
}
|
||||
stats={
|
||||
<PartBoundary
|
||||
name="channel-stats"
|
||||
title={t('stats.error-title')}
|
||||
description={t('stats.error-description')}
|
||||
framed
|
||||
>
|
||||
<Suspense
|
||||
fallback={
|
||||
<SkeletonPreset preset="stats" label={t('stats.loading')} />
|
||||
}
|
||||
>
|
||||
<ChannelStats
|
||||
creatorId={channel.creatorId}
|
||||
labels={creatorStatsLabels(i18n.getFixedT(null, 'content'))}
|
||||
/>
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
}
|
||||
actions={
|
||||
<PartBoundary name="channel-actions">
|
||||
<ChannelActions
|
||||
creatorId={channel.creatorId}
|
||||
username={channel.username}
|
||||
channelUrl={channelUrl}
|
||||
layout="desktop"
|
||||
/>
|
||||
</PartBoundary>
|
||||
}
|
||||
labels={channelHeaderLabels(t, i18n.getFixedT(null, 'common'))}
|
||||
/>
|
||||
<PartBoundary name="channel-feed">
|
||||
<Suspense
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="post"
|
||||
count={2}
|
||||
label={t('feed.loading')}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<ChannelFeed channel={channel} now={now} layout="desktop" />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { ChannelTemplate } from './ChannelTemplate';
|
||||
export type { ChannelTemplateProps } from './types';
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import type { PublicCreatorPayload } from '@lumina/market/features/channel';
|
||||
|
||||
export type ChannelTemplateProps = {
|
||||
channel: PublicCreatorPayload;
|
||||
/** «lumina.ir/@sara_gold». */
|
||||
channelUrl: string;
|
||||
/** The render's time: the posts' relative times count from it. */
|
||||
now: string;
|
||||
};
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
|
||||
/** The list before it arrives, row for row; the layout keeps the heading and the tabs. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<SkeletonPreset
|
||||
preset="list"
|
||||
cards="lg"
|
||||
delayed
|
||||
label={i18n.t('dashboard:following.loading')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { PartBoundary } from '@lumina/market/app/error-boundaries';
|
||||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import { FollowingList } from '@lumina/market/app/screens/(main)/dashboard/following/organisms/following-list';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
title: i18n.t('dashboard:following.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* داشبورد › دنبالشدهها (U8 ۶.۱): the investor's own list, in the browser only, behind rows of the
|
||||
* same size. A failed read shows in place of the list; the heading and the tabs stay (U8 ۴.۵).
|
||||
*/
|
||||
export default function FollowingPage() {
|
||||
const skeleton = (
|
||||
<SkeletonPreset
|
||||
preset="list"
|
||||
cards="lg"
|
||||
label={i18n.t('dashboard:following.loading')}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<PartBoundary
|
||||
name="following-list"
|
||||
description={i18n.t('dashboard:following.error')}
|
||||
framed
|
||||
>
|
||||
<AuthGuard role="investor" fallback={skeleton}>
|
||||
<Suspense fallback={skeleton}>
|
||||
<FollowingList layout="desktop" />
|
||||
</Suspense>
|
||||
</AuthGuard>
|
||||
</PartBoundary>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { DashboardTabs } from '@lumina/market/app/screens/(main)/dashboard/organisms/dashboard-tabs';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
/**
|
||||
* The investor's داشبورد on desktop (U8 ۶.۱; U2): the 640 column under the header, with the
|
||||
* «داشبورد» heading, the section row «اشتراکها» · «تراکنشها» · «دنبالشدهها», then the section.
|
||||
* Each section is its own route with its own loading, so the heading and the row stay while one
|
||||
* loads.
|
||||
*/
|
||||
export default function InvestorDashboardLayout({
|
||||
children,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<FlexBox tag="main" justifyContent="justify-center" className="px-8 py-10">
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
gap="gap-4"
|
||||
className="w-full max-w-content"
|
||||
>
|
||||
<Typography tag="h1" variant="heading-lg">
|
||||
{i18n.t('common:nav.dashboard')}
|
||||
</Typography>
|
||||
<DashboardTabs layout="desktop" />
|
||||
{children}
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
|
||||
/**
|
||||
* The main page under the «پست جدید» dialog when there is none. A soft navigation to /compose/post
|
||||
* from outside the main pages (the full composer's own header, a login that returns there) still
|
||||
* lands on the `@modal` intercept, with no main page for it to cover. Load the URL again, so the
|
||||
* full composer page takes over.
|
||||
*/
|
||||
export default function MainDefault() {
|
||||
useEffect(() => {
|
||||
window.location.replace(window.location.href);
|
||||
}, []);
|
||||
return null;
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { DesktopHeader } from '@lumina/market/app/navigation';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
type MainLayoutProps = {
|
||||
children: ReactNode;
|
||||
/** The `@modal` slot: «پست جدید» over the page (C4 ۷.۳), or nothing. */
|
||||
modal: ReactNode;
|
||||
};
|
||||
|
||||
/**
|
||||
* The main pages on desktop: the header over each page's column. «انتشار» › «پست جدید» opens the
|
||||
* composer as a dialog over the page in the `@modal` slot, which intercepts /compose/post.
|
||||
*/
|
||||
export default function MainLayout({ children, modal }: MainLayoutProps) {
|
||||
return (
|
||||
<FlexBox direction="flex-col" className="min-h-dvh bg-bg-page">
|
||||
<DesktopHeader />
|
||||
{children}
|
||||
{modal}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
export { getQueryClient } from './react-query';
|
||||
export { rootMetadata } from './seo';
|
||||
export { displayUrl } from './site';
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
import { clientEnv } from '../env';
|
||||
|
||||
/** A path on this site as people read and type it, without the scheme: «lumina.ir/@sara_gold». */
|
||||
export function displayUrl(path: string): string {
|
||||
return `${new URL(clientEnv.NEXT_PUBLIC_SITE_URL).host}${path}`;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
|
||||
/** The composer before it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
delayed
|
||||
label={i18n.t('content:composer.loading')}
|
||||
className="p-4"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import { PostComposer } from '@lumina/market/app/screens/(flow)/compose/post/organisms/post-composer';
|
||||
import { POST_ID_PATTERN } from '@lumina/market/features/post';
|
||||
import type { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
|
||||
type EditPostPageProps = { params: Promise<{ id: string }> };
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
title: i18n.t('content:composer.edit-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/** Editing a published post (C4 ۵.۲), in its first 15 minutes; in the browser only. */
|
||||
export default async function EditPostPage({ params }: EditPostPageProps) {
|
||||
const { id } = await params;
|
||||
// The API answers a malformed id with a 500, not a 404.
|
||||
if (!POST_ID_PATTERN.test(id)) notFound();
|
||||
return (
|
||||
<AuthGuard
|
||||
role="creator"
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
label={i18n.t('content:composer.loading')}
|
||||
className="p-4"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<PostComposer layout="mobile" postId={id} />
|
||||
</AuthGuard>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
/** The composer before it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
delayed
|
||||
label={i18n.t('content:composer.loading')}
|
||||
className="p-4"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import { PostComposer } from '@lumina/market/app/screens/(flow)/compose/post/organisms/post-composer';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
title: i18n.t('content:composer.new-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/** A new post (C4): the creator's own task flow, in the browser only, with no bottom nav. */
|
||||
export default function ComposePostPage() {
|
||||
return (
|
||||
<AuthGuard
|
||||
role="creator"
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
label={i18n.t('content:composer.loading')}
|
||||
className="p-4"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<PostComposer layout="mobile" />
|
||||
</AuthGuard>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import { HomeFeedSkeleton } from '@lumina/market/app/screens/(main)/organisms/home-feed';
|
||||
|
||||
import { i18n } from '../../../i18n';
|
||||
import { HomeTemplate } from './templates/home-template';
|
||||
|
||||
/** خانه before it arrives (S1-03): the real top bar and heading, then three post skeletons. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<HomeTemplate>
|
||||
<HomeFeedSkeleton
|
||||
layout="mobile"
|
||||
delayed
|
||||
label={i18n.t('home:feed.loading')}
|
||||
/>
|
||||
</HomeTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
import { PartBoundary } from '@lumina/market/app/error-boundaries';
|
||||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
import {
|
||||
EXAMPLE_CHANNEL_USERNAME,
|
||||
HomeFeed,
|
||||
HomeFeedSkeleton,
|
||||
HomeGuard,
|
||||
} from '@lumina/market/app/screens/(main)/organisms/home-feed';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { displayUrl } from '../../../configs';
|
||||
import { i18n } from '../../../i18n';
|
||||
import { HomeTemplate } from './templates/home-template';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return { title: i18n.t('home:meta.title'), robots: { index: false } };
|
||||
}
|
||||
|
||||
/**
|
||||
* خانه, `/`: the investor's feed of the creators they follow. The server sends only the frame and
|
||||
* the feed's skeleton, the same for every visitor; the feed loads in the browser with the session.
|
||||
* A guest goes to login, which returns here, and a creator to their own channel.
|
||||
*/
|
||||
export default function HomePage() {
|
||||
const skeleton = (
|
||||
<HomeFeedSkeleton layout="mobile" label={i18n.t('home:feed.loading')} />
|
||||
);
|
||||
return (
|
||||
<HomeTemplate>
|
||||
<PartBoundary name="home-feed">
|
||||
<HomeGuard fallback={skeleton}>
|
||||
<Suspense fallback={skeleton}>
|
||||
<HomeFeed
|
||||
layout="mobile"
|
||||
exampleChannelUrl={displayUrl(
|
||||
ROUTES.channel(EXAMPLE_CHANNEL_USERNAME),
|
||||
)}
|
||||
/>
|
||||
</Suspense>
|
||||
</HomeGuard>
|
||||
</PartBoundary>
|
||||
</HomeTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { MobileTopBar } from '@lumina/market/app/navigation';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import type { HomeTemplateProps } from './types';
|
||||
|
||||
/**
|
||||
* خانه's frame on mobile, shared by the page and its loading: the tab's top bar (the brand,
|
||||
* support and the account, no title), then «خانه» over the feed, the h2 the boards draw
|
||||
* (Home--relocked, Home--confirmed-banner). The bottom nav comes from the main layout, خانه on.
|
||||
*/
|
||||
export function HomeTemplate({ children }: HomeTemplateProps) {
|
||||
const t = i18n.getFixedT(null, 'home');
|
||||
return (
|
||||
<>
|
||||
<MobileTopBar isTab />
|
||||
<FlexBox
|
||||
tag="main"
|
||||
direction="flex-col"
|
||||
gap="gap-3"
|
||||
className="flex-1 p-4"
|
||||
>
|
||||
<Typography tag="h2" variant="heading-sm">
|
||||
{t('heading')}
|
||||
</Typography>
|
||||
{children}
|
||||
</FlexBox>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { HomeTemplate } from './HomeTemplate';
|
||||
export type { HomeTemplateProps } from './types';
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import type { ReactNode } from 'react';
|
||||
|
||||
export type HomeTemplateProps = {
|
||||
/** The feed, or its skeleton; it fills the height, so an empty feed centres in it. */
|
||||
children: ReactNode;
|
||||
};
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { MobileTopBar } from '@lumina/market/app/navigation';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
/** The channel before it arrives: the real top bar, then the header, track record and a post. */
|
||||
export default function Loading() {
|
||||
const t = i18n.getFixedT(null, 'channel');
|
||||
return (
|
||||
<>
|
||||
<MobileTopBar title={t('top-bar.channel')} />
|
||||
<FlexBox tag="main" direction="flex-col" className="flex-1">
|
||||
{/* The skeleton draws the header's flush band itself. */}
|
||||
<SkeletonPreset preset="header" delayed label={t('loading')} />
|
||||
<FlexBox direction="flex-col" gap="gap-3" className="p-4">
|
||||
<SkeletonPreset
|
||||
preset="post-media"
|
||||
delayed
|
||||
label={t('feed.loading')}
|
||||
/>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import {
|
||||
ChannelNotFound,
|
||||
ChannelNotFoundTopBar,
|
||||
} from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-not-found';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { displayUrl } from '../../../../configs';
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
export const metadata: Metadata = { robots: { index: false } };
|
||||
|
||||
/**
|
||||
* No channel at this address, or not any more. Its creator, before approval, sees their own tab
|
||||
* here instead (C6 ۱.۲), under their tab bar; both are decided in the browser. The main is flush
|
||||
* for that tab's banner strip and header; the message keeps its own inset.
|
||||
*/
|
||||
export default function ChannelNotFoundPage() {
|
||||
return (
|
||||
<>
|
||||
<ChannelNotFoundTopBar title={i18n.t('channel:top-bar.channel')} />
|
||||
<FlexBox tag="main" direction="flex-col" className="flex-1">
|
||||
<ChannelNotFound layout="mobile" siteHost={displayUrl('')} />
|
||||
</FlexBox>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
import {
|
||||
channelMetadata,
|
||||
getChannel,
|
||||
getRequestTime,
|
||||
readOnServer,
|
||||
} from '@lumina/market/server';
|
||||
import { toChannelUsername } from '@lumina/market/shared/utils';
|
||||
import type { Metadata } from 'next';
|
||||
import { notFound, permanentRedirect } from 'next/navigation';
|
||||
|
||||
import { displayUrl } from '../../../../configs';
|
||||
import { i18n } from '../../../../i18n';
|
||||
import { ChannelTemplate } from './templates/channel-template';
|
||||
|
||||
type ChannelPageProps = { params: Promise<{ username: string }> };
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: ChannelPageProps): Promise<Metadata> {
|
||||
const username = toChannelUsername((await params).username);
|
||||
if (!username) return { robots: { index: false } };
|
||||
const channel = await readOnServer(() => getChannel(username));
|
||||
if (channel.status !== 'ok') return { robots: { index: false } };
|
||||
if (channel.data.suspended) {
|
||||
return {
|
||||
title: i18n.t('channel:meta.unavailable-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
return channelMetadata({
|
||||
channel: channel.data,
|
||||
title: i18n.t('channel:meta.title', { username }),
|
||||
description: i18n.t('channel:meta.description', { username }),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A creator's channel, `/@username`. The same server render for every visitor: the header, the
|
||||
* track record and the first posts; subscribe, follow and the locked posts' gates load in the
|
||||
* browser. Any other spelling of the username redirects to the one the API stores.
|
||||
*/
|
||||
export default async function ChannelPage({ params }: ChannelPageProps) {
|
||||
const segment = (await params).username;
|
||||
const username = toChannelUsername(segment);
|
||||
if (!username) notFound();
|
||||
if (username !== segment) permanentRedirect(ROUTES.channel(username));
|
||||
const channel = await readOnServer(() => getChannel(username));
|
||||
if (channel.status !== 'ok') notFound();
|
||||
|
||||
return (
|
||||
<ChannelTemplate
|
||||
channel={channel.data}
|
||||
channelUrl={displayUrl(ROUTES.channel(username))}
|
||||
now={getRequestTime()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { MobileTopBar } from '@lumina/market/app/navigation';
|
||||
|
||||
import { i18n } from '../../../../../../i18n';
|
||||
|
||||
/**
|
||||
* The post before it arrives, in the real layout (C4b ۱.۵): the live top bar, the channel bar's
|
||||
* band with the author row and the subscribe and follow row, then the post with its media. No lock
|
||||
* is guessed meanwhile.
|
||||
*/
|
||||
export default function Loading() {
|
||||
const t = i18n.getFixedT(null, 'channel');
|
||||
return (
|
||||
<>
|
||||
<MobileTopBar title={t('top-bar.post')} />
|
||||
<FlexBox tag="main" direction="flex-col" className="flex-1">
|
||||
<SkeletonRegion
|
||||
delayed
|
||||
label={t('loading')}
|
||||
className="border-b border-border-subtle bg-surface p-4"
|
||||
>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
gap="gap-3"
|
||||
className="min-h-touch-target"
|
||||
>
|
||||
<Skeleton shape="circle" className="size-10" />
|
||||
<Skeleton className="h-4 w-32" />
|
||||
</FlexBox>
|
||||
<FlexBox gap="gap-2">
|
||||
<Skeleton shape="pill" className="h-control-md flex-1" />
|
||||
<Skeleton shape="pill" className="h-control-md w-32" />
|
||||
</FlexBox>
|
||||
</SkeletonRegion>
|
||||
<FlexBox direction="flex-col" className="p-4">
|
||||
<SkeletonPreset
|
||||
preset="post-media"
|
||||
delayed
|
||||
label={t('post.loading')}
|
||||
/>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
import { POST_ID_PATTERN } from '@lumina/market/features/post';
|
||||
import {
|
||||
getChannel,
|
||||
getRequestTime,
|
||||
getPost,
|
||||
postMetadata,
|
||||
readOnServer,
|
||||
} from '@lumina/market/server';
|
||||
import { toChannelUsername } from '@lumina/market/shared/utils';
|
||||
import type { Metadata } from 'next';
|
||||
import { notFound, permanentRedirect } from 'next/navigation';
|
||||
|
||||
import { displayUrl } from '../../../../../../configs';
|
||||
import { i18n } from '../../../../../../i18n';
|
||||
import { PostTemplate } from './templates/post-template';
|
||||
|
||||
type PostPageProps = { params: Promise<{ username: string; id: string }> };
|
||||
|
||||
/** The channel and the post, read together; a post that isn't this channel's is missing. */
|
||||
async function readPostPage(username: string, id: string) {
|
||||
const [channel, post] = await Promise.all([
|
||||
readOnServer(() => getChannel(username)),
|
||||
POST_ID_PATTERN.test(id)
|
||||
? readOnServer(() => getPost(id))
|
||||
: ({ status: 'not-found' } as const),
|
||||
]);
|
||||
if (channel.status !== 'ok') return null;
|
||||
const found =
|
||||
post.status === 'ok' && post.data.creatorId === channel.data.creatorId
|
||||
? post.data
|
||||
: null;
|
||||
return { channel: channel.data, post: found };
|
||||
}
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: PostPageProps): Promise<Metadata> {
|
||||
const { username: segment, id } = await params;
|
||||
const username = toChannelUsername(segment);
|
||||
const page = username ? await readPostPage(username, id) : null;
|
||||
if (!page?.post || page.channel.suspended) {
|
||||
return {
|
||||
title: i18n.t('channel:meta.post-missing-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
return postMetadata({
|
||||
channel: page.channel,
|
||||
post: page.post,
|
||||
fallbackTitle: i18n.t('channel:meta.post-title', {
|
||||
username: page.channel.username,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* One post, `/@username/posts/[id]`: where every shared link lands. The server renders it as every
|
||||
* visitor sees it; a subscriber's or the creator's premium post opens in the browser. A deleted
|
||||
* or unknown post keeps the channel's frame and leads back to the channel.
|
||||
*/
|
||||
export default async function PostPage({ params }: PostPageProps) {
|
||||
const { username: segment, id } = await params;
|
||||
const username = toChannelUsername(segment);
|
||||
if (!username) notFound();
|
||||
if (username !== segment) permanentRedirect(ROUTES.post(username, id));
|
||||
const page = await readPostPage(username, id);
|
||||
if (!page) notFound();
|
||||
|
||||
return (
|
||||
<PostTemplate
|
||||
channel={page.channel}
|
||||
post={page.post}
|
||||
channelUrl={displayUrl(ROUTES.channel(username))}
|
||||
now={getRequestTime()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { PartBoundary } from '@lumina/market/app/error-boundaries';
|
||||
import { MobileTopBar } from '@lumina/market/app/navigation';
|
||||
import { ChannelActions } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-actions';
|
||||
import { ChannelUnavailable } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-unavailable';
|
||||
import { PostChannelBar } from '@lumina/market/app/screens/(main)/channels/[username]/posts/[id]/organisms/post-channel-bar';
|
||||
import { PostMissing } from '@lumina/market/app/screens/(main)/channels/[username]/posts/[id]/organisms/post-missing';
|
||||
import { PostView } from '@lumina/market/app/screens/(main)/channels/[username]/posts/[id]/organisms/post-view';
|
||||
|
||||
import { i18n } from '../../../../../../../../i18n';
|
||||
import type { PostTemplateProps } from './types';
|
||||
|
||||
/**
|
||||
* The post on mobile, pushed from خانه or the channel: the creator with subscribe and follow,
|
||||
* then the post in full. The action area loads in the browser.
|
||||
*/
|
||||
export function PostTemplate({
|
||||
channel,
|
||||
post,
|
||||
channelUrl,
|
||||
now,
|
||||
}: PostTemplateProps) {
|
||||
const t = i18n.getFixedT(null, 'channel');
|
||||
|
||||
return (
|
||||
<>
|
||||
<MobileTopBar
|
||||
title={t('top-bar.post')}
|
||||
previewTitle={i18n.t('content:preview.title')}
|
||||
/>
|
||||
<FlexBox tag="main" direction="flex-col" className="flex-1">
|
||||
{channel.suspended ? (
|
||||
<ChannelUnavailable context="post" />
|
||||
) : post ? (
|
||||
<>
|
||||
<PostChannelBar
|
||||
channel={channel}
|
||||
layout="mobile"
|
||||
verifiedLabel={t('header.verified')}
|
||||
actions={
|
||||
<PartBoundary name="post-channel-actions">
|
||||
<ChannelActions
|
||||
creatorId={channel.creatorId}
|
||||
username={channel.username}
|
||||
channelUrl={channelUrl}
|
||||
layout="mobile"
|
||||
/>
|
||||
</PartBoundary>
|
||||
}
|
||||
/>
|
||||
<FlexBox direction="flex-col" className="p-4">
|
||||
<PostView
|
||||
post={post}
|
||||
username={channel.username}
|
||||
avatarUrl={channel.avatarUrl}
|
||||
now={now}
|
||||
layout="mobile"
|
||||
/>
|
||||
</FlexBox>
|
||||
</>
|
||||
) : (
|
||||
<FlexBox direction="flex-col" className="flex-1 bg-surface px-4">
|
||||
<PostMissing username={channel.username} />
|
||||
</FlexBox>
|
||||
)}
|
||||
</FlexBox>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { PostTemplate } from './PostTemplate';
|
||||
export type { PostTemplateProps } from './types';
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import type { PublicCreatorPayload } from '@lumina/market/features/channel';
|
||||
import type { PostPayload } from '@lumina/market/features/post';
|
||||
|
||||
export type PostTemplateProps = {
|
||||
channel: PublicCreatorPayload;
|
||||
/** `null`: deleted, unknown, or another channel's. */
|
||||
post: PostPayload | null;
|
||||
/** «lumina.ir/@sara_gold», for the guest's login prompt. */
|
||||
channelUrl: string;
|
||||
/** The render's time: the post's time counts from it. */
|
||||
now: string;
|
||||
};
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { PartBoundary } from '@lumina/market/app/error-boundaries';
|
||||
import { MobileTopBar } from '@lumina/market/app/navigation';
|
||||
import { ChannelActions } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-actions';
|
||||
import { ChannelFeed } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-feed/server';
|
||||
import {
|
||||
ChannelHeader,
|
||||
channelHeaderLabels,
|
||||
} from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-header';
|
||||
import { ChannelShare } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-share';
|
||||
import { ChannelStats } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-stats/server';
|
||||
import { ChannelUnavailable } from '@lumina/market/app/screens/(main)/channels/[username]/organisms/channel-unavailable';
|
||||
import { creatorStatsLabels } from '@lumina/market/shared/labels';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../../../../i18n';
|
||||
import type { ChannelTemplateProps } from './types';
|
||||
|
||||
/**
|
||||
* The channel on mobile: a page pushed from خانه (the creator's own کانال tab). The header renders
|
||||
* at once; the track record and the feed stream in reading order, each in its own boundary, and
|
||||
* the action area loads in the browser.
|
||||
*/
|
||||
export function ChannelTemplate({
|
||||
channel,
|
||||
channelUrl,
|
||||
now,
|
||||
}: ChannelTemplateProps) {
|
||||
const t = i18n.getFixedT(null, 'channel');
|
||||
|
||||
// Suspension outranks everything: no header, posts or actions, for anyone (U6 ۱.۳). Its creator
|
||||
// sees their suspended tab under their tab bar (C6 ۱.۳); the browser decides. The main is flush
|
||||
// for that tab's banner strip and header; the message keeps its own inset.
|
||||
if (channel.suspended) {
|
||||
return (
|
||||
<>
|
||||
<MobileTopBar
|
||||
title={t('top-bar.channel')}
|
||||
tabOwnerId={channel.creatorId}
|
||||
/>
|
||||
<FlexBox tag="main" direction="flex-col" className="flex-1">
|
||||
<ChannelUnavailable
|
||||
context="channel"
|
||||
channel={channel}
|
||||
channelUrl={channelUrl}
|
||||
layout="mobile"
|
||||
/>
|
||||
</FlexBox>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<MobileTopBar
|
||||
title={t('top-bar.channel')}
|
||||
tabOwnerId={channel.creatorId}
|
||||
/>
|
||||
<FlexBox tag="main" direction="flex-col" className="flex-1">
|
||||
<ChannelHeader
|
||||
channel={channel}
|
||||
channelUrl={channelUrl}
|
||||
layout="mobile"
|
||||
share={
|
||||
<ChannelShare
|
||||
creatorId={channel.creatorId}
|
||||
username={channel.username}
|
||||
channelUrl={channelUrl}
|
||||
layout="mobile"
|
||||
/>
|
||||
}
|
||||
stats={
|
||||
<PartBoundary
|
||||
name="channel-stats"
|
||||
title={t('stats.error-title')}
|
||||
description={t('stats.error-description')}
|
||||
framed
|
||||
>
|
||||
<Suspense
|
||||
fallback={
|
||||
<SkeletonPreset preset="stats" label={t('stats.loading')} />
|
||||
}
|
||||
>
|
||||
<ChannelStats
|
||||
creatorId={channel.creatorId}
|
||||
labels={creatorStatsLabels(i18n.getFixedT(null, 'content'))}
|
||||
/>
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
}
|
||||
actions={
|
||||
<PartBoundary name="channel-actions">
|
||||
<ChannelActions
|
||||
creatorId={channel.creatorId}
|
||||
username={channel.username}
|
||||
channelUrl={channelUrl}
|
||||
layout="mobile"
|
||||
/>
|
||||
</PartBoundary>
|
||||
}
|
||||
labels={channelHeaderLabels(t, i18n.getFixedT(null, 'common'))}
|
||||
/>
|
||||
<FlexBox direction="flex-col" className="p-4">
|
||||
<PartBoundary name="channel-feed">
|
||||
<Suspense
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="post"
|
||||
count={2}
|
||||
label={t('feed.loading')}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<ChannelFeed channel={channel} now={now} layout="mobile" />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { ChannelTemplate } from './ChannelTemplate';
|
||||
export type { ChannelTemplateProps } from './types';
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import type { PublicCreatorPayload } from '@lumina/market/features/channel';
|
||||
|
||||
export type ChannelTemplateProps = {
|
||||
channel: PublicCreatorPayload;
|
||||
/** «lumina.ir/@sara_gold». */
|
||||
channelUrl: string;
|
||||
/** The render's time: the posts' relative times count from it. */
|
||||
now: string;
|
||||
};
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
|
||||
/** The list before it arrives, row for row; the layout keeps the bar and the tabs. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<SkeletonPreset
|
||||
preset="list"
|
||||
cards="md"
|
||||
delayed
|
||||
label={i18n.t('dashboard:following.loading')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { PartBoundary } from '@lumina/market/app/error-boundaries';
|
||||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import { FollowingList } from '@lumina/market/app/screens/(main)/dashboard/following/organisms/following-list';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
title: i18n.t('dashboard:following.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* داشبورد › دنبالشدهها (U8 §۴): the investor's own list, in the browser only, behind rows of the
|
||||
* same size. A failed read shows in place of the list; the bar and the tabs stay (U8 ۴.۵).
|
||||
*/
|
||||
export default function FollowingPage() {
|
||||
const skeleton = (
|
||||
<SkeletonPreset
|
||||
preset="list"
|
||||
cards="md"
|
||||
label={i18n.t('dashboard:following.loading')}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<PartBoundary
|
||||
name="following-list"
|
||||
description={i18n.t('dashboard:following.error')}
|
||||
framed
|
||||
>
|
||||
<AuthGuard role="investor" fallback={skeleton}>
|
||||
<Suspense fallback={skeleton}>
|
||||
<FollowingList layout="mobile" />
|
||||
</Suspense>
|
||||
</AuthGuard>
|
||||
</PartBoundary>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { MobileTopBar } from '@lumina/market/app/navigation';
|
||||
import { DashboardTabs } from '@lumina/market/app/screens/(main)/dashboard/organisms/dashboard-tabs';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
/**
|
||||
* The investor's داشبورد on mobile (U8 ۴.۱; U2): the tab bar «داشبورد», the section row
|
||||
* «اشتراکها» · «تراکنشها» · «دنبالشدهها», then the section. Each section is its own route with
|
||||
* its own loading, so the bar and the row stay while one loads.
|
||||
*/
|
||||
export default function InvestorDashboardLayout({
|
||||
children,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<MobileTopBar isTab title={i18n.t('common:nav.dashboard')} />
|
||||
<DashboardTabs layout="mobile" />
|
||||
<FlexBox tag="main" direction="flex-col" className="flex-1 p-4">
|
||||
{children}
|
||||
</FlexBox>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { BottomNav } from '@lumina/market/app/navigation';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
/** The main pages on mobile: each page brings its top bar; the bottom nav is shared. */
|
||||
export default function MainLayout({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<FlexBox direction="flex-col" className="min-h-dvh bg-bg-page">
|
||||
{children}
|
||||
<BottomNav />
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
export { getQueryClient } from './react-query';
|
||||
export { rootMetadata } from './seo';
|
||||
export { displayUrl } from './site';
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
import { clientEnv } from '../env';
|
||||
|
||||
/** A path on this site as people read and type it, without the scheme: «lumina.ir/@sara_gold». */
|
||||
export function displayUrl(path: string): string {
|
||||
return `${new URL(clientEnv.NEXT_PUBLIC_SITE_URL).host}${path}`;
|
||||
}
|
||||
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
import { Toaster } from '@lumina/island/molecules/toast';
|
||||
import { QueryClientProvider } from '@tanstack/react-query';
|
||||
import { useEffect } from 'react';
|
||||
import { I18nextProvider } from 'react-i18next';
|
||||
|
||||
import { usePostDraftStore } from '../../stores/post-draft';
|
||||
import { NetworkBoundary } from './components/NetworkBoundary';
|
||||
import { useSession } from './hooks/use-session';
|
||||
import type { AppShellProps } from './types';
|
||||
|
|
@ -15,6 +17,10 @@ import type { AppShellProps } from './types';
|
|||
*/
|
||||
export function AppShell({ queryClient, i18n, children }: AppShellProps) {
|
||||
useSession(queryClient);
|
||||
// Persisted stores wait for the first browser render, so it matches the server's.
|
||||
useEffect(() => {
|
||||
void usePostDraftStore.persist.rehydrate();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
import { handleError } from '@lumina/libs/error-handler';
|
||||
import { eventEmitter } from '@lumina/libs/event-emitter';
|
||||
import { storage } from '@lumina/libs/local-storage';
|
||||
import type { QueryClient } from '@tanstack/react-query';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { AUTH_EVENTS, restoreSession } from '../../../features/auth';
|
||||
import { useAuthStore } from '../../../stores/auth';
|
||||
import { usePostDraftStore } from '../../../stores/post-draft';
|
||||
|
||||
/**
|
||||
* The browser learns who the viewer is once per page load; auth-dependent parts wait in their
|
||||
* skeleton until then. A read that failed offline or on a gateway error leaves the viewer unknown,
|
||||
* so it runs again when the connection comes back. When the session ends (sign-out, or a refresh
|
||||
* that failed), the store goes back to guest and every cached query is dropped: it belonged to the
|
||||
* old account.
|
||||
* old account, and so is what it kept on the device (`session.` keys).
|
||||
*/
|
||||
export function useSession(queryClient: QueryClient): void {
|
||||
useEffect(() => {
|
||||
|
|
@ -27,6 +29,10 @@ export function useSession(queryClient: QueryClient): void {
|
|||
const offLogout = eventEmitter.on(AUTH_EVENTS.logout, () => {
|
||||
useAuthStore.getState().clearSession();
|
||||
queryClient.clear();
|
||||
// The account's own drafts and choices stay with it, not with the device. The stores go
|
||||
// first: a persisted store writes its key again on every change.
|
||||
usePostDraftStore.getState().clearDraft();
|
||||
storage.clearByPrefix('session.');
|
||||
});
|
||||
return () => {
|
||||
window.removeEventListener('online', restoreIfUnknown);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
'use client';
|
||||
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
import { ErrorState } from '@lumina/island/molecules/error-state';
|
||||
import {
|
||||
classifyError,
|
||||
|
|
@ -7,6 +8,7 @@ import {
|
|||
handleError,
|
||||
} from '@lumina/libs/error-handler';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { StatusEmptyState } from '../status-empty-state';
|
||||
|
|
@ -17,13 +19,17 @@ import { errorKind } from './utils';
|
|||
* What every boundary renders. A silent error (aborted, or a 401 already redirecting) shows
|
||||
* nothing; a 404 or 403 read shows its empty state; anything else shows ErrorState with Try again
|
||||
* for a network cause or Reload page for a bug, and the reference ID. It reports the error once,
|
||||
* and a page or app fallback moves focus to its heading.
|
||||
* and a page or app fallback moves focus to its heading. A framed part sits in a Card, as the
|
||||
* boards draw a section's error (S3-03, U8 ۴.۵).
|
||||
*/
|
||||
export function ErrorFallback({
|
||||
error,
|
||||
size,
|
||||
name,
|
||||
onRetry,
|
||||
title,
|
||||
description,
|
||||
framed = false,
|
||||
}: ErrorFallbackProps) {
|
||||
const { t } = useTranslation('errors');
|
||||
const headingRef = useRef<HTMLHeadingElement>(null);
|
||||
|
|
@ -35,13 +41,14 @@ export function ErrorFallback({
|
|||
}, [error, size, name]);
|
||||
|
||||
if (read === 'silent') return null;
|
||||
const frame = (state: ReactNode) => (framed ? <Card>{state}</Card> : state);
|
||||
if (read !== 'boundary') {
|
||||
return (
|
||||
return frame(
|
||||
<StatusEmptyState
|
||||
variant={read}
|
||||
size={size === 'part' ? 'part' : 'page'}
|
||||
headingRef={headingRef}
|
||||
/>
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -49,19 +56,21 @@ export function ErrorFallback({
|
|||
// Only the reference ID is read here, so no copy goes through a translator.
|
||||
const { referenceId } = describeError(error, (key) => key);
|
||||
const isBug = cause === 'logic';
|
||||
// Offline keeps its own copy: it says the page updates by itself once the device is back.
|
||||
const ownDescription = kind === 'offline' ? undefined : description;
|
||||
|
||||
return (
|
||||
return frame(
|
||||
<ErrorState
|
||||
kind={kind}
|
||||
size={size === 'part' ? 'section' : 'page'}
|
||||
headingRef={headingRef}
|
||||
title={t(`fallback.${kind}.title`)}
|
||||
description={t(`fallback.${kind}.description`)}
|
||||
title={title ?? t(`fallback.${kind}.title`)}
|
||||
description={ownDescription ?? t(`fallback.${kind}.description`)}
|
||||
// A bug won't go away on retry: reload the page instead.
|
||||
onRetry={isBug ? () => window.location.reload() : onRetry}
|
||||
retryLabel={isBug ? t('fallback.reload') : t('fallback.retry')}
|
||||
digest={referenceId}
|
||||
digestLabel={t('fallback.reference')}
|
||||
/>
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,4 +16,12 @@ export type ErrorFallbackProps = {
|
|||
name?: string;
|
||||
/** Try again: resets the failed queries, then the boundary. */
|
||||
onRetry?: () => void;
|
||||
/**
|
||||
* A part's own copy for a failure it can be retried from; empty states keep theirs, and offline
|
||||
* keeps its description.
|
||||
*/
|
||||
title?: string;
|
||||
description?: string;
|
||||
/** Sits in a Card, where the board draws the part's error as a card (S3-03, U8 ۴.۵). */
|
||||
framed?: boolean;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { ErrorFallback } from '../error-fallback';
|
|||
import type { PartBoundaryProps } from './types';
|
||||
|
||||
function PartFallback(
|
||||
{ name }: PartBoundaryProps,
|
||||
{ name, title, description, framed }: PartBoundaryProps,
|
||||
{ error, retry, reset }: ErrorInfo,
|
||||
) {
|
||||
const queryErrors = useQueryErrorResetBoundary();
|
||||
|
|
@ -21,6 +21,9 @@ function PartFallback(
|
|||
error={error}
|
||||
size="part"
|
||||
name={name}
|
||||
title={title}
|
||||
description={description}
|
||||
framed={framed}
|
||||
onRetry={() => {
|
||||
queryErrors.reset();
|
||||
if (isServerError) retry();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,12 @@
|
|||
export type PartBoundaryProps = {
|
||||
/** The part, for the error report: «creator-stats», «feed». Never personal data. */
|
||||
name: string;
|
||||
/**
|
||||
* The part's own failure copy, such as «عملکرد پیشبینیها بارگذاری نشد» / «بقیه کانال در دسترس
|
||||
* است…» (S3); without it the fallback says what every part says.
|
||||
*/
|
||||
title?: string;
|
||||
description?: string;
|
||||
/** The fallback sits in a Card, where the board draws the part's error as a card (S3-03). */
|
||||
framed?: boolean;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
import {
|
||||
CHANNEL_PREFIX,
|
||||
CHANNEL_ROUTE_PREFIX,
|
||||
DASHBOARD_PATH,
|
||||
} from './constants';
|
||||
import type { NavTabName } from './types';
|
||||
|
||||
/**
|
||||
* The creator's own channel or a page under it, by its public path or the route it is rewritten
|
||||
* onto, depending on who reads it.
|
||||
*/
|
||||
export function isOwnChannelPath(
|
||||
pathname: string,
|
||||
ownUsername: string,
|
||||
): boolean {
|
||||
return [CHANNEL_PREFIX, CHANNEL_ROUTE_PREFIX].some((prefix) => {
|
||||
const channel = `${prefix}${ownUsername}`;
|
||||
return pathname === channel || pathname.startsWith(`${channel}/`);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The tab a page belongs to: the one it was pushed from. داشبورد for its own pages, کانال for the
|
||||
* creator's own channel and its posts, and خانه for everything else (a channel, a post).
|
||||
*/
|
||||
export function activeTab(
|
||||
pathname: string,
|
||||
ownUsername: string | null,
|
||||
): NavTabName {
|
||||
if (pathname.startsWith(DASHBOARD_PATH)) return 'dashboard';
|
||||
if (ownUsername && isOwnChannelPath(pathname, ownUsername)) return 'channel';
|
||||
return 'home';
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
'use client';
|
||||
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useCurrentAccount, useViewerStatus } from '../../../../stores/auth';
|
||||
import { activeTab } from '../../active-tab';
|
||||
import { useIsOwnPreview } from '../../hooks/use-is-own-preview';
|
||||
import { ROUTES } from '../../navigation';
|
||||
import { PublishMenu } from '../publish-menu';
|
||||
import { NavTab } from './components/NavTab';
|
||||
|
||||
/**
|
||||
* The mobile bottom nav of a signed-in person, on tab screens and the pages pushed from them, with
|
||||
* the tab they came from active. An investor: خانه · داشبورد. A creator: کانال · «انتشار» ·
|
||||
* داشبورد. A guest gets none; until the viewer is known nothing renders, and the bar is fixed, so
|
||||
* the page doesn't move when it appears.
|
||||
*/
|
||||
export function BottomNav() {
|
||||
const { t } = useTranslation();
|
||||
const status = useViewerStatus();
|
||||
const account = useCurrentAccount();
|
||||
const pathname = usePathname();
|
||||
const isPreview = useIsOwnPreview();
|
||||
|
||||
if (status !== 'member' || !account || isPreview) return null;
|
||||
const isCreator = account.role === 'creator';
|
||||
const active = activeTab(pathname, isCreator ? account.username : null);
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Keeps the page's end clear of the fixed bar. */}
|
||||
<Element aria-hidden className="h-16 flex-none" />
|
||||
<FlexBox
|
||||
tag="nav"
|
||||
aria-label={t('nav.label')}
|
||||
alignItems="items-stretch"
|
||||
className="fixed inset-x-0 bottom-0 z-sticky h-16 border-t border-border-subtle bg-surface"
|
||||
>
|
||||
{isCreator ? (
|
||||
<NavTab
|
||||
href={ROUTES.channel(account.username)}
|
||||
icon="channel"
|
||||
label={t('nav.channel')}
|
||||
isActive={active === 'channel'}
|
||||
/>
|
||||
) : (
|
||||
<NavTab
|
||||
href={ROUTES.home}
|
||||
icon="home"
|
||||
label={t('nav.home')}
|
||||
isActive={active === 'home'}
|
||||
/>
|
||||
)}
|
||||
{isCreator && (
|
||||
<FlexBox alignItems="items-center" className="flex-none px-2">
|
||||
<PublishMenu placement="nav" />
|
||||
</FlexBox>
|
||||
)}
|
||||
<NavTab
|
||||
href={
|
||||
isCreator
|
||||
? ROUTES.dashboard.pricing
|
||||
: ROUTES.dashboard.subscriptions
|
||||
}
|
||||
icon="dashboard"
|
||||
label={t('nav.dashboard')}
|
||||
isActive={active === 'dashboard'}
|
||||
/>
|
||||
</FlexBox>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Icon } from '@lumina/island/atoms/icon';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { cn } from '@lumina/island/tools/cn';
|
||||
import NextLink from 'next/link';
|
||||
|
||||
import type { NavTabProps } from '../types';
|
||||
|
||||
/** One tab: its icon over its name, the active one in the brand colour. */
|
||||
export function NavTab({ href, icon, label, isActive }: NavTabProps) {
|
||||
return (
|
||||
<FlexBox
|
||||
tag={NextLink}
|
||||
href={href}
|
||||
direction="flex-col"
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-center"
|
||||
aria-current={isActive ? 'page' : undefined}
|
||||
className={cn(
|
||||
'min-w-touch-target flex-1 no-underline focus-visible:focus-ring',
|
||||
isActive ? 'text-action-primary-text' : 'text-text-secondary',
|
||||
)}
|
||||
>
|
||||
<Icon name={icon} size={24} />
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="micro"
|
||||
color="inherit"
|
||||
className="font-semibold"
|
||||
>
|
||||
{label}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
export { BottomNav } from './BottomNav';
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import type { IconName } from '@lumina/island/atoms/icon';
|
||||
|
||||
export type NavTabProps = {
|
||||
href: string;
|
||||
icon: IconName;
|
||||
label: string;
|
||||
isActive: boolean;
|
||||
};
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
'use client';
|
||||
|
||||
import { Avatar } from '@lumina/island/atoms/avatar';
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { Skeleton } from '@lumina/island/atoms/skeleton';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import NextLink from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useCurrentAccount, useViewerStatus } from '../../../../stores/auth';
|
||||
import { SupportEntry } from '../../../screens/organisms/support-entry';
|
||||
import { activeTab } from '../../active-tab';
|
||||
import { loginRoute, ROUTES } from '../../navigation';
|
||||
import { PublishMenu } from '../publish-menu';
|
||||
import { HeaderNavLink } from './components/HeaderNavLink';
|
||||
|
||||
/**
|
||||
* The desktop header on every main page: the brand, the nav, then support and the account at the
|
||||
* end. An investor's nav is خانه · داشبورد; a creator's is کانال · داشبورد, with «انتشار» before
|
||||
* support. A guest sees only the brand, support and «ورود/ثبتنام», which returns here. The brand
|
||||
* goes home, or to a creator's own channel. Who is looking is known only in the browser; until then
|
||||
* the account's place is a skeleton.
|
||||
*/
|
||||
export function DesktopHeader() {
|
||||
const { t } = useTranslation();
|
||||
const status = useViewerStatus();
|
||||
const account = useCurrentAccount();
|
||||
const pathname = usePathname();
|
||||
const isCreator = account?.role === 'creator';
|
||||
const active = activeTab(pathname, isCreator ? account.username : null);
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
tag="header"
|
||||
alignItems="items-center"
|
||||
gap="gap-8"
|
||||
className="sticky top-0 z-sticky min-h-16 border-b border-border-subtle bg-surface ps-8 pe-6"
|
||||
>
|
||||
<Typography
|
||||
tag={NextLink}
|
||||
// A creator's home tab is their channel; going there directly leaves no `/` to bounce off.
|
||||
href={isCreator ? ROUTES.channel(account.username) : ROUTES.home}
|
||||
aria-label={t('nav.brand-home')}
|
||||
variant="heading-sm"
|
||||
color="brand"
|
||||
className="rounded-xs no-underline focus-visible:focus-ring"
|
||||
>
|
||||
{t('nav.brand')}
|
||||
</Typography>
|
||||
{status === 'member' && account && (
|
||||
<FlexBox
|
||||
tag="nav"
|
||||
aria-label={t('nav.label')}
|
||||
alignItems="items-center"
|
||||
gap="gap-1"
|
||||
>
|
||||
{isCreator ? (
|
||||
<HeaderNavLink
|
||||
href={ROUTES.channel(account.username)}
|
||||
label={t('nav.channel')}
|
||||
isActive={active === 'channel'}
|
||||
/>
|
||||
) : (
|
||||
<HeaderNavLink
|
||||
href={ROUTES.home}
|
||||
label={t('nav.home')}
|
||||
isActive={active === 'home'}
|
||||
/>
|
||||
)}
|
||||
<HeaderNavLink
|
||||
href={
|
||||
isCreator
|
||||
? ROUTES.dashboard.pricing
|
||||
: ROUTES.dashboard.subscriptions
|
||||
}
|
||||
label={t('nav.dashboard')}
|
||||
isActive={active === 'dashboard'}
|
||||
/>
|
||||
</FlexBox>
|
||||
)}
|
||||
<FlexBox alignItems="items-center" gap="gap-2" className="ms-auto">
|
||||
{isCreator && <PublishMenu placement="header" />}
|
||||
<SupportEntry trigger="icon" placement="popover" />
|
||||
{status === 'unknown' && (
|
||||
// The account link's size, so the end doesn't move when the session arrives.
|
||||
<GridBox
|
||||
justifyItems="justify-items-center"
|
||||
alignItems="items-center"
|
||||
className="size-touch-target"
|
||||
>
|
||||
<Skeleton shape="circle" width="2rem" height="2rem" />
|
||||
</GridBox>
|
||||
)}
|
||||
{status === 'guest' && (
|
||||
<Button variant="primary" href={loginRoute(pathname)}>
|
||||
{t('nav.login')}
|
||||
</Button>
|
||||
)}
|
||||
{status === 'member' && account && (
|
||||
<GridBox
|
||||
tag={NextLink}
|
||||
href={ROUTES.account}
|
||||
aria-label={t('nav.account')}
|
||||
justifyItems="justify-items-center"
|
||||
alignItems="items-center"
|
||||
className="size-touch-target rounded-full focus-visible:focus-ring"
|
||||
>
|
||||
<Avatar name={account.username} src={account.avatarUrl} size="sm" />
|
||||
</GridBox>
|
||||
)}
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { cn } from '@lumina/island/tools/cn';
|
||||
import NextLink from 'next/link';
|
||||
|
||||
import type { HeaderNavLinkProps } from '../types';
|
||||
|
||||
/** A 40px pill in the header nav; the active one on the brand's subtle fill. */
|
||||
export function HeaderNavLink({ href, label, isActive }: HeaderNavLinkProps) {
|
||||
return (
|
||||
<Typography
|
||||
tag={NextLink}
|
||||
href={href}
|
||||
color={isActive ? 'brand' : 'secondary'}
|
||||
aria-current={isActive ? 'page' : undefined}
|
||||
className={cn(
|
||||
'inline-block rounded-full px-4 py-1.5 font-semibold no-underline transition-colors duration-120 ease-standard hover:text-text-primary focus-visible:focus-ring',
|
||||
isActive && 'bg-action-primary-subtle',
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
export { DesktopHeader } from './DesktopHeader';
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
export type HeaderNavLinkProps = {
|
||||
href: string;
|
||||
label: string;
|
||||
isActive: boolean;
|
||||
};
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
'use client';
|
||||
|
||||
import { Avatar } from '@lumina/island/atoms/avatar';
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { Skeleton } from '@lumina/island/atoms/skeleton';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import NextLink from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useCurrentAccount, useViewerStatus } from '../../../../stores/auth';
|
||||
import { SupportEntry } from '../../../screens/organisms/support-entry';
|
||||
import { useIsOwnPreview } from '../../hooks/use-is-own-preview';
|
||||
import { loginRoute, ROUTES } from '../../navigation';
|
||||
import { BackButton } from './components/BackButton';
|
||||
import { Brand } from './components/Brand';
|
||||
import type { MobileTopBarProps } from './types';
|
||||
|
||||
/**
|
||||
* The mobile top bar of a page pushed from a tab: back, the page's name and support. A guest sees
|
||||
* the logged-out bar instead (the brand, support and «ورود/ثبتنام», which returns here). A tab's
|
||||
* main screen, and a creator on their own tab, get the tab bar: the brand, the tab's name centred
|
||||
* when it has one («داشبورد»; خانه has none), support and the member's account (Main A, U8 ۴.۱).
|
||||
* Who is looking is known only in the browser, so the server and the first browser render show a
|
||||
* tab's bar with its brand and name and a placeholder where the account goes, and a pushed page's
|
||||
* bar without its start. A creator's brand goes to their own channel, their home tab.
|
||||
*/
|
||||
export function MobileTopBar({
|
||||
title,
|
||||
isTab = false,
|
||||
tabOwnerId,
|
||||
onBack,
|
||||
previewTitle,
|
||||
}: MobileTopBarProps) {
|
||||
const { t } = useTranslation();
|
||||
const status = useViewerStatus();
|
||||
const account = useCurrentAccount();
|
||||
const pathname = usePathname();
|
||||
const isPreview = useIsOwnPreview();
|
||||
// While the viewer is unknown, account is null, so only a tab's main screen gets the tab bar.
|
||||
const isTabBar = isTab || (account != null && account.id === tabOwnerId);
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
tag="header"
|
||||
alignItems="items-center"
|
||||
gap="gap-1"
|
||||
className="sticky top-0 z-sticky min-h-14 border-b border-border-subtle bg-surface px-2"
|
||||
>
|
||||
{status === 'unknown' && !isTabBar && (
|
||||
<FlexBox className="flex-1 px-2">
|
||||
<Skeleton width="6rem" />
|
||||
</FlexBox>
|
||||
)}
|
||||
{(status === 'guest' || isTabBar) && (
|
||||
<Brand
|
||||
label={t('nav.brand')}
|
||||
homeLabel={t('nav.brand-home')}
|
||||
href={
|
||||
account?.role === 'creator'
|
||||
? ROUTES.channel(account.username)
|
||||
: ROUTES.home
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{status !== 'guest' && isTab && title && (
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="heading-sm"
|
||||
className="pointer-events-none absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 whitespace-nowrap"
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
)}
|
||||
{status === 'member' && !isTabBar && (
|
||||
<>
|
||||
<BackButton label={t('nav.back')} onBack={onBack} />
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="heading-sm"
|
||||
className="flex-1 truncate"
|
||||
>
|
||||
{isPreview && previewTitle ? previewTitle : title}
|
||||
</Typography>
|
||||
</>
|
||||
)}
|
||||
<SupportEntry trigger="icon" placement="bottom" />
|
||||
{status === 'guest' && (
|
||||
<Button variant="ghost" size="sm" href={loginRoute(pathname)}>
|
||||
{t('nav.login')}
|
||||
</Button>
|
||||
)}
|
||||
{status === 'unknown' && isTabBar && (
|
||||
<GridBox
|
||||
justifyItems="justify-items-center"
|
||||
alignItems="items-center"
|
||||
className="size-touch-target"
|
||||
>
|
||||
<Skeleton shape="circle" width="2rem" height="2rem" />
|
||||
</GridBox>
|
||||
)}
|
||||
{status === 'member' && isTabBar && account && (
|
||||
<GridBox
|
||||
tag={NextLink}
|
||||
href={ROUTES.account}
|
||||
aria-label={t('nav.account')}
|
||||
justifyItems="justify-items-center"
|
||||
alignItems="items-center"
|
||||
className="size-touch-target rounded-full focus-visible:focus-ring"
|
||||
>
|
||||
<Avatar name={account.username} src={account.avatarUrl} size="sm" />
|
||||
</GridBox>
|
||||
)}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import { ROUTES } from '../../../navigation';
|
||||
import type { BackButtonProps } from '../types';
|
||||
|
||||
/**
|
||||
* Back to where the person came from; a page opened on its own (a shared link) goes home. A page
|
||||
* that may lose work passes `onBack` and asks first.
|
||||
*/
|
||||
export function BackButton({ label, onBack }: BackButtonProps) {
|
||||
const router = useRouter();
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
icon="chevron-right"
|
||||
label={label}
|
||||
onClick={() => {
|
||||
if (onBack) onBack();
|
||||
else if (window.history.length > 1) router.back();
|
||||
else router.push(ROUTES.home);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import NextLink from 'next/link';
|
||||
|
||||
import { ROUTES } from '../../../navigation';
|
||||
import type { BrandProps } from '../types';
|
||||
|
||||
/** «لومینا», linking home (a creator's is their channel); it takes the bar's free space. */
|
||||
export function Brand({ label, homeLabel, href = ROUTES.home }: BrandProps) {
|
||||
return (
|
||||
<FlexBox className="flex-1 px-2">
|
||||
<Typography
|
||||
tag={NextLink}
|
||||
href={href}
|
||||
aria-label={homeLabel}
|
||||
variant="heading-sm"
|
||||
color="brand"
|
||||
className="rounded-xs no-underline focus-visible:focus-ring"
|
||||
>
|
||||
{label}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { MobileTopBar } from './MobileTopBar';
|
||||
export type { MobileTopBarProps } from './types';
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/** A page pushed from a tab: back and its name for a member. */
|
||||
type PushedBarProps = {
|
||||
/** The page's name: «کانال», «پست». */
|
||||
title: string;
|
||||
isTab?: false;
|
||||
/**
|
||||
* The creator whose tab this page is (their own channel): they see the tab bar, with the brand
|
||||
* and their account, instead of back and the title.
|
||||
*/
|
||||
tabOwnerId?: string;
|
||||
/** Back asks first (a composer with unsaved text); without it back goes back. */
|
||||
onBack?: () => void;
|
||||
/** The title while the page is in the creator's preview (`?preview`): «پیشنمایش پست». */
|
||||
previewTitle?: string;
|
||||
};
|
||||
|
||||
/** A tab's main screen (خانه, داشبورد): every member sees the tab bar. */
|
||||
type TabBarProps = {
|
||||
isTab: true;
|
||||
/** The tab's name, centred: «داشبورد». خانه has none. */
|
||||
title?: string;
|
||||
tabOwnerId?: never;
|
||||
onBack?: never;
|
||||
previewTitle?: never;
|
||||
};
|
||||
|
||||
export type MobileTopBarProps = PushedBarProps | TabBarProps;
|
||||
|
||||
export type BackButtonProps = { label: string; onBack?: () => void };
|
||||
|
||||
export type BrandProps = {
|
||||
/** «لومینا». */
|
||||
label: string;
|
||||
/** The link's accessible name: «صفحه اصلی لومینا». */
|
||||
homeLabel: string;
|
||||
/** Where it goes: home, or a signed-in creator's own channel (their home tab). */
|
||||
href?: string;
|
||||
};
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { ActionMenu } from '@lumina/island/molecules/action-menu';
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useCreatorStanding } from '../../../../features/profile';
|
||||
import { useCurrentAccount } from '../../../../stores/auth';
|
||||
import { ROUTES } from '../../navigation';
|
||||
import { BlockedPublishDialog } from './components/BlockedPublishDialog';
|
||||
import type { BlockedStanding, PublishMenuProps } from './types';
|
||||
|
||||
const isBlocked = (standing: string): standing is BlockedStanding =>
|
||||
standing === 'pending' || standing === 'rejected' || standing === 'suspended';
|
||||
|
||||
/**
|
||||
* «انتشار» (C4 ۱.۱, ۱.۲, ۷.۱): a verified creator gets the menu, «پست جدید» or «پیشبینی جدید». A
|
||||
* creator who can't publish sees it frozen, and a press explains why instead of a tooltip.
|
||||
*/
|
||||
export function PublishMenu({ placement }: PublishMenuProps) {
|
||||
const { t } = useTranslation();
|
||||
const account = useCurrentAccount();
|
||||
const standing = useCreatorStanding(account?.role === 'creator');
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [isExplaining, setIsExplaining] = useState(false);
|
||||
const blocked = isBlocked(standing) ? standing : null;
|
||||
|
||||
return (
|
||||
<FlexBox display="inline-flex" className="relative">
|
||||
<Button
|
||||
variant="primary"
|
||||
icon={isOpen ? 'close' : 'plus'}
|
||||
aria-haspopup={blocked ? 'dialog' : 'menu'}
|
||||
aria-expanded={blocked ? isExplaining : isOpen}
|
||||
frozen={blocked !== null}
|
||||
// The press explains why, in a dialog rather than a tooltip.
|
||||
pressableWhenFrozen
|
||||
onClick={() =>
|
||||
blocked ? setIsExplaining(true) : setIsOpen((open) => !open)
|
||||
}
|
||||
>
|
||||
{t('publish.menu')}
|
||||
</Button>
|
||||
<ActionMenu
|
||||
open={isOpen}
|
||||
onClose={() => setIsOpen(false)}
|
||||
label={t('publish.menu')}
|
||||
placement={placement === 'nav' ? 'above' : 'below'}
|
||||
items={[
|
||||
{ href: ROUTES.composePost, icon: 'edit', label: t('publish.post') },
|
||||
{
|
||||
href: ROUTES.composePrediction,
|
||||
icon: 'trend-up',
|
||||
label: t('publish.prediction'),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
{blocked && (
|
||||
<BlockedPublishDialog
|
||||
standing={blocked}
|
||||
open={isExplaining}
|
||||
onClose={() => setIsExplaining(false)}
|
||||
layout={placement === 'nav' ? 'mobile' : 'desktop'}
|
||||
/>
|
||||
)}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { Icon } from '@lumina/island/atoms/icon';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Modal } from '@lumina/island/molecules/modal';
|
||||
import { Sheet } from '@lumina/island/molecules/sheet';
|
||||
import { cn } from '@lumina/island/tools/cn';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { SupportEntry } from '../../../../screens/organisms/support-entry';
|
||||
import { ROUTES } from '../../../navigation';
|
||||
import { BLOCKED_ART } from '../constants';
|
||||
import type { BlockedPublishDialogProps } from '../types';
|
||||
|
||||
/**
|
||||
* Why «انتشار» can't publish (C4 ۲.۱–۲.۳), with the one way forward: the identity review's status,
|
||||
* resubmitting it, or support for a suspended account. «بستن» under it; no ✕.
|
||||
*/
|
||||
export function BlockedPublishDialog({
|
||||
standing,
|
||||
open,
|
||||
onClose,
|
||||
layout,
|
||||
}: BlockedPublishDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const size = layout === 'mobile' ? 'lg' : undefined;
|
||||
const art = BLOCKED_ART[standing];
|
||||
const icon = (
|
||||
<GridBox
|
||||
justifyItems="justify-items-center"
|
||||
alignItems="items-center"
|
||||
className={cn('size-13 rounded-lg', art.className)}
|
||||
>
|
||||
<Icon name={art.icon} size={24} />
|
||||
</GridBox>
|
||||
);
|
||||
const next =
|
||||
standing === 'suspended' ? (
|
||||
<SupportEntry
|
||||
trigger="button"
|
||||
placement={layout === 'mobile' ? 'bottom' : 'popover'}
|
||||
size={layout === 'mobile' ? 'lg' : 'md'}
|
||||
/>
|
||||
) : (
|
||||
<Button variant="primary" size={size} block href={ROUTES.account}>
|
||||
{t(`publish.${standing}.action`)}
|
||||
</Button>
|
||||
);
|
||||
const buttons = (
|
||||
<>
|
||||
{next}
|
||||
<Button variant="secondary" size={size} block onClick={onClose}>
|
||||
{t('publish.close')}
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
const body = (
|
||||
<Typography color="secondary">{t(`publish.${standing}.reason`)}</Typography>
|
||||
);
|
||||
|
||||
return layout === 'mobile' ? (
|
||||
<Sheet
|
||||
open={open}
|
||||
title={t(`publish.${standing}.title`)}
|
||||
icon={icon}
|
||||
onClose={onClose}
|
||||
footer={buttons}
|
||||
>
|
||||
{body}
|
||||
</Sheet>
|
||||
) : (
|
||||
<Modal
|
||||
open={open}
|
||||
title={t(`publish.${standing}.title`)}
|
||||
icon={icon}
|
||||
onClose={onClose}
|
||||
actions={buttons}
|
||||
>
|
||||
{body}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import type { IconName } from '@lumina/island/atoms/icon';
|
||||
|
||||
import type { BlockedStanding } from './types';
|
||||
|
||||
/** Each blocked standing's art: its icon and its tile's tone. */
|
||||
export const BLOCKED_ART: Record<
|
||||
BlockedStanding,
|
||||
{ icon: IconName; className: string }
|
||||
> = {
|
||||
pending: {
|
||||
icon: 'clock',
|
||||
className: 'bg-surface-sunken text-text-secondary',
|
||||
},
|
||||
rejected: { icon: 'alert', className: 'bg-danger-subtle text-danger-text' },
|
||||
suspended: { icon: 'lock', className: 'bg-surface-sunken text-text-primary' },
|
||||
};
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { PublishMenu } from './PublishMenu';
|
||||
export type { PublishMenuProps } from './types';
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import type { CreatorStanding } from '../../../../features/profile';
|
||||
|
||||
export type PublishMenuProps = {
|
||||
/** nav: the mobile FAB, its menu above it. header: the desktop button, its menu below. */
|
||||
placement: 'nav' | 'header';
|
||||
};
|
||||
|
||||
/** A creator who may not publish yet, or at all. */
|
||||
export type BlockedStanding = Extract<
|
||||
CreatorStanding,
|
||||
'pending' | 'rejected' | 'suspended'
|
||||
>;
|
||||
|
||||
export type BlockedPublishDialogProps = {
|
||||
standing: BlockedStanding;
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
layout: 'mobile' | 'desktop';
|
||||
};
|
||||
|
|
@ -1,5 +1,14 @@
|
|||
/** The public channel URL prefix; next.config rewrites `/@username` onto `channels/[username]`. */
|
||||
export const CHANNEL_PREFIX = '/@';
|
||||
|
||||
/** The App Router's own path for a channel, which `/@username` is rewritten onto. */
|
||||
export const CHANNEL_ROUTE_PREFIX = '/channels/';
|
||||
|
||||
/** `?preview=visitor|subscriber`: the creator's preview of their own post as others see it (C5 §6). */
|
||||
export const PREVIEW_PARAM = 'preview';
|
||||
|
||||
/** Login's query parameter naming the channel a guest wants to subscribe to. */
|
||||
export const SUBSCRIBE_PARAM = 'subscribe';
|
||||
|
||||
/** The investor's dashboard and the creator's live under one path; it marks داشبورد active. */
|
||||
export const DASHBOARD_PATH = '/dashboard';
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
import { usePathname, useSearchParams } from 'next/navigation';
|
||||
|
||||
import { useCurrentAccount } from '../../../stores/auth';
|
||||
import { isOwnChannelPath } from '../active-tab';
|
||||
import { PREVIEW_PARAM } from '../constants';
|
||||
|
||||
/**
|
||||
* The creator previewing a post of their own channel (`?preview`): a task flow, so the nav steps
|
||||
* aside and the top bar says so (R8). Anyone else opening the same link gets the usual chrome,
|
||||
* as the post page shows them no preview.
|
||||
*/
|
||||
export function useIsOwnPreview(): boolean {
|
||||
const account = useCurrentAccount();
|
||||
const pathname = usePathname();
|
||||
const hasPreview = useSearchParams().has(PREVIEW_PARAM);
|
||||
return (
|
||||
hasPreview &&
|
||||
account?.role === 'creator' &&
|
||||
isOwnChannelPath(pathname, account.username) &&
|
||||
pathname.includes('/posts/')
|
||||
);
|
||||
}
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
export { CHANNEL_PREFIX } from './constants';
|
||||
export { BottomNav } from './components/bottom-nav';
|
||||
export { DesktopHeader } from './components/desktop-header';
|
||||
export { MobileTopBar } from './components/mobile-top-bar';
|
||||
export type { MobileTopBarProps } from './components/mobile-top-bar';
|
||||
export { CHANNEL_PREFIX, PREVIEW_PARAM } from './constants';
|
||||
export { useAuthRoutes } from './hooks/use-auth-routes';
|
||||
export {
|
||||
loginRoute,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ export const ROUTES = {
|
|||
checkout: (username: string) => `/checkout/${encodeURIComponent(username)}`,
|
||||
paymentReturn: '/payment/return',
|
||||
composePost: '/compose/post',
|
||||
/** The composer on a published post of the creator's own, for its first 15 minutes. */
|
||||
editPost: (id: string) => `/compose/post/${encodeURIComponent(id)}`,
|
||||
composePrediction: '/compose/prediction',
|
||||
dashboard: {
|
||||
subscriptions: '/dashboard/subscriptions',
|
||||
|
|
|
|||
|
|
@ -17,3 +17,6 @@ export type AuthRoutes = {
|
|||
/** The channel's username when a guest came to log in from «اشتراک», else `null`. */
|
||||
subscribeTo: string | null;
|
||||
};
|
||||
|
||||
/** The bottom nav's and the desktop header's tabs; a page belongs to the one it was pushed from. */
|
||||
export type NavTabName = 'home' | 'dashboard' | 'channel';
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
'use client';
|
||||
|
||||
import { useCurrentAccount } from '../../../../../../../stores/auth';
|
||||
import { ComposerForm } from './components/ComposerForm';
|
||||
import { EditComposer } from './components/EditComposer';
|
||||
import type { PostComposerProps } from './types';
|
||||
|
||||
/**
|
||||
* The creator's post composer, new or editing, in the browser only: the page wraps it in the
|
||||
* creator-only guard, which shows the skeleton until the session is known.
|
||||
*/
|
||||
export function PostComposer({ layout, postId }: PostComposerProps) {
|
||||
const account = useCurrentAccount();
|
||||
if (!account) return null;
|
||||
|
||||
return postId ? (
|
||||
<EditComposer
|
||||
layout={layout}
|
||||
creatorId={account.id}
|
||||
username={account.username}
|
||||
postId={postId}
|
||||
/>
|
||||
) : (
|
||||
<ComposerForm
|
||||
layout={layout}
|
||||
creatorId={account.id}
|
||||
username={account.username}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue