mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
move file
This commit is contained in:
@@ -3,7 +3,7 @@ import { useEffect } from 'react';
|
||||
import { Subplebbit } from '@plebbit/plebbit-react-hooks';
|
||||
import { getFormattedTimeAgo } from '../lib/utils/time-utils';
|
||||
import useSubplebbitOfflineStore from '../stores/use-subplebbit-offline-store';
|
||||
import useSubplebbitsLoadingStartTimestamps from './use-subplebbits-loading-start-timestamps-store';
|
||||
import useSubplebbitsLoadingStartTimestamps from '../stores/use-subplebbits-loading-start-timestamps-store';
|
||||
|
||||
const useIsSubplebbitOffline = (subplebbit: Subplebbit) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { create } from 'zustand';
|
||||
|
||||
interface SubplebbitsLoadingStartTimestampsState {
|
||||
timestamps: Record<string, number>;
|
||||
addSubplebbits: (subplebbitAddresses: string[]) => void;
|
||||
}
|
||||
|
||||
const useSubplebbitsLoadingStartTimestampsStore = create<SubplebbitsLoadingStartTimestampsState>((set, get) => ({
|
||||
timestamps: {},
|
||||
addSubplebbits: (subplebbitAddresses) => {
|
||||
const { timestamps } = get();
|
||||
const newTimestamps: Record<string, number> = {};
|
||||
subplebbitAddresses.forEach((subplebbitAddress) => {
|
||||
if (!timestamps[subplebbitAddress]) {
|
||||
newTimestamps[subplebbitAddress] = Math.round(Date.now() / 1000);
|
||||
}
|
||||
});
|
||||
if (Object.keys(newTimestamps).length) {
|
||||
set((state) => ({ timestamps: { ...state.timestamps, ...newTimestamps } }));
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
const useSubplebbitsLoadingStartTimestamps = (subplebbitAddresses?: string[]) => {
|
||||
const timestampsStore = useSubplebbitsLoadingStartTimestampsStore((state) => state.timestamps);
|
||||
const addSubplebbits = useSubplebbitsLoadingStartTimestampsStore((state) => state.addSubplebbits);
|
||||
|
||||
useEffect(() => {
|
||||
if (subplebbitAddresses) {
|
||||
addSubplebbits(subplebbitAddresses);
|
||||
}
|
||||
}, [subplebbitAddresses, addSubplebbits]);
|
||||
|
||||
const subplebbitsLoadingStartTimestamps = useMemo(() => {
|
||||
return subplebbitAddresses?.map((subplebbitAddress) => timestampsStore[subplebbitAddress]) || [];
|
||||
}, [timestampsStore, subplebbitAddresses]);
|
||||
|
||||
return subplebbitsLoadingStartTimestamps;
|
||||
};
|
||||
|
||||
export default useSubplebbitsLoadingStartTimestamps;
|
||||
Reference in New Issue
Block a user