Skip to content

Commit 5dea20a

Browse files
committed
frontend + other small changes
1 parent 299eb31 commit 5dea20a

File tree

6 files changed

+317
-74
lines changed

6 files changed

+317
-74
lines changed

docs/themes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ Use `&theme=THEME_NAME` parameter like so :
1212
Codeforces readme stats comes with several built-in themes (e.g. `dark`, `radical`, `merko`, `gruvbox`, `tokyonight`, `onedark`, `cobalt`, `synthwave`, `highcontrast`, `dracula`).
1313

1414
<p>
15-
<img style="width:340px" src="https://codeforces-readme-stats.vercel.app/api/card?username=redheadphone&theme=dark">
16-
<img style="width:340px" src="https://codeforces-readme-stats.vercel.app/api/card?username=redheadphone&theme=radical">
17-
<img style="width:340px" src="https://codeforces-readme-stats.vercel.app/api/card?username=redheadphone&theme=gruvbox">
18-
<img style="width:340px" src="https://codeforces-readme-stats.vercel.app/api/card?username=redheadphone&theme=tokyonight">
15+
<img style="width:340px" src="https://codeforces-readme-stats.vercel.app/api/card?username=redheadphone&theme=dark&border_color=63656e">
16+
<img style="width:340px" src="https://codeforces-readme-stats.vercel.app/api/card?username=redheadphone&theme=radical&border_color=63656e">
17+
<img style="width:340px" src="https://codeforces-readme-stats.vercel.app/api/card?username=redheadphone&theme=gruvbox&border_color=63656e">
18+
<img style="width:340px" src="https://codeforces-readme-stats.vercel.app/api/card?username=redheadphone&theme=tokyonight&border_color=63656e">
1919
</p>
2020

2121
You can look at all available themes from the [theme config file](https://github.com/RedHeadphone/codeforces-readme-stats/blob/master/src/themes.js) & **you can also contribute new themes** if you like :D

src/fetcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function fetch_error_handler(fetch, username, last_cache) {
1010
resolve(res);
1111
}
1212
else reject({ status: 500, error: "Codeforces Server Error" });
13-
}, 2000);
13+
}, 4000);
1414
fetch()
1515
.then((result) => {
1616
clearTimeout(timeoutID);

src/hooks/option.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import useLocalStorageState from "use-local-storage-state";
22
import qs from "fast-querystring";
3-
import Error from "@/images/error.svg";
43

54
const defaultOption = {
65
username: "redheadphone",
@@ -14,29 +13,45 @@ const useOption = () => {
1413
const [options, setOptions] = useLocalStorageState("options", {
1514
defaultValue: defaultOption,
1615
});
17-
const [querystring, setQuerystring] = useLocalStorageState("querystring", {
16+
const [imageUrl, setImageUrl] = useLocalStorageState("imageUrl", {
1817
defaultValue: qs.stringify(options),
1918
});
2019
const [error, setError] = useLocalStorageState("error", {
2120
defaultValue: false,
2221
});
22+
const [loading, setLoading] = useLocalStorageState("loading", {
23+
defaultValue: true,
24+
});
2325

24-
const getImgUrl = (query = querystring) => {
25-
return error ? Error.src : `/api/card?${query}`;
26+
const updateImage = (newOptions) => {
27+
const newImageUrl = `/api/card?${qs.stringify(newOptions)}`;
28+
if (newImageUrl != imageUrl || error) setLoading(true);
29+
setError(false);
30+
setImageUrl(newImageUrl);
2631
};
2732

28-
const updateQuerystring = (newOptions) => {
29-
setError(false);
30-
setQuerystring(qs.stringify(newOptions));
33+
const checkHandleNotFound = () => {
34+
return new Promise((resolve) => {
35+
fetch(
36+
`https://codeforces.com/api/user.info?handles=${options.username}`
37+
).then((res) => {
38+
if (res.status === 400) {
39+
resolve();
40+
}
41+
});
42+
});
3143
};
3244

3345
return {
3446
options,
3547
setOptions,
36-
getImgUrl,
48+
imageUrl,
49+
updateImage,
3750
error,
3851
setError,
39-
updateQuerystring,
52+
loading,
53+
setLoading,
54+
checkHandleNotFound,
4055
};
4156
};
4257

0 commit comments

Comments
 (0)