mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
@@ -66,7 +66,7 @@ const Board = () => {
|
|||||||
const { subplebbitAddress } = useParams();
|
const { subplebbitAddress } = useParams();
|
||||||
const subplebbit = useSubplebbit({subplebbitAddress: selectedAddress});
|
const subplebbit = useSubplebbit({subplebbitAddress: selectedAddress});
|
||||||
|
|
||||||
const stateString = useStateString(subplebbit?.clients);
|
const stateString = useStateString(subplebbit);
|
||||||
|
|
||||||
const { subscribed, subscribe, unsubscribe } = useSubscribe({subplebbitAddress: selectedAddress});
|
const { subscribed, subscribe, unsubscribe } = useSubscribe({subplebbitAddress: selectedAddress});
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ const Catalog = () => {
|
|||||||
const { subplebbitAddress } = useParams();
|
const { subplebbitAddress } = useParams();
|
||||||
const subplebbit = useSubplebbit({subplebbitAddress: selectedAddress});
|
const subplebbit = useSubplebbit({subplebbitAddress: selectedAddress});
|
||||||
|
|
||||||
const stateString = useStateString(subplebbit?.clients);
|
const stateString = useStateString(subplebbit);
|
||||||
|
|
||||||
const errorString = useMemo(() => {
|
const errorString = useMemo(() => {
|
||||||
if (subplebbit?.state === 'failed') {
|
if (subplebbit?.state === 'failed') {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ const Pending = () => {
|
|||||||
setSelectedAddress(comment?.subplebbitAddress);
|
setSelectedAddress(comment?.subplebbitAddress);
|
||||||
}, [comment, setSelectedAddress]);
|
}, [comment, setSelectedAddress]);
|
||||||
|
|
||||||
const stateString = useStateString(comment?.clients)
|
const stateString = useStateString(comment)
|
||||||
|
|
||||||
const errorString = useMemo(() => {
|
const errorString = useMemo(() => {
|
||||||
if (comment?.state === 'failed') {
|
if (comment?.state === 'failed') {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ const Thread = () => {
|
|||||||
const subplebbit = useSubplebbit({subplebbitAddress: comment.subplebbitAddress});
|
const subplebbit = useSubplebbit({subplebbitAddress: comment.subplebbitAddress});
|
||||||
const selectedAddress = subplebbit.address;
|
const selectedAddress = subplebbit.address;
|
||||||
|
|
||||||
const stateString = useStateString(comment?.clients);
|
const stateString = useStateString(comment);
|
||||||
|
|
||||||
const commentMediaInfo = getCommentMediaInfo(comment);
|
const commentMediaInfo = getCommentMediaInfo(comment);
|
||||||
const fallbackImgUrl = "assets/filedeleted-res.gif";
|
const fallbackImgUrl = "assets/filedeleted-res.gif";
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import isValidUrl from '../utils/isValidUrl'
|
|
||||||
|
|
||||||
const useStateString = (clients) => {
|
const useStateString = (commentOrSubplebbit) => {
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
if (!clients) {
|
if (!commentOrSubplebbit?.clients) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const clients = commentOrSubplebbit?.clients
|
||||||
|
|
||||||
const states = {}
|
const states = {}
|
||||||
for (const clientType in clients) {
|
for (const clientType in clients) {
|
||||||
@@ -33,7 +33,7 @@ const useStateString = (clients) => {
|
|||||||
let stateString = ''
|
let stateString = ''
|
||||||
for (const state in states) {
|
for (const state in states) {
|
||||||
const clientUrls = states[state]
|
const clientUrls = states[state]
|
||||||
const clientHosts = clientUrls.filter(isValidUrl).map(clientUrl => getClientHost(clientUrl))
|
const clientHosts = clientUrls.map(clientUrl => getClientHost(clientUrl))
|
||||||
|
|
||||||
// if there are no valid hosts, skip this state
|
// if there are no valid hosts, skip this state
|
||||||
if (clientHosts.length === 0) {
|
if (clientHosts.length === 0) {
|
||||||
@@ -50,6 +50,19 @@ const useStateString = (clients) => {
|
|||||||
stateString += `${formattedState} from ${clientHosts.join(', ')}`
|
stateString += `${formattedState} from ${clientHosts.join(', ')}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fallback to comment or subplebbit state when possible
|
||||||
|
if (!stateString) {
|
||||||
|
if (commentOrSubplebbit?.publishingState !== 'stopped') {
|
||||||
|
stateString = commentOrSubplebbit.publishingState
|
||||||
|
}
|
||||||
|
else if (commentOrSubplebbit?.updatingState !== 'stopped') {
|
||||||
|
stateString = commentOrSubplebbit.updatingState
|
||||||
|
}
|
||||||
|
if (stateString) {
|
||||||
|
stateString = stateString.replaceAll('-', ' ').replace('ipfs', 'IPFS').replace('ipns', 'IPNS')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// capitalize first letter
|
// capitalize first letter
|
||||||
if (stateString) {
|
if (stateString) {
|
||||||
stateString = stateString.charAt(0).toUpperCase() + stateString.slice(1)
|
stateString = stateString.charAt(0).toUpperCase() + stateString.slice(1)
|
||||||
@@ -57,7 +70,7 @@ const useStateString = (clients) => {
|
|||||||
|
|
||||||
// if string is empty, return undefined instead
|
// if string is empty, return undefined instead
|
||||||
return stateString === '' ? undefined : stateString
|
return stateString === '' ? undefined : stateString
|
||||||
}, [clients])
|
}, [commentOrSubplebbit])
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useStateString
|
export default useStateString
|
||||||
Reference in New Issue
Block a user