mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
implement MultisubSubplebbit.lowUptime
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
import { useMemo } from 'react';
|
||||
|
||||
const getUniqueTags = (multisub: any) => {
|
||||
const allTags = new Set<string>();
|
||||
Object.values(multisub).forEach((sub: any) => {
|
||||
if (sub?.tags?.length) {
|
||||
sub.tags.forEach((tag: string) => allTags.add(tag));
|
||||
}
|
||||
});
|
||||
return Array.from(allTags).sort();
|
||||
};
|
||||
|
||||
export const useDefaultSubplebbitTags = (subplebbits: any) => {
|
||||
return useMemo(() => getUniqueTags(subplebbits), [subplebbits]);
|
||||
};
|
||||
@@ -13,6 +13,7 @@ export interface MultisubSubplebbit {
|
||||
tags?: string[];
|
||||
features?: string[];
|
||||
plebchanAutoSubscribe?: boolean;
|
||||
lowUptime?: boolean;
|
||||
}
|
||||
|
||||
export interface DefaultSubplebbitsState {
|
||||
@@ -51,15 +52,17 @@ export const useDefaultSubplebbits = () => {
|
||||
return res.json();
|
||||
});
|
||||
|
||||
cacheSubplebbits = multisub.subplebbits;
|
||||
const filteredSubplebbits = multisub.subplebbits.filter((sub: MultisubSubplebbit) => !sub.lowUptime);
|
||||
|
||||
cacheSubplebbits = filteredSubplebbits;
|
||||
|
||||
// Cache auto-subscribe addresses when we fetch subplebbits
|
||||
cacheAutoSubscribeAddresses = multisub.subplebbits
|
||||
cacheAutoSubscribeAddresses = filteredSubplebbits
|
||||
.filter((sub: MultisubSubplebbit) => sub.plebchanAutoSubscribe && sub.address)
|
||||
.map((sub: MultisubSubplebbit) => sub.address);
|
||||
|
||||
setState({
|
||||
subplebbits: multisub.subplebbits,
|
||||
subplebbits: filteredSubplebbits,
|
||||
loading: false,
|
||||
error: null,
|
||||
});
|
||||
@@ -78,6 +81,8 @@ export const useDefaultSubplebbits = () => {
|
||||
return cacheSubplebbits || state.subplebbits;
|
||||
};
|
||||
|
||||
export const getAutoSubscribeAddresses = () => cacheAutoSubscribeAddresses || [];
|
||||
|
||||
export const useDefaultSubplebbitsState = () => {
|
||||
const [state, setState] = useState<DefaultSubplebbitsState>({
|
||||
subplebbits: cacheSubplebbits || [],
|
||||
@@ -154,4 +159,16 @@ export const useMultisubMetadata = () => {
|
||||
return cacheMetadata || metadata;
|
||||
};
|
||||
|
||||
export const getAutoSubscribeAddresses = () => cacheAutoSubscribeAddresses || [];
|
||||
const getUniqueTags = (multisub: any) => {
|
||||
const allTags = new Set<string>();
|
||||
Object.values(multisub).forEach((sub: any) => {
|
||||
if (sub?.tags?.length) {
|
||||
sub.tags.forEach((tag: string) => allTags.add(tag));
|
||||
}
|
||||
});
|
||||
return Array.from(allTags).sort();
|
||||
};
|
||||
|
||||
export const useDefaultSubplebbitTags = (subplebbits: any) => {
|
||||
return useMemo(() => getUniqueTags(subplebbits), [subplebbits]);
|
||||
};
|
||||
|
||||
@@ -3,8 +3,7 @@ import { Link, useLocation } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import Plebbit from '@plebbit/plebbit-js/dist/browser/index.js';
|
||||
import { Subplebbit, useSubplebbit, useSubplebbitStats } from '@plebbit/plebbit-react-hooks';
|
||||
import { useDefaultSubplebbitsState } from '../../../hooks/use-default-subplebbits';
|
||||
import { useDefaultSubplebbitTags } from '../../../hooks/use-default-subplebbits-tags';
|
||||
import { useDefaultSubplebbitsState, useDefaultSubplebbitTags } from '../../../hooks/use-default-subplebbits';
|
||||
import useIsMobile from '../../../hooks/use-is-mobile';
|
||||
import useIsSubplebbitOffline from '../../../hooks/use-is-subplebbit-offline';
|
||||
import LoadingEllipsis from '../../../components/loading-ellipsis';
|
||||
|
||||
Reference in New Issue
Block a user