chore(prettier): prettify

This commit is contained in:
plebeius.eth
2023-09-25 14:05:43 +02:00
parent eab546939d
commit 322e2f89b3
+36 -36
View File
@@ -14,48 +14,48 @@ const getClientHost = (clientUrl) => {
}; };
const useStateString = (commentOrSubplebbit) => { const useStateString = (commentOrSubplebbit) => {
const { states } = useClientsStates({ comment: commentOrSubplebbit }); const { states } = useClientsStates({ comment: commentOrSubplebbit });
return useMemo(() => { return useMemo(() => {
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.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) {
continue; continue;
} }
// separate 2 different states using ' ' // separate 2 different states using ' '
if (stateString) { if (stateString) {
stateString += ', '; stateString += ', ';
} }
// e.g. 'fetching IPFS from cloudflare-ipfs.com, ipfs.io' // e.g. 'fetching IPFS from cloudflare-ipfs.com, ipfs.io'
const formattedState = state.replaceAll('-', ' ').replace('ipfs', 'IPFS').replace('ipns', 'IPNS'); const formattedState = state.replaceAll('-', ' ').replace('ipfs', 'IPFS').replace('ipns', 'IPNS');
stateString += `${formattedState} from ${clientHosts.join(', ')}`; stateString += `${formattedState} from ${clientHosts.join(', ')}`;
} }
// fallback to comment or subplebbit state when possible // fallback to comment or subplebbit state when possible
if (!stateString && commentOrSubplebbit?.state !== 'succeeded') { if (!stateString && commentOrSubplebbit?.state !== 'succeeded') {
if (commentOrSubplebbit?.publishingState && commentOrSubplebbit?.publishingState !== 'stopped' && commentOrSubplebbit?.publishingState !== 'succeeded') { if (commentOrSubplebbit?.publishingState && commentOrSubplebbit?.publishingState !== 'stopped' && commentOrSubplebbit?.publishingState !== 'succeeded') {
stateString = commentOrSubplebbit.publishingState; stateString = commentOrSubplebbit.publishingState;
} else if (commentOrSubplebbit?.updatingState !== 'stopped' && commentOrSubplebbit?.updatingState !== 'succeeded') { } else if (commentOrSubplebbit?.updatingState !== 'stopped' && commentOrSubplebbit?.updatingState !== 'succeeded') {
stateString = commentOrSubplebbit.updatingState; stateString = commentOrSubplebbit.updatingState;
} }
if (stateString) { if (stateString) {
stateString = stateString.replaceAll('-', ' ').replace('ipfs', 'IPFS').replace('ipns', 'IPNS'); 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);
} }
// if string is empty, return undefined instead // if string is empty, return undefined instead
return stateString === '' ? undefined : stateString; return stateString === '' ? undefined : stateString;
}, [states, commentOrSubplebbit]); }, [states, commentOrSubplebbit]);
}; };
export default useStateString; export default useStateString;