Skip to content

Commit ce18261

Browse files
committed
small changes
1 parent 3473253 commit ce18261

File tree

6 files changed

+45
-18
lines changed

6 files changed

+45
-18
lines changed

package-lock.json

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"next": "13.1.6",
2121
"nunjucks": "^3.2.3",
2222
"react": "18.2.0",
23-
"react-dom": "18.2.0"
23+
"react-dom": "18.2.0",
24+
"use-local-storage-state": "^19.4.0"
2425
},
2526
"devDependencies": {
2627
"@types/node": "18.11.18",

src/common.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,3 @@ export const capitalize = (str) => {
6262
);
6363
return capitalized_words.join(" ");
6464
};
65-
66-
export const word_count = (str) => {
67-
return str.split(" ").length;
68-
};

src/hooks/option.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
import { useState } from "react";
1+
import useLocalStorageState from "use-local-storage-state";
22
import qs from "fast-querystring";
33
import Error from "@/images/error.svg";
44

55
const defaultOption = {
66
username: "redheadphone",
7-
theme: "default",
7+
theme: "github_dark",
88
disable_animations: false,
99
show_icons: true,
1010
force_username: true,
1111
};
1212

1313
const useOption = () => {
14-
const [options, setOptions] = useState(defaultOption);
15-
const [querystring, setQuerystring] = useState(qs.stringify(options));
16-
const [error, setError] = useState(false);
14+
const [options, setOptions] = useLocalStorageState("options", {
15+
defaultValue: defaultOption,
16+
});
17+
const [querystring, setQuerystring] = useLocalStorageState("querystring", {
18+
defaultValue: qs.stringify(options),
19+
});
20+
const [error, setError] = useLocalStorageState("error", {
21+
defaultValue: false,
22+
});
1723

1824
const getImgUrl = (query = querystring) => {
1925
return error ? Error.src : `/api/card?${query}`;

src/pages/api/card.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import {
55
get_color_from_rating,
66
CONSTANTS,
77
clamp_value,
8-
word_count,
98
} from "@/common.js";
109

11-
function check_overflow(category, maxCategory) {
12-
return word_count(category) + word_count(maxCategory) > 2;
10+
function check_overflow(rank, maxRank, width) {
11+
return (rank.length + maxRank.length + 8)*10 + 34 > width;
1312
}
1413

1514
export default async function handler(req, res) {
@@ -88,6 +87,9 @@ export default async function handler(req, res) {
8887
...themes[theme],
8988
...customColorScheme,
9089
};
90+
const width = Math.max(380, 100 + name.length * 14);
91+
const breakBetweenRank = check_overflow(rank, maxRank, width);
92+
const height = 290 + (breakBetweenRank ? 25 : 0);
9193

9294
res.send(
9395
renderTemplate("card.svg", {
@@ -96,9 +98,9 @@ export default async function handler(req, res) {
9698
maxRating,
9799
rank,
98100
maxRank,
99-
breakBetweenRank: check_overflow(rank, maxRank),
100-
height: 290 + (check_overflow(rank, maxRank) ? 25 : 0),
101-
width: Math.max(380, 100 + name.length * 14),
101+
breakBetweenRank,
102+
height,
103+
width,
102104
contestsCount,
103105
problemsSolved,
104106
friendOfCount,

src/pages/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default function Home() {
105105
},
106106
]}
107107
>
108-
<Input autoComplete="off" onPressEnter={onUsernameEnter} />
108+
<Input autoComplete="off" spellCheck={false} onPressEnter={onUsernameEnter} />
109109
</Form.Item>
110110
<Form.Item className="form-item" label="Theme" name="theme">
111111
<Select

0 commit comments

Comments
 (0)