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[];
|
tags?: string[];
|
||||||
features?: string[];
|
features?: string[];
|
||||||
plebchanAutoSubscribe?: boolean;
|
plebchanAutoSubscribe?: boolean;
|
||||||
|
lowUptime?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DefaultSubplebbitsState {
|
export interface DefaultSubplebbitsState {
|
||||||
@@ -51,15 +52,17 @@ export const useDefaultSubplebbits = () => {
|
|||||||
return res.json();
|
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
|
// Cache auto-subscribe addresses when we fetch subplebbits
|
||||||
cacheAutoSubscribeAddresses = multisub.subplebbits
|
cacheAutoSubscribeAddresses = filteredSubplebbits
|
||||||
.filter((sub: MultisubSubplebbit) => sub.plebchanAutoSubscribe && sub.address)
|
.filter((sub: MultisubSubplebbit) => sub.plebchanAutoSubscribe && sub.address)
|
||||||
.map((sub: MultisubSubplebbit) => sub.address);
|
.map((sub: MultisubSubplebbit) => sub.address);
|
||||||
|
|
||||||
setState({
|
setState({
|
||||||
subplebbits: multisub.subplebbits,
|
subplebbits: filteredSubplebbits,
|
||||||
loading: false,
|
loading: false,
|
||||||
error: null,
|
error: null,
|
||||||
});
|
});
|
||||||
@@ -78,6 +81,8 @@ export const useDefaultSubplebbits = () => {
|
|||||||
return cacheSubplebbits || state.subplebbits;
|
return cacheSubplebbits || state.subplebbits;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getAutoSubscribeAddresses = () => cacheAutoSubscribeAddresses || [];
|
||||||
|
|
||||||
export const useDefaultSubplebbitsState = () => {
|
export const useDefaultSubplebbitsState = () => {
|
||||||
const [state, setState] = useState<DefaultSubplebbitsState>({
|
const [state, setState] = useState<DefaultSubplebbitsState>({
|
||||||
subplebbits: cacheSubplebbits || [],
|
subplebbits: cacheSubplebbits || [],
|
||||||
@@ -154,4 +159,16 @@ export const useMultisubMetadata = () => {
|
|||||||
return cacheMetadata || metadata;
|
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 { useTranslation } from 'react-i18next';
|
||||||
import Plebbit from '@plebbit/plebbit-js/dist/browser/index.js';
|
import Plebbit from '@plebbit/plebbit-js/dist/browser/index.js';
|
||||||
import { Subplebbit, useSubplebbit, useSubplebbitStats } from '@plebbit/plebbit-react-hooks';
|
import { Subplebbit, useSubplebbit, useSubplebbitStats } from '@plebbit/plebbit-react-hooks';
|
||||||
import { useDefaultSubplebbitsState } from '../../../hooks/use-default-subplebbits';
|
import { useDefaultSubplebbitsState, useDefaultSubplebbitTags } from '../../../hooks/use-default-subplebbits';
|
||||||
import { useDefaultSubplebbitTags } from '../../../hooks/use-default-subplebbits-tags';
|
|
||||||
import useIsMobile from '../../../hooks/use-is-mobile';
|
import useIsMobile from '../../../hooks/use-is-mobile';
|
||||||
import useIsSubplebbitOffline from '../../../hooks/use-is-subplebbit-offline';
|
import useIsSubplebbitOffline from '../../../hooks/use-is-subplebbit-offline';
|
||||||
import LoadingEllipsis from '../../../components/loading-ellipsis';
|
import LoadingEllipsis from '../../../components/loading-ellipsis';
|
||||||
|
|||||||
Reference in New Issue
Block a user