Skip to content

Commit

Permalink
remove language reset for now
Browse files Browse the repository at this point in the history
  • Loading branch information
LexSwed committed Aug 9, 2024
1 parent 77bac9b commit 2b629c7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 54 deletions.
65 changes: 30 additions & 35 deletions packages/web/src/routes/app/profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,41 +107,36 @@ export default function ProfilePage() {
<Text as="legend" with="overline" class="mb-3">
{t("section.locale")}
</Text>
<div class="flex flex-col gap-2">
<Picker
label={t("setting.locale")}
value={user().locale}
autocomplete="language"
class="[&_[data-part=trigger]_[data-flag]]:block"
name="locale"
>
<Option
value={"en" satisfies SupportedLocale}
label={
<div class="flex w-full flex-row justify-between gap-4">
English
<span class="hidden" data-flag>
🏴󠁧󠁢󠁥󠁮󠁧󠁿
</span>
</div>
}
/>
<Option
value={"es" satisfies SupportedLocale}
label={
<div class="flex w-full flex-row justify-between gap-4">
Español
<span class="hidden" data-flag>
🇪🇸
</span>
</div>
}
/>
</Picker>
<Show when={user().isLangNotMatching}>
<Button variant="link">{t("reset-locale")}</Button>
</Show>
</div>
<Picker
label={t("setting.locale")}
value={user().locale}
autocomplete="language"
class="[&_[data-part=trigger]_[data-flag]]:block"
name="locale"
>
<Option
value={"en" satisfies SupportedLocale}
label={
<div class="flex w-full flex-row justify-between gap-4">
English
<span class="hidden" data-flag>
🏴󠁧󠁢󠁥󠁮󠁧󠁿
</span>
</div>
}
/>
<Option
value={"es" satisfies SupportedLocale}
label={
<div class="flex w-full flex-row justify-between gap-4">
Español
<span class="hidden" data-flag>
🇪🇸
</span>
</div>
}
/>
</Picker>
<Picker
label={t("setting.measure-system.label")}
value={user().measurementSystem}
Expand Down
18 changes: 18 additions & 0 deletions packages/web/src/server/api/user.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import { json } from "@solidjs/router";
import { isValiError } from "valibot";
import { header as getHeaderLang } from "../i18n/locale";

import { getRequestUser } from "~/server/auth/request-user";
import { type UpdateUserSchema, userUpdate } from "~/server/db/queries/userUpdate";

import { useUserSession } from "../auth/user-session";
import { userProfile } from "../db/queries/userFamily";
import { translateErrorTokens } from "../utils";

export async function updateUserProfileServer(formData: FormData) {
Expand Down Expand Up @@ -35,3 +37,19 @@ export async function updateUserProfileServer(formData: FormData) {
return json({ failureReason: "other" as const }, { status: 500, revalidate: [] });
}
}

export async function getUserProfileServer() {
try {
const user = await getRequestUser();
const profile = await userProfile(user.userId);
const headerLang = getHeaderLang();

return {
...profile,
isLangNotMatching: headerLang ? headerLang.language !== profile.locale : false,
};
} catch (error) {
console.error(error);
throw error;
}
}
22 changes: 3 additions & 19 deletions packages/web/src/server/api/user.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { action, cache } from "@solidjs/router";

import { getRequestUser } from "~/server/auth/request-user";
import { userFamily, userProfile } from "~/server/db/queries/userFamily";
import { userFamily } from "~/server/db/queries/userFamily";

import { header as getHeaderLang } from "../i18n/locale";
import { updateUserProfileServer } from "./user.server";
import { getUserProfileServer, updateUserProfileServer } from "./user.server";

export const getUserFamily = cache(async () => {
"use server";
Expand All @@ -24,22 +23,7 @@ export const getUser = cache(async () => {
return user;
}, "user");

export const getUserProfile = cache(async () => {
"use server";
try {
const user = await getRequestUser();
const profile = await userProfile(user.userId);
const headerLang = await getHeaderLang();

return {
...profile,
isLangNotMatching: headerLang ? headerLang.language !== profile.locale : false,
};
} catch (error) {
console.error(error);
throw error;
}
}, "user-profile");
export const getUserProfile = cache(async () => getUserProfileServer(), "user-profile");

export const updateUserProfile = action(
async (formData: FormData) => updateUserProfileServer(formData),
Expand Down

0 comments on commit 2b629c7

Please sign in to comment.