-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor data fetching and loading logic
- Loading branch information
Showing
6 changed files
with
96 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export function fetchCollection(setRoutes: (value: {}) => void) { | ||
return new Promise(async (resolve, reject) => { | ||
const api = "https://api.mind.ch3nyang.top"; | ||
let url = `${api}/collection`; | ||
|
||
try { | ||
const response = await fetch(url, { method: 'GET' }); | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
const data: string[] = await response.json(); | ||
let routes: { [key: string]: string } = {}; | ||
data.forEach((collection) => { | ||
routes[`/${collection.toLowerCase()}`] = collection; | ||
}); | ||
setRoutes(routes); | ||
resolve(undefined); | ||
} catch (e) { | ||
console.error(`Fetch failed: ${(e as Error).message}`); | ||
console.error(`Failed URL: ${url}`); | ||
reject(e); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.loading { | ||
border: 16px solid #f3f3f3; | ||
border-radius: 50%; | ||
border-top: 16px solid black; | ||
width: 120px; | ||
height: 120px; | ||
animation: spin 2s linear infinite; | ||
position: fixed; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
margin: auto; | ||
} | ||
|
||
@keyframes spin { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
|
||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} |