Skip to content

Commit 9b7cf6d

Browse files
authored
Merge pull request #1831 from dotanm/frontend/scan-button-feedback-361
frontend: guard scan button when scan directory is not set
2 parents 85f2d61 + 7a80bad commit 9b7cf6d

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

apps/frontend/src/components/settings/Library.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import React, { useEffect, useState } from "react";
4141
import { Trans, useTranslation } from "react-i18next";
4242
import { fetchClient } from "../../api_client/api";
4343
import { serverAddress } from "../../api_client/apiClient";
44+
import { useAccessToken } from "../../api_client/auth/hooks";
4445
import { useTrainFacesMutation } from "../../api_client/faces";
4546
import { useFetchNextcloudDirsQuery } from "../../api_client/folders/hooks/useFetchNextcloudDirsQuery";
4647
import {
@@ -53,12 +54,13 @@ import {
5354
import { useDeleteMissingPhotosMutation } from "../../api_client/photos/hooks";
5455
import { useFetchCountStatsQuery } from "../../api_client/stats/hooks";
5556
import { COUNT_STATS_DEFAULTS } from "../../api_client/stats/types";
56-
import { useUpdateUserMutation } from "../../api_client/user/hooks";
57+
import { useFetchUserListQuery, useUpdateUserMutation } from "../../api_client/user/hooks";
5758
import { useCurrentUserSelfDetailsQuery } from "../../api_client/user/hooks/useCurrentUserSelfDetailsQuery";
5859
import { User } from "../../api_client/user/types";
5960
import { notification } from "../../service/notifications";
6061
import { CountStats } from "../CountStats";
6162
import { ModalNextcloudScanDirectoryEdit } from "../modals/ModalNextcloudScanDirectoryEdit";
63+
import { ModalUserEdit } from "../modals/ModalUserEdit";
6264

6365
function BadgeIcon(details: User, isSuccess: boolean, isError: boolean, isFetching: boolean) {
6466
const { nextcloud_server_address: server } = details;
@@ -80,7 +82,10 @@ export function Library() {
8082
const [isOpenNextcloudHelp, setIsOpenNextcloudHelp] = useState(false);
8183
const [avatarImgSrc, setAvatarImgSrc] = useState("/unknown_user.jpg");
8284
const [modalNextcloudScanDirectoryOpen, setModalNextcloudScanDirectoryOpen] = useState(false);
85+
const [scanDirectorySetupOpen, setScanDirectorySetupOpen] = useState(false);
8386
const { data: userSelfDetails } = useCurrentUserSelfDetailsQuery();
87+
const { data: auth } = useAccessToken();
88+
const { data: userList } = useFetchUserListQuery();
8489
const [editedUser, setEditedUser] = useState<User | null>(null);
8590
const { data: worker } = useWorkerQuery();
8691
const [workerAvailability, setWorkerAvailability] = useState(false);
@@ -111,6 +116,18 @@ export function Library() {
111116
close();
112117
};
113118

119+
const guardScan = (run: () => void) => {
120+
if (userSelfDetails?.scan_directory) {
121+
run();
122+
return;
123+
}
124+
if (auth?.access?.is_admin) {
125+
setScanDirectorySetupOpen(true);
126+
} else {
127+
notification.scanDirectoryRequired();
128+
}
129+
};
130+
114131
// open update dialog, when user was edited
115132
useEffect(() => {
116133
if (JSON.stringify(editedUser) !== JSON.stringify(userSelfDetails)) {
@@ -266,7 +283,7 @@ export function Library() {
266283
<Grid.Col span={{ base: 12, sm: 2 }}>
267284
<Group wrap="nowrap" gap={0} justify="flex-end">
268285
<Button
269-
onClick={() => scanPhotos.mutate()}
286+
onClick={() => guardScan(() => scanPhotos.mutate())}
270287
disabled={!workerAvailability}
271288
leftSection={<Refresh />}
272289
variant="filled"
@@ -295,7 +312,7 @@ export function Library() {
295312
<Menu.Dropdown>
296313
<Menu.Item
297314
leftSection={<Refresh size="1rem" />}
298-
onClick={() => rescanPhotos.mutate()}
315+
onClick={() => guardScan(() => rescanPhotos.mutate())}
299316
disabled={!workerAvailability}
300317
>
301318
{t("settings.statusrescanphotosfalse")}
@@ -609,6 +626,16 @@ export function Library() {
609626
/>
610627
</Card>
611628

629+
<ModalUserEdit
630+
onRequestClose={() => setScanDirectorySetupOpen(false)}
631+
userToEdit={userSelfDetails}
632+
isOpen={scanDirectorySetupOpen}
633+
updateAndScan
634+
userList={userList ?? []}
635+
createNew={false}
636+
firstTimeSetup
637+
/>
638+
612639
<Dialog opened={isOpenUpdateDialog} withCloseButton onClose={handleCancel} size="lg" radius="md">
613640
<Text size="sm" style={{ marginBottom: 10 }} fw={500}>
614641
Save Changes?

apps/frontend/src/service/notifications/photos.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ function deleteMissingPhotos() {
152152
});
153153
}
154154

155+
function scanDirectoryRequired() {
156+
showNotification({
157+
message: i18n.t("toasts.scan_directory_required"),
158+
title: i18n.t("toasts.scanphotostitle"),
159+
color: "red",
160+
});
161+
}
162+
155163
export const photos = {
156164
deleteMissingPhotos,
157165
downloadCompleted,
@@ -160,6 +168,7 @@ export const photos = {
160168
removePhotos,
161169
rotatePhotos,
162170
savePhotoCaptions,
171+
scanDirectoryRequired,
163172
startFullPhotoScan,
164173
startNextcloudPhotoScan,
165174
startPhotoScan,

0 commit comments

Comments
 (0)