feat: use red offline icon for subplebbits that are most likely offline (ipns record fails to update)

This commit is contained in:
Tom (plebeius.eth)
2024-07-07 20:02:58 +02:00
parent a2347769e2
commit 9f7544936e
9 changed files with 46 additions and 30 deletions
+19
View File
@@ -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;