Skip to content

Commit

Permalink
update loading state of newly published sub
Browse files Browse the repository at this point in the history
  • Loading branch information
plebeius-eth committed May 6, 2024
1 parent de5e999 commit 1bc7102
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
18 changes: 16 additions & 2 deletions src/components/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface sidebarProps {
cid?: string;
createdAt?: number;
description?: string;
isSubCreatedButNotYetPublished?: boolean;
downvoteCount?: number;
roles?: Record<string, Role>;
rules?: string[];
Expand Down Expand Up @@ -124,15 +125,28 @@ const downloadAppLink = (() => {
}
})();

const Sidebar = ({ address, cid, createdAt, description, downvoteCount = 0, roles, rules, timestamp = 0, title, updatedAt, upvoteCount = 0, settings }: sidebarProps) => {
const Sidebar = ({
address,
cid,
createdAt,
description,
downvoteCount = 0,
isSubCreatedButNotYetPublished,
roles,
rules,
timestamp = 0,
title,
updatedAt,
upvoteCount = 0,
settings,
}: sidebarProps) => {
const { t } = useTranslation();
const { allActiveUserCount, hourActiveUserCount } = useSubplebbitStats({ subplebbitAddress: address });
const isOnline = updatedAt && updatedAt > Date.now() / 1000 - 60 * 30;
const onlineNotice = t('users_online', { count: hourActiveUserCount });
const offlineNotice = updatedAt && t('posts_last_synced', { dateAgo: getFormattedTimeAgo(updatedAt) });
const onlineStatus = isOnline ? onlineNotice : offlineNotice;

const isSubCreatedButNotYetPublished = typeof createdAt === 'number' && !updatedAt;
const subCreatedButNotYetPublishedStatus = <LoadingEllipsis string='Publishing community over IPFS' />;

const location = useLocation();
Expand Down
10 changes: 6 additions & 4 deletions src/views/subplebbit/subplebbit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ const Subplebbit = () => {
const subplebbitAddress = params.subplebbitAddress;
const subplebbitAddresses = useMemo(() => [subplebbitAddress], [subplebbitAddress]) as string[];
const subplebbit = useSubplebbit({ subplebbitAddress });
const { createdAt, description, roles, rules, shortAddress, state, title, updatedAt, settings } = subplebbit || {};
const { createdAt, description, roles, rules, shortAddress, started, state, title, updatedAt, settings } = subplebbit || {};
const { feed, hasMore, loadMore } = useFeed({ subplebbitAddresses, sortType, filter: timeFilter });

const isSubCreatedButNotYetPublished = typeof createdAt === 'number' && !updatedAt;
const loadingStateString = useFeedStateString(subplebbitAddresses) || t('loading');
const loadingString = <div className={styles.stateString}>{state === 'failed' ? state : <LoadingEllipsis string={loadingStateString} />}</div>;
const isOnline = updatedAt && updatedAt > Date.now() / 1000 - 60 * 30;

let isOnline = updatedAt && updatedAt > Date.now() / 1000 - 60 * 30;
const isSubCreatedButNotYetPublished = typeof createdAt === 'number' && !updatedAt;

const { blocked } = useBlock({ address: subplebbitAddress });

Expand All @@ -44,7 +45,7 @@ const Subplebbit = () => {
} else {
footerContent = t('no_posts');
}
} else if (feed.length === 0 && isSubCreatedButNotYetPublished) {
} else if (feed.length === 0 && started && isSubCreatedButNotYetPublished) {
footerContent = t('no_posts');
} else if (hasMore) {
footerContent = loadingString;
Expand Down Expand Up @@ -78,6 +79,7 @@ const Subplebbit = () => {
address={subplebbitAddress}
createdAt={createdAt}
description={description}
isSubCreatedButNotYetPublished={started && isSubCreatedButNotYetPublished}
roles={roles}
rules={rules}
title={title}
Expand Down

0 comments on commit 1bc7102

Please sign in to comment.