Skip to content

Commit 5225907

Browse files
Merge branch 'main' into launcher-db-overhual
2 parents 1c7c52e + 8704d3a commit 5225907

File tree

25 files changed

+312
-292
lines changed

25 files changed

+312
-292
lines changed

apps/frontend/nuxt.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,14 @@ export default defineNuxtConfig({
392392
autoprefixer: {},
393393
},
394394
},
395+
routeRules: {
396+
"/**": {
397+
headers: {
398+
"Accept-CH": "Sec-CH-Prefers-Color-Scheme",
399+
"Critical-CH": "Sec-CH-Prefers-Color-Scheme",
400+
},
401+
},
402+
},
395403
compatibilityDate: "2024-07-03",
396404
});
397405

apps/frontend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
"intl:extract": "formatjs extract \"{,components,composables,layouts,middleware,modules,pages,plugins,utils}/**/*.{vue,ts,tsx,js,jsx,mts,cts,mjs,cjs}\" --ignore '**/*.d.ts' --ignore 'node_modules' --out-file locales/en-US/index.json --format crowdin --preserve-whitespace"
1414
},
1515
"devDependencies": {
16-
"eslint": "^8.57.0",
1716
"@nuxt/devtools": "^1.3.3",
1817
"@nuxtjs/turnstile": "^0.8.0",
1918
"@types/node": "^20.1.0",
2019
"@vintl/compact-number": "^2.0.5",
2120
"@vintl/how-ago": "^3.0.1",
22-
"@vintl/nuxt": "^1.8.0",
21+
"@vintl/nuxt": "^1.9.2",
2322
"autoprefixer": "^10.4.19",
23+
"eslint": "^8.57.0",
2424
"glob": "^10.2.7",
2525
"nuxt": "^3.12.3",
2626
"postcss": "^8.4.39",

apps/frontend/src/components/ui/charts/ChartDisplay.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
<div
163163
:style="{
164164
'--color-brand': isUsingProjectColors
165-
? intToRgba(project.color, project.id, theme ?? undefined)
165+
? intToRgba(project.color, project.id, theme.active ?? undefined)
166166
: getDefaultColor(project.id),
167167
}"
168168
class="legend__item__color"

apps/frontend/src/composables/cosmetics.js

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function useTheme() {
2+
return useNuxtApp().$theme;
3+
}
4+
5+
export function useCosmetics() {
6+
return useNuxtApp().$cosmetics;
7+
}

apps/frontend/src/composables/theme.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

apps/frontend/src/composables/vue.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Creates a computed reference that uses a provide getter function called with an argument representing the current mount state of the component.
3+
* @param getter A getter function that will run with `mounted` argument representing whether or not the component is mounted.
4+
* @returns A computed reference that changes when component becomes mounted or unmounted.
5+
*/
6+
export function useMountedValue<T>(getter: (isMounted: boolean) => T) {
7+
const mounted = ref(getCurrentInstance()?.isMounted ?? false);
8+
9+
onMounted(() => (mounted.value = true));
10+
11+
onUnmounted(() => (mounted.value = false));
12+
13+
return computed(() => getter(mounted.value));
14+
}

apps/frontend/src/layouts/default.vue

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
:title="formatMessage(messages.changeTheme)"
6363
@click="changeTheme"
6464
>
65-
<MoonIcon v-if="$colorMode.value === 'light'" aria-hidden="true" />
65+
<MoonIcon v-if="$theme.active === 'light'" aria-hidden="true" />
6666
<SunIcon v-else aria-hidden="true" />
6767
</button>
6868
<div
@@ -242,7 +242,7 @@
242242
{{ formatMessage(commonMessages.settingsLabel) }}
243243
</NuxtLink>
244244
<button class="iconified-button" @click="changeTheme">
245-
<MoonIcon v-if="$colorMode.value === 'light'" class="icon" />
245+
<MoonIcon v-if="$theme.active === 'light'" class="icon" />
246246
<SunIcon v-else class="icon" />
247247
<span class="dropdown-item__text">
248248
{{ formatMessage(messages.changeTheme) }}
@@ -403,7 +403,7 @@
403403
{{ formatMessage(messages.getModrinthApp) }}
404404
</nuxt-link>
405405
<button class="iconified-button raised-button" @click="changeTheme">
406-
<MoonIcon v-if="$colorMode.value === 'light'" aria-hidden="true" />
406+
<MoonIcon v-if="$theme.active === 'light'" aria-hidden="true" />
407407
<SunIcon v-else aria-hidden="true" />
408408
{{ formatMessage(messages.changeTheme) }}
409409
</button>
@@ -449,7 +449,6 @@ import ModalCreation from "~/components/ui/ModalCreation.vue";
449449
import Avatar from "~/components/ui/Avatar.vue";
450450
import { getProjectTypeMessage } from "~/utils/i18n-project-type.ts";
451451
import { commonMessages } from "~/utils/common-messages.ts";
452-
import { DARK_THEMES } from "~/composables/theme.js";
453452
454453
const { formatMessage } = useVIntl();
455454
@@ -738,18 +737,11 @@ function toggleBrowseMenu() {
738737
isMobileMenuOpen.value = false;
739738
}
740739
}
741-
function changeTheme() {
742-
updateTheme(
743-
DARK_THEMES.includes(app.$colorMode.value)
744-
? "light"
745-
: cosmetics.value.preferredDarkTheme ?? "dark",
746-
true,
747-
);
748-
}
740+
741+
const { cycle: changeTheme } = useTheme();
749742
750743
function hideStagingBanner() {
751744
cosmetics.value.hideStagingBanner = true;
752-
saveCosmetics();
753745
}
754746
</script>
755747

apps/frontend/src/middleware/auth.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

apps/frontend/src/middleware/auth.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const whitelistedParams = ["flow", "error"];
2+
3+
export default defineNuxtRouteMiddleware(async (_to, from) => {
4+
const config = useRuntimeConfig();
5+
const auth = await useAuth();
6+
7+
if (auth.value.user) return;
8+
9+
const fullPath = from.fullPath;
10+
11+
const url = new URL(fullPath, config.public.apiBaseUrl);
12+
13+
const extractedParams = Object.create(null) as Record<string, string>;
14+
15+
for (const param of whitelistedParams) {
16+
const val = url.searchParams.get(param);
17+
if (val != null) {
18+
extractedParams[param] = val;
19+
url.searchParams.delete(param);
20+
}
21+
}
22+
23+
const redirect = encodeURIComponent(url.pathname + url.search);
24+
25+
return await navigateTo(
26+
{
27+
path: "/auth/sign-in",
28+
query: {
29+
redirect,
30+
...extractedParams,
31+
},
32+
},
33+
{ replace: true },
34+
);
35+
});

0 commit comments

Comments
 (0)