MCPcopy
hub / github.com/jwngr/sdow / Loading

Function Loading

website/src/components/Loading.tsx:102–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100`;
101
102export const Loading: React.FC = () => {
103 const [currentFact, setCurrentFact] = useState(getRandomWikipediaFact());
104
105 useEffect(() => {
106 const interval = setInterval(() => {
107 setCurrentFact(getRandomWikipediaFact());
108 }, 7_000);
109 return () => clearInterval(interval);
110 }, []);
111
112 // Replace page titles in the current fact with a link to the corresponding Wikipedia page.
113 let skipCount = 0;
114 const factContent: React.ReactNode[] = [];
115 const tokens = currentFact.split('"');
116 tokens.forEach((token, i) => {
117 if (skipCount === 0) {
118 if (i % 2 === 0) {
119 // Regular text
120 factContent.push(<span key={i}>{token}</span>);
121 } else {
122 // Wikipedia link
123 // Single apostrophe is used for Wikipedia links which themselves have a double apostrophe
124 // in them.
125 token = token.replace(/'/g, `"`);
126 factContent.push(
127 <StyledTextLink key={i} text={token} href={getWikipediaPageUrl(token)} target="_blank" />
128 );
129 }
130 } else {
131 skipCount--;
132 }
133 });
134
135 return (
136 <Wrapper>
137 <LoadingIndicator>
138 <div />
139 <div />
140 <div />
141 <div />
142 </LoadingIndicator>
143 <FactWrapper>{factContent}</FactWrapper>
144 </Wrapper>
145 );
146};

Callers

nothing calls this directly

Calls 2

getRandomWikipediaFactFunction · 0.90
getWikipediaPageUrlFunction · 0.90

Tested by

no test coverage detected