Skip to content

Commit

Permalink
Improved Stat, translation fix
Browse files Browse the repository at this point in the history
- Stat component uses  mantine-color-light variables, more compact code
- Stat component in deck section more responsive
- Fixed trailing comma in welcome message in HomeView when no user name is given
  • Loading branch information
h16nning committed Feb 6, 2024
1 parent 284fc6c commit 5137d0f
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 51 deletions.
6 changes: 5 additions & 1 deletion src/components/HomeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export default function HomeView({
<IconMenu2 />
</ActionIcon>
)}
<Title order={3}>{t("home.welcome-back", { name: userName })}</Title>
<Title order={3}>
{t(userName ? "home.welcome-user" : "home.welcome", {
name: userName,
})}
</Title>
</Group>

<Stack gap="sm" align="flex-end" w="100%">
Expand Down
27 changes: 10 additions & 17 deletions src/components/custom/Stat/Stat.module.css
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
.stat {
padding: 0.75rem;
border-radius: var(--mantine-radius-sm);
position: relative;
}

.statBackground {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border: 1px solid;
border-radius: var(--mantine-radius-sm);
opacity: light-dark(0.2, 0.2);
z-index: 0;
width: 100%;
max-width: 7rem;
}

.statIcon {
width: 1.25rem;
height: 1.25rem;
width: 1rem;
height: 1rem;
min-width: 1rem;
min-height: 1rem;
stroke-width: 1.7;
opacity: initial;
}

.statValue {
font-weight: 700;
font-size: var(--mantine-font-size-md);

}

.statName {
font-size: var(--mantine-font-size-xs);
font-weight: 400;
font-weight: 500;
font-size: var(--mantine-font-size-sm);
}
30 changes: 8 additions & 22 deletions src/components/custom/Stat/Stat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,18 @@ export default function Stat({
<Box
component="div"
className={classes.stat}
miw={width ?? "6rem"}
style={{
color: `var(--mantine-color-${color}-${scheme === "light" ? 9 : 2})`,
backgroundColor: `var(--mantine-color-${color}-light)`,
}}
>
<Box
component="div"
className={classes.statBackground}
style={{
backgroundColor: `var(--mantine-color-${color}-${
scheme === "light" ? 4 : 7
})`,
borderColor: `var(--mantine-color-${color}-${
scheme === "light" ? 5 : 5
})`,
}}
/>
<Group align="center" gap="xs">
<Icon className={classes.statIcon} />
<Stack gap="0rem" align="start">
<Text className={classes.statValue}>{value}</Text>
<Text className={classes.statName} opacity="0.7">
{name}
</Text>
</Stack>
</Group>
<Stack gap="0" w="100%" align="center">
<Text className={classes.statValue}>{value}</Text>
<Group align="center" gap="4px" wrap="nowrap" opacity={0.8}>
<Icon className={classes.statIcon} />
<Text className={classes.statName}>{name}</Text>
</Group>
</Stack>
</Box>
);
}
4 changes: 2 additions & 2 deletions src/components/deck/HeroDeckSection/HeroDeckSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ function HeroDeckSection({
</Button>
</Stack>
) : (
<Stack gap="md" align="center">
<Group>
<Stack gap="md" align="center" w="100%">
<Group wrap="nowrap" w="100%" justify="center">
<Stat
value={stats.newCards ?? 0}
name={t("deck.new-cards-label")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function FinishedLearningView({
<Text style={{ textAlign: "center" }}>
You learned all cards for today of this deck.
</Text>
<Group>
<Group wrap="nowrap">
<Stat
name="Duration"
value={
Expand Down
11 changes: 6 additions & 5 deletions src/components/learning/LearnView/LearnView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ function LearnView() {
>(undefined);

useEffect(() => {
if (useZenMode && !fullscreen) {
toggle();
return () => {
toggle();
}
};
}, []);

useEffect(() => {
getCardsOf(deck).then((cards) => setCardSet(cards ?? null));
}, [deck]);

Expand Down Expand Up @@ -72,9 +76,6 @@ function LearnView() {
useEffect(() => {
if (controller.learningIsFinished) {
stopwatchResult.pause();
if (fullscreen) {
toggle();
}
}
}, [controller.learningIsFinished]);

Expand Down
5 changes: 4 additions & 1 deletion src/i18n/locales/de/translation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"home": { "welcome-back": "Wilkommen zurück, {{name}}!" },
"home": {
"welcome": "Willkomen!",
"welcome-user": "Willkommen zurück, {{name}}!"
},
"deck": {
"new-deck-button": "Neues Deck",
"review-cards-label": "Wiederholen",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"home": {
"welcome-back": "Welcome back, {{name}}!"
"welcome": "Welcome!",
"welcome-user": "Welcome back, {{name}}!"
},
"deck": {
"new-deck-button": "New Deck",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/sv/translation.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"home": {
"welcome-back": "Välkommen tillbaka, {{name}}!"
"welcome": "Välkommen",
"welcome-user": "Välkommen tillbaka, {{name}}!"
},
"deck": {
"new-deck": "Ny bunt",
Expand Down

0 comments on commit 5137d0f

Please sign in to comment.