Skip to content

Commit

Permalink
add loading indicator and error message for awesome swarm component
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahMaizels committed Nov 7, 2024
1 parent 2a89a62 commit ecf3691
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/components/AwesomeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,36 @@ import Markdown from 'react-markdown';

const AwesomeList = () => {
const [content, setContent] = useState('');
const [loading, setLoading] = useState(true);
const [error, setError] = useState(false);

useEffect(() => {
fetch('https://raw.githubusercontent.com/ethersphere/awesome-swarm/refs/heads/master/README.md')
.then((res) => res.text())
.then((text) => setContent(text));
.then((res) => {
if (!res.ok) {
throw new Error('Network response was not ok');
}
return res.text();
})
.then((text) => {
setContent(text);
setLoading(false);
})
.catch((err) => {
console.error('Error fetching Awesome Swarm list:', err);
setError(true);
setLoading(false);
});
}, []);

if (loading) {
return <p>Loading Awesome Swarm list...</p>;
}

if (error) {
return <p>Failed to retrieve Awesome Swarm list contents</p>;
}

return <Markdown>{content}</Markdown>;
};

Expand Down

0 comments on commit ecf3691

Please sign in to comment.