mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat: use red offline icon for subplebbits that are most likely offline (ipns record fails to update)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Subplebbit } from '@plebbit/plebbit-react-hooks';
|
||||
import { getFormattedTimeAgo } from '../lib/utils/time-utils';
|
||||
|
||||
const useIsSubplebbitOffline = (subplebbit: Subplebbit) => {
|
||||
const { t } = useTranslation();
|
||||
const { updatedAt, updatingState } = subplebbit || {};
|
||||
const isProbablyOffline = !updatedAt || (updatedAt && updatedAt < Date.now() / 1000 - 60 * 60);
|
||||
const isDefinitelyOffline = updatingState === 'failed';
|
||||
const isOffline = isProbablyOffline || isDefinitelyOffline;
|
||||
|
||||
const offlineTitle = updatedAt
|
||||
? isOffline && t('posts_last_synced_info', { time: getFormattedTimeAgo(updatedAt), interpolation: { escapeValue: false } })
|
||||
: t('subplebbit_offline_info');
|
||||
|
||||
return { isOffline, isDefinitelyOffline, offlineTitle };
|
||||
};
|
||||
|
||||
export default useIsSubplebbitOffline;
|
||||
Reference in New Issue
Block a user