mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
add accurate loading states in all views
This commit is contained in:
@@ -3,7 +3,7 @@ import { Helmet } from 'react-helmet-async';
|
|||||||
import { Link, useNavigate, useParams } from 'react-router-dom';
|
import { Link, useNavigate, useParams } from 'react-router-dom';
|
||||||
import { Tooltip } from 'react-tooltip';
|
import { Tooltip } from 'react-tooltip';
|
||||||
import { Virtuoso } from 'react-virtuoso';
|
import { Virtuoso } from 'react-virtuoso';
|
||||||
import { useAccount, useAccountComments, useFeed, usePublishComment, useSubscribe } from '@plebbit/plebbit-react-hooks';
|
import { useAccount, useAccountComments, useFeed, usePublishComment, useSubplebbit, useSubscribe } from '@plebbit/plebbit-react-hooks';
|
||||||
import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils'
|
import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils'
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import useGeneralStore from '../../hooks/stores/useGeneralStore';
|
import useGeneralStore from '../../hooks/stores/useGeneralStore';
|
||||||
@@ -16,6 +16,7 @@ import PostLoader from '../PostLoader';
|
|||||||
import ReplyModal from '../ReplyModal';
|
import ReplyModal from '../ReplyModal';
|
||||||
import SettingsModal from '../SettingsModal';
|
import SettingsModal from '../SettingsModal';
|
||||||
import findShortParentCid from '../../utils/findShortParentCid';
|
import findShortParentCid from '../../utils/findShortParentCid';
|
||||||
|
import formatState from '../../utils/formatState';
|
||||||
import getCommentMediaInfo from '../../utils/getCommentMediaInfo';
|
import getCommentMediaInfo from '../../utils/getCommentMediaInfo';
|
||||||
import getDate from '../../utils/getDate';
|
import getDate from '../../utils/getDate';
|
||||||
import handleAddressClick from '../../utils/handleAddressClick';
|
import handleAddressClick from '../../utils/handleAddressClick';
|
||||||
@@ -63,6 +64,7 @@ const Board = () => {
|
|||||||
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: [`${selectedAddress}`], sortType: 'new'});
|
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: [`${selectedAddress}`], sortType: 'new'});
|
||||||
const [selectedFeed, setSelectedFeed] = useState(feed);
|
const [selectedFeed, setSelectedFeed] = useState(feed);
|
||||||
const { subplebbitAddress } = useParams();
|
const { subplebbitAddress } = useParams();
|
||||||
|
const subplebbit = useSubplebbit({subplebbitAddress: selectedAddress});
|
||||||
|
|
||||||
const { subscribed, subscribe, unsubscribe } = useSubscribe({subplebbitAddress: selectedAddress});
|
const { subscribed, subscribe, unsubscribe } = useSubscribe({subplebbitAddress: selectedAddress});
|
||||||
|
|
||||||
@@ -322,6 +324,7 @@ const Board = () => {
|
|||||||
navigate(`/p/${selected}`);
|
navigate(`/p/${selected}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleSubscribe = async () => {
|
const handleSubscribe = async () => {
|
||||||
try {
|
try {
|
||||||
if (subscribed === false) {
|
if (subscribed === false) {
|
||||||
@@ -333,6 +336,7 @@ const Board = () => {
|
|||||||
setErrorMessage(error);
|
setErrorMessage(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -505,7 +509,7 @@ const Board = () => {
|
|||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<div id="stats" style={{float: "right", marginTop: "5px"}}>
|
<div id="stats" style={{float: "right", marginTop: "5px"}}>
|
||||||
<span>Fetching IPFS...</span>
|
<span>{formatState(subplebbit.state)}</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div id="catalog-button-mobile">
|
<div id="catalog-button-mobile">
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React, { Fragment, useCallback, useEffect, useRef, useState } from 'react
|
|||||||
import { Helmet } from 'react-helmet-async';
|
import { Helmet } from 'react-helmet-async';
|
||||||
import InfiniteScroll from 'react-infinite-scroller';
|
import InfiniteScroll from 'react-infinite-scroller';
|
||||||
import { Link, useNavigate, useParams } from 'react-router-dom';
|
import { Link, useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useFeed, usePublishComment, useSubscribe } from '@plebbit/plebbit-react-hooks';
|
import { useFeed, usePublishComment, useSubplebbit, useSubscribe } from '@plebbit/plebbit-react-hooks';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import useGeneralStore from '../../hooks/stores/useGeneralStore';
|
import useGeneralStore from '../../hooks/stores/useGeneralStore';
|
||||||
import { Container, NavBar, Header, Break, PostForm, PostFormLink, PostFormTable } from '../styled/Board.styled';
|
import { Container, NavBar, Header, Break, PostForm, PostFormLink, PostFormTable } from '../styled/Board.styled';
|
||||||
@@ -12,6 +12,7 @@ import CatalogLoader from '../CatalogLoader';
|
|||||||
import ImageBanner from '../ImageBanner';
|
import ImageBanner from '../ImageBanner';
|
||||||
import OfflineIndicator from '../OfflineIndicator';
|
import OfflineIndicator from '../OfflineIndicator';
|
||||||
import SettingsModal from '../SettingsModal';
|
import SettingsModal from '../SettingsModal';
|
||||||
|
import formatState from '../../utils/formatState';
|
||||||
import getCommentMediaInfo from '../../utils/getCommentMediaInfo';
|
import getCommentMediaInfo from '../../utils/getCommentMediaInfo';
|
||||||
import handleStyleChange from '../../utils/handleStyleChange';
|
import handleStyleChange from '../../utils/handleStyleChange';
|
||||||
import useClickForm from '../../hooks/useClickForm';
|
import useClickForm from '../../hooks/useClickForm';
|
||||||
@@ -49,6 +50,7 @@ const Catalog = () => {
|
|||||||
const [visible, setVisible] = useState(true);
|
const [visible, setVisible] = useState(true);
|
||||||
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: [`${selectedAddress}`], sortType: 'new'});
|
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: [`${selectedAddress}`], sortType: 'new'});
|
||||||
const { subplebbitAddress } = useParams();
|
const { subplebbitAddress } = useParams();
|
||||||
|
const subplebbit = useSubplebbit({subplebbitAddress: selectedAddress});
|
||||||
|
|
||||||
const { subscribed, subscribe, unsubscribe } = useSubscribe({subplebbitAddress: selectedAddress});
|
const { subscribed, subscribe, unsubscribe } = useSubscribe({subplebbitAddress: selectedAddress});
|
||||||
|
|
||||||
@@ -248,6 +250,7 @@ const Catalog = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Helmet>
|
<Helmet>
|
||||||
@@ -418,7 +421,7 @@ const Catalog = () => {
|
|||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<div id="stats" style={{float: "right", marginTop: "5px"}}>
|
<div id="stats" style={{float: "right", marginTop: "5px"}}>
|
||||||
<span>Fetching IPFS...</span>
|
<span>{formatState(subplebbit.state)}</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div id="return-button-mobile">
|
<div id="return-button-mobile">
|
||||||
@@ -426,9 +429,6 @@ const Catalog = () => {
|
|||||||
<Link to={`/p/${selectedAddress}`}>Return</Link>
|
<Link to={`/p/${selectedAddress}`}>Return</Link>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="stats" style={{float: "right", marginTop: "5px"}}>
|
|
||||||
{feed.length > 0 ? (null) : (<span>Fetching IPFS...</span>)}
|
|
||||||
</div>
|
|
||||||
<hr />
|
<hr />
|
||||||
</TopBar>
|
</TopBar>
|
||||||
<Threads selectedStyle={selectedStyle}>
|
<Threads selectedStyle={selectedStyle}>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Helmet } from 'react-helmet-async';
|
import { Helmet } from 'react-helmet-async';
|
||||||
import { Link, useNavigate, useParams } from 'react-router-dom';
|
import { Link, useNavigate, useParams } from 'react-router-dom';
|
||||||
import { Tooltip } from 'react-tooltip';
|
import { Tooltip } from 'react-tooltip';
|
||||||
@@ -35,6 +35,7 @@ const Pending = () => {
|
|||||||
|
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
const comment = useAccountComment({commentIndex: index});
|
const comment = useAccountComment({commentIndex: index});
|
||||||
|
const { publishingState } = useAccountComment({commentIndex: index});
|
||||||
|
|
||||||
const [visible] = useState(true);
|
const [visible] = useState(true);
|
||||||
const [errorMessage] = useState(null);
|
const [errorMessage] = useState(null);
|
||||||
@@ -169,7 +170,7 @@ const Pending = () => {
|
|||||||
<Link to={`/p/${selectedAddress}/catalog`}>Catalog</Link>
|
<Link to={`/p/${selectedAddress}/catalog`}>Catalog</Link>
|
||||||
]
|
]
|
||||||
</span>
|
</span>
|
||||||
<span className="reply-stat">{formatState(comment.state)}</span>
|
<span className="reply-stat">{formatState(publishingState)}</span>
|
||||||
<hr />
|
<hr />
|
||||||
</TopBar>
|
</TopBar>
|
||||||
<Tooltip id="tooltip" className="tooltip" />
|
<Tooltip id="tooltip" className="tooltip" />
|
||||||
|
|||||||
@@ -152,10 +152,6 @@ const Subscriptions = () => {
|
|||||||
navigate(`/p/${selected}`);
|
navigate(`/p/${selected}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
console.log(feed);
|
|
||||||
}, [feed]);
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
+23
-14
@@ -1,18 +1,27 @@
|
|||||||
function formatState(str) {
|
function formatState(str) {
|
||||||
return (
|
if (!str) {
|
||||||
str
|
return null;
|
||||||
.replace(/-/g, " ")
|
}
|
||||||
.split(" ")
|
|
||||||
.map((word) => {
|
const formattedWords = str
|
||||||
word = word.toLowerCase();
|
.replace(/-/g, " ")
|
||||||
if (word === "ipfs" || word === "ipns") {
|
.split(" ")
|
||||||
return word.toUpperCase();
|
.map((word, index) => {
|
||||||
} else {
|
word = word.toLowerCase();
|
||||||
return word.charAt(0).toUpperCase() + word.slice(1);
|
if (word === "ipfs" || word === "ipns") {
|
||||||
}
|
return word.toUpperCase();
|
||||||
})
|
} else if (index === 0) {
|
||||||
.join(" ") + "..."
|
return word.charAt(0).toUpperCase() + word.slice(1);
|
||||||
);
|
} else {
|
||||||
|
return word;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (formattedWords.includes("Failed")) {
|
||||||
|
return formattedWords.join(" ") + ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedWords.join(" ") + "...";
|
||||||
}
|
}
|
||||||
|
|
||||||
export default formatState;
|
export default formatState;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
const isValidUrl = (url) => {
|
||||||
|
try {
|
||||||
|
new URL(url);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default isValidUrl;
|
||||||
Reference in New Issue
Block a user