Skip to content

Commit 74de275

Browse files
authored
Add home redirection (#3437)
1 parent 59dd568 commit 74de275

12 files changed

Lines changed: 89 additions & 19 deletions

File tree

app/Http/Resources/GalleryConfigs/InitConfig.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class InitConfig extends Data
9292
// User registration enabled
9393
public bool $is_registration_enabled;
9494

95+
// Homepage
96+
public string $default_homepage;
97+
9598
public function __construct()
9699
{
97100
// Debug mode
@@ -148,6 +151,9 @@ public function __construct()
148151
// User registration enabled
149152
$this->is_registration_enabled = Configs::getValueAsBool('user_registration_enabled');
150153

154+
// Homepage
155+
$this->default_homepage = Configs::getValueAsString('home_page_default');
156+
151157
$this->set_supporter_properties();
152158
}
153159

config/honeypot.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
'bc',
4949
'bk',
5050
'blog',
51-
'home',
5251
'main',
5352
'new',
5453
'newsite',
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
use App\Models\Extensions\BaseConfigMigration;
10+
11+
return new class() extends BaseConfigMigration {
12+
public const TIMELINE = 'Mod Timeline';
13+
public const CONFIG = 'config';
14+
public const STRING_REQ = 'string_required';
15+
16+
public function getConfigs(): array
17+
{
18+
return [
19+
[
20+
'key' => 'home_page_default',
21+
'value' => 'gallery',
22+
'cat' => self::CONFIG,
23+
'type_range' => 'gallery', // We will change the type_range later when adding for functionalities.
24+
'description' => 'Default home page after landing',
25+
'details' => '',
26+
'is_secret' => false,
27+
'level' => 0,
28+
'order' => 4,
29+
],
30+
];
31+
}
32+
};

resources/js/components/settings/ConfigGroup.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@
118118
<NumberField v-else-if="config.type === 'int'" :config="config" :min="0" @filled="filled" @reset="reset" />
119119
<NumberField v-else-if="config.type === 'positive'" :config="config" :min="1" @filled="filled" @reset="reset" />
120120
<SliderField v-else-if="config.type.includes('|')" :config="config" @filled="filled" @reset="reset" />
121-
<p v-else class="bg-red-500">{{ config.key }} -- {{ config.value }} -- {{ config.documentation }} -- {{ config.type }}</p>
121+
<p v-else-if="is_debug_enabled" class="bg-red-500">
122+
{{ config.key }} -- {{ config.value }} -- {{ config.documentation }} -- {{ config.type }}
123+
</p>
122124
</div>
123125
</div>
124126
</template>
@@ -151,7 +153,7 @@ import { useLycheeStateStore } from "@/stores/LycheeState";
151153
import { storeToRefs } from "pinia";
152154
153155
const lycheeStore = useLycheeStateStore();
154-
const { is_old_style, is_expert_mode } = storeToRefs(lycheeStore);
156+
const { is_old_style, is_expert_mode, is_debug_enabled } = storeToRefs(lycheeStore);
155157
156158
const props = defineProps<{
157159
configs: App.Http.Resources.Models.ConfigResource[];

resources/js/lychee.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ declare namespace App.Http.Resources.GalleryConfigs {
276276
is_se_info_hidden: boolean;
277277
is_live_metrics_enabled: boolean;
278278
is_registration_enabled: boolean;
279+
default_homepage: string;
279280
};
280281
export type LandingPageResource = {
281282
landing_page_enable: boolean;
@@ -408,8 +409,8 @@ declare namespace App.Http.Resources.Models {
408409
visitor_id: string;
409410
action: App.Enum.MetricsAction;
410411
photo_id: string | null;
411-
album_id: string | null;
412-
title: string | null;
412+
album_id: string;
413+
title: string;
413414
url: string | null;
414415
};
415416
export type PhotoResource = {

resources/js/menus/LeftMenu.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ import AlbumService from "@/services/album-service";
112112
import SETag from "@/components/icons/SETag.vue";
113113
import Constants from "@/services/constants";
114114
import { useRoute } from "vue-router";
115-
import { useTogglablesStateStore } from "@/stores/ModalsState";
116115
import Button from "primevue/button";
117116
import PiMiniIcon from "@/components/icons/PiMiniIcon.vue";
118117
import { useLeftMenuStateStore } from "@/stores/LeftMenuState";
@@ -124,7 +123,6 @@ const leftMenuState = useLeftMenuStateStore();
124123
const route = useRoute();
125124
const authStore = useAuthStore();
126125
const lycheeStore = useLycheeStateStore();
127-
const togglableStore = useTogglablesStateStore();
128126
const favouritesStore = useFavouriteStore();
129127
130128
const { user, left_menu_open, initData, openLycheeAbout, canSeeAdmin, load, items, profileItems } = useLeftMenu(
@@ -140,7 +138,7 @@ function logout() {
140138
initData.value = undefined;
141139
authStore.setUser(null);
142140
AlbumService.clearCache();
143-
window.location.href = Constants.BASE_URL + "/gallery";
141+
window.location.href = Constants.BASE_URL + "/home";
144142
});
145143
}
146144

resources/js/router/routes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Albums from "@/views/gallery-panels/Albums.vue";
33

44
const Landing = () => import("@/views/Landing.vue");
55
const Favourites = () => import("@/views/gallery-panels/Favourites.vue");
6+
const Home = () => import("@/views/Home.vue");
67
const Frame = () => import("@/views/gallery-panels/Frame.vue");
78
const Search = () => import("@/views/gallery-panels/Search.vue");
89
const MapView = () => import("@/views/gallery-panels/Map.vue");
@@ -39,6 +40,11 @@ const routes_ = [
3940
component: Album,
4041
props: true,
4142
},
43+
{
44+
name: "home",
45+
path: "/home",
46+
component: Home,
47+
},
4248
{
4349
name: "gallery",
4450
path: "/gallery",

resources/js/stores/LycheeState.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const useLycheeStateStore = defineStore("lychee-store", {
6161
// Site title & Dropbox API key
6262
title: "gallery.title",
6363
dropbox_api_key: "disabled",
64+
default_homepage: "gallery",
6465

6566
// Lychee Supporter Edition
6667
is_se_enabled: false,
@@ -77,22 +78,22 @@ export const useLycheeStateStore = defineStore("lychee-store", {
7778
is_registration_enabled: false,
7879
}),
7980
actions: {
80-
init() {
81+
init(): Promise<void> {
8182
// Check if already initialized
8283
if (this.is_init) {
83-
return;
84+
return Promise.resolve();
8485
}
85-
this.load();
86+
return this.load();
8687
},
8788

88-
load() {
89+
load(): Promise<void> {
8990
// semaphore to avoid multiple calls
9091
if (this.is_loading) {
91-
return;
92+
return Promise.resolve();
9293
}
9394
this.is_loading = true;
9495

95-
InitService.fetchInitData()
96+
return InitService.fetchInitData()
9697
.then((response) => {
9798
this.is_init = true;
9899
this.is_loading = false;
@@ -146,6 +147,8 @@ export const useLycheeStateStore = defineStore("lychee-store", {
146147
this.photo_previous_next_size = data.photo_previous_next_size;
147148

148149
this.is_registration_enabled = data.is_registration_enabled;
150+
151+
this.default_homepage = data.default_homepage;
149152
})
150153
.catch((error) => {
151154
// In this specific case, even though it has been possibly disabled, we really need to see the error.

resources/js/views/Home.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<!-- Nothing to see here is is more of a redirection component -->
3+
</template>
4+
<script setup lang="ts">
5+
import { useLycheeStateStore } from "@/stores/LycheeState";
6+
import { useRouter } from "vue-router";
7+
8+
const router = useRouter();
9+
const lycheeStore = useLycheeStateStore();
10+
lycheeStore.init().then(() => {
11+
// Now that we loaded the stuff, we can redirect to the correct page
12+
if (lycheeStore.default_homepage === "gallery") {
13+
router.push({ name: "gallery" });
14+
// Insert other pages here later (feed or others...)
15+
} else {
16+
// Default
17+
router.push({ name: "gallery" });
18+
}
19+
});
20+
</script>

resources/js/views/Landing.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
<div id="menu" class="w-full animate-landingAnimateDown">
1616
<ul class="menu list-none">
1717
<li class="menu-item relative block float-right pt-6 pb-5 px-3">
18-
<RouterLink to="/gallery" class="cursor-pointer block text-xs uppercase font-normal text-surface-0 hover:text-muted-color">
18+
<RouterLink
19+
:to="{ name: 'home' }"
20+
class="cursor-pointer block text-xs uppercase font-normal text-surface-0 hover:text-muted-color"
21+
>
1922
{{ $t("landing.gallery") }}
2023
</RouterLink>
2124
</li>
@@ -62,7 +65,7 @@
6265
</div>
6366
<div class="flex w-full h-1/2 absolute top-1/3 md:top-1/2 left-0 items-center justify-center animate-landingEnterPopIn opacity-0">
6467
<RouterLink
65-
to="/gallery"
68+
:to="{ name: 'home' }"
6669
class="cursor-pointer block text-2xl uppercase text-surface-0 hover:scale-125 transition-all duration-300 p-10 filter-shadow text-center"
6770
>
6871
{{ $t("landing.access_gallery") }}<br class="md:hidden" />
@@ -88,7 +91,7 @@ const router = useRouter();
8891
8992
InitService.fetchLandingData().then((data) => {
9093
if (data.data.landing_page_enable === false) {
91-
router.push("/gallery");
94+
router.push({ name: "home" });
9295
} else {
9396
initdata.value = data.data;
9497
setTimeout(() => (introVisible.value = false), 4000);

0 commit comments

Comments
 (0)