Skip to content

Commit 273a3f3

Browse files
committed
remove dependency on parent-id in modals and directly extract the info from the url
1 parent ac67199 commit 273a3f3

14 files changed

Lines changed: 65 additions & 78 deletions

File tree

resources/js/components/forms/album/AlbumCreateDialog.vue

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,22 @@
3131
import AlbumService from "@/services/album-service";
3232
import Dialog from "primevue/dialog";
3333
import InputText from "@/components/forms/basic/InputText.vue";
34-
import { computed, ref, watch } from "vue";
34+
import { computed, ref } from "vue";
3535
import { useRouter } from "vue-router";
3636
import FloatLabel from "primevue/floatlabel";
3737
import Button from "primevue/button";
3838
import { useToast } from "primevue/usetoast";
3939
import { useTogglablesStateStore } from "@/stores/ModalsState";
4040
import { storeToRefs } from "pinia";
4141
import { onKeyPressed } from "@vueuse/core";
42-
43-
const props = defineProps<{
44-
parentId: string | null;
45-
}>();
42+
import { usePhotoRoute } from "@/composables/photo/photoRoute";
4643
4744
const togglableStore = useTogglablesStateStore();
4845
const { is_create_album_visible } = storeToRefs(togglableStore);
49-
50-
const parentId = ref(props.parentId);
46+
const router = useRouter();
47+
const { getParentId } = usePhotoRoute(router);
5148
5249
const toast = useToast();
53-
const router = useRouter();
5450
5551
const title = ref<string | undefined>(undefined);
5652
@@ -63,12 +59,12 @@ function create() {
6359
6460
AlbumService.createAlbum({
6561
title: title.value as string,
66-
parent_id: parentId.value,
62+
parent_id: getParentId() ?? null,
6763
})
6864
.then((response) => {
6965
title.value = undefined;
7066
is_create_album_visible.value = false;
71-
AlbumService.clearCache(parentId.value);
67+
AlbumService.clearCache(getParentId());
7268
router.push(`/gallery/${response.data}`);
7369
})
7470
.catch((error) => {
@@ -77,12 +73,4 @@ function create() {
7773
}
7874
7975
onKeyPressed("Enter", () => is_create_album_visible.value && isValid.value && create());
80-
81-
watch(
82-
() => props.parentId,
83-
(newAlbumID, _oldAlbumID) => {
84-
title.value = undefined;
85-
parentId.value = newAlbumID as string | null;
86-
},
87-
);
8876
</script>

resources/js/components/forms/gallery-dialogs/AlbumMergeDialog.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ import SearchTargetAlbum from "@/components/forms/album/SearchTargetAlbum.vue";
4141
import AlbumService from "@/services/album-service";
4242
import { useToast } from "primevue/usetoast";
4343
import Dialog from "primevue/dialog";
44+
import { useRouter } from "vue-router";
45+
import { usePhotoRoute } from "@/composables/photo/photoRoute";
4446
4547
const props = defineProps<{
46-
parentId: string | undefined;
4748
album?: App.Http.Resources.Models.ThumbAlbumResource;
4849
albumIds: string[];
4950
}>();
5051
52+
const router = useRouter();
53+
const { getParentId } = usePhotoRoute(router);
5154
const visible = defineModel<boolean>("visible", { default: false });
5255
5356
const emits = defineEmits<{
@@ -100,10 +103,10 @@ function execute() {
100103
for (const id in albumMergedIds) {
101104
AlbumService.clearCache(id);
102105
}
103-
if (props.parentId === undefined) {
106+
if (getParentId() === undefined) {
104107
AlbumService.clearAlbums();
105108
} else {
106-
AlbumService.clearCache(props.parentId);
109+
AlbumService.clearCache(getParentId());
107110
}
108111
109112
// RESET !

resources/js/components/forms/gallery-dialogs/DeleteDialog.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,20 @@ import { sprintf } from "sprintf-js";
2727
import Dialog from "primevue/dialog";
2828
import Button from "primevue/button";
2929
import { useToast } from "primevue/usetoast";
30-
const toast = useToast();
30+
import { useRouter } from "vue-router";
31+
import { usePhotoRoute } from "@/composables/photo/photoRoute";
3132
33+
const toast = useToast();
3234
const props = defineProps<{
33-
parentId: string | undefined;
3435
photo?: App.Http.Resources.Models.PhotoResource;
3536
photoIds?: string[];
3637
album?: App.Http.Resources.Models.ThumbAlbumResource;
3738
albumIds?: string[];
3839
}>();
3940
41+
const router = useRouter();
42+
const { getParentId } = usePhotoRoute(router);
43+
4044
const visible = defineModel<boolean>("visible", { default: false });
4145
const emits = defineEmits<{
4246
deleted: [];
@@ -83,10 +87,10 @@ function executeDeleteAlbum() {
8387
}
8488
8589
AlbumService.delete(albumDeletedIds).then(() => {
86-
if (props.parentId === undefined) {
90+
if (getParentId() === undefined) {
8791
AlbumService.clearAlbums();
8892
} else {
89-
AlbumService.clearCache(props.parentId);
93+
AlbumService.clearCache(getParentId());
9094
}
9195
emits("deleted");
9296
});
@@ -105,7 +109,7 @@ function executeDeletePhoto() {
105109
summary: trans("dialogs.photo_delete.deleted"),
106110
life: 3000,
107111
});
108-
AlbumService.clearCache(props.parentId);
112+
AlbumService.clearCache(getParentId());
109113
emits("deleted");
110114
});
111115
}

resources/js/components/forms/gallery-dialogs/MoveDialog.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ import SearchTargetAlbum from "@/components/forms/album/SearchTargetAlbum.vue";
3939
import { useToast } from "primevue/usetoast";
4040
import Button from "primevue/button";
4141
import Dialog from "primevue/dialog";
42+
import { useRouter } from "vue-router";
43+
import { usePhotoRoute } from "@/composables/photo/photoRoute";
4244
4345
const props = defineProps<{
44-
parentId: string | undefined;
4546
album?: App.Http.Resources.Models.ThumbAlbumResource;
4647
albumIds?: string[];
4748
photo?: App.Http.Resources.Models.PhotoResource;
4849
photoIds?: string[];
4950
}>();
5051
52+
const router = useRouter();
53+
const { getParentId } = usePhotoRoute(router);
5154
const visible = defineModel<boolean>("visible", { default: false });
5255
5356
const emits = defineEmits<{
@@ -142,11 +145,12 @@ function executeMoveAlbum() {
142145
for (const id in albumMovedIds) {
143146
AlbumService.clearCache(id);
144147
}
145-
if (props.parentId === undefined) {
148+
if (getParentId() === undefined) {
146149
AlbumService.clearAlbums();
147150
} else {
148-
AlbumService.clearCache(props.parentId);
151+
AlbumService.clearCache(getParentId());
149152
}
153+
close();
150154
emits("moved");
151155
});
152156
}
@@ -161,19 +165,18 @@ function executeMovePhoto() {
161165
} else {
162166
photoMovedIds = props.photoIds as string[];
163167
}
164-
PhotoService.move(destination_id.value, photoMovedIds).then(() => {
168+
PhotoService.move({ album_id: destination_id.value, photo_ids: photoMovedIds }).then(() => {
165169
toast.add({
166170
severity: "success",
167171
summary: sprintf(trans("dialogs.move_photo.moved"), titleMovedTo.value),
168172
life: 3000,
169173
});
170174
// Clear the cache for the current album and the destination album
171-
AlbumService.clearCache(props.parentId);
175+
AlbumService.clearCache(getParentId());
172176
AlbumService.clearCache(destination_id.value);
173177
174178
// RESET !
175-
destination_id.value = undefined;
176-
179+
close();
177180
emits("moved");
178181
});
179182
}

resources/js/components/forms/photo/PhotoCopyDialog.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import Dialog from "primevue/dialog";
4141
import { trans } from "laravel-vue-i18n";
4242
4343
const props = defineProps<{
44-
parentId: string | undefined;
4544
photo?: App.Http.Resources.Models.PhotoResource;
4645
photoIds?: string[];
4746
}>();

resources/js/components/headers/AlbumHeader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<ImportFromLink v-if="canUpload" v-model:visible="is_import_from_link_open" :parent-id="props.album.id" @refresh="emits('refresh')" />
2+
<ImportFromLink v-if="canUpload" v-model:visible="is_import_from_link_open" @refresh="emits('refresh')" />
33
<DropBox v-if="canUpload" v-model:visible="is_import_from_dropbox_open" :album-id="props.album.id" />
44
<Toolbar class="w-full border-0 h-14" v-if="album">
55
<template #start>

resources/js/components/headers/AlbumsHeader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<ImportFromLink v-if="canUpload" v-model:visible="is_import_from_link_open" :parent-id="null" />
2+
<ImportFromLink v-if="canUpload" v-model:visible="is_import_from_link_open" />
33
<DropBox v-if="canUpload" v-model:visible="is_import_from_dropbox_open" :album-id="null" />
44
<Toolbar
55
class="w-full border-0 h-14"

resources/js/components/modals/ImportFromLink.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@ import Button from "primevue/button";
4040
import Dialog from "primevue/dialog";
4141
import PhotoService from "@/services/photo-service";
4242
import Textarea from "primevue/textarea";
43+
import { useRouter } from "vue-router";
44+
import { usePhotoRoute } from "@/composables/photo/photoRoute";
4345
4446
const visible = defineModel("visible", { default: false }) as Ref<boolean>;
45-
const props = defineProps<{ parentId: string | null }>();
4647
const emits = defineEmits<{ refresh: [] }>();
4748
49+
const router = useRouter();
50+
const { getParentId } = usePhotoRoute(router);
51+
4852
const urls = ref<string>("");
4953
5054
function submit() {
51-
PhotoService.importFromUrl(urls.value.split("\n"), props.parentId).then(() => {
55+
PhotoService.importFromUrl(urls.value.split("\n"), getParentId() ?? null).then(() => {
5256
urls.value = "";
5357
visible.value = false;
5458
emits("refresh");

resources/js/composables/photo/photoRoute.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import { ALL } from "@/config/constants";
22
import { Router } from "vue-router";
33

44
export function usePhotoRoute(router: Router) {
5+
function getParentId(): string | undefined {
6+
return router.currentRoute.value.params.albumId as string | undefined;
7+
}
8+
59
function photoRoute(photoId: string) {
610
const currentRoute = router.currentRoute.value.name as string;
7-
const albumId = router.currentRoute.value.params.albumId as string | undefined;
11+
const albumId = getParentId();
812

913
if (currentRoute.startsWith("search")) {
1014
return { name: "search", params: { albumId: albumId ?? ALL, photoId: photoId } };
@@ -13,5 +17,5 @@ export function usePhotoRoute(router: Router) {
1317
return { name: "album", params: { albumId: albumId ?? ALL, photoId: photoId } };
1418
}
1519

16-
return { photoRoute };
20+
return { getParentId, photoRoute };
1721
}

resources/js/services/photo-service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export type PhotoUpdateRequest = {
1010
taken_at: string | null;
1111
};
1212

13+
export type PhotoMove = {
14+
photo_ids: string[];
15+
album_id: string | null;
16+
};
17+
1318
const PhotoService = {
1419
get(photo_id: string): Promise<AxiosResponse<App.Http.Resources.Models.PhotoResource>> {
1520
return axios.get(`${Constants.getApiUrl()}Photo`, { params: { photo_id: photo_id }, data: {} });
@@ -27,8 +32,8 @@ const PhotoService = {
2732
return axios.patch(`${Constants.getApiUrl()}Photo::rename`, { photo_id: photo_id, title: title });
2833
},
2934

30-
move(destination_id: string | null, photo_ids: string[]): Promise<AxiosResponse> {
31-
return axios.post(`${Constants.getApiUrl()}Photo::move`, { album_id: destination_id, photo_ids: photo_ids });
35+
move(data: PhotoMove): Promise<AxiosResponse> {
36+
return axios.post(`${Constants.getApiUrl()}Photo::move`, data);
3237
},
3338

3439
tags(photo_ids: string[], tags: string[], shall_override: boolean): Promise<AxiosResponse> {

0 commit comments

Comments
 (0)