From 9da39ffda980ad169527de22a0320ad09b8c42ec Mon Sep 17 00:00:00 2001 From: Harshith Mohan <26010946+harshithmohan@users.noreply.github.com> Date: Mon, 4 Nov 2024 01:33:34 +0530 Subject: [PATCH] =?UTF-8?q?Renamer=20fixes,=20check=20settings=20query=20s?= =?UTF-8?q?tatus=20in=20MainPage=20instead=20of=20das=E2=80=A6=20(#1131)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Renamer fixes, check settings query status in MainPage instead of dashboard * Change document title to just "Shoko" --- index.html | 2 +- src/pages/dashboard/DashboardPage.tsx | 13 +------------ src/pages/main/MainPage.tsx | 27 +++++++++++++++++++++++---- src/pages/utilities/Renamer.tsx | 18 +++++++++++++++--- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/index.html b/index.html index 2d35c093..369c6b38 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - Shoko WEB UI + Shoko diff --git a/src/pages/dashboard/DashboardPage.tsx b/src/pages/dashboard/DashboardPage.tsx index 9835f96a..8fa0267a 100644 --- a/src/pages/dashboard/DashboardPage.tsx +++ b/src/pages/dashboard/DashboardPage.tsx @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'; import { Responsive, WidthProvider } from 'react-grid-layout'; import { useDispatch, useSelector } from 'react-redux'; import { useLocation } from 'react-router-dom'; -import { mdiLoading, mdiMenuDown } from '@mdi/js'; +import { mdiMenuDown } from '@mdi/js'; import { Icon } from '@mdi/react'; import { produce } from 'immer'; @@ -148,17 +148,6 @@ function DashboardPage() { window.dispatchEvent(new Event('resize')); }, [currentLayout]); - // settingsQuery.isSuccess is always true due to the existence of initialData - // settingsRevision will be 0 before the first actual fetch and it will never be 0 for fetched data - // This is kind of a hack but it works - if (settingsQuery.data.WebUI_Settings.settingsRevision === 0) { - return ( -
- -
- ); - } - return ( <> settingsQuery.data.WebUI_Settings.settingsRevision > 0, + [settingsQuery.data], + ); useEffect(() => { - dispatch({ type: Events.MAINPAGE_LOADED }); - }, [dispatch]); + if (isSettingsLoaded) dispatch({ type: Events.MAINPAGE_LOADED }); + }, [dispatch, isSettingsLoaded]); const scrollRef = useRef(null); + if (!isSettingsLoaded) { + return ( +
+ +
+ ); + } + return ( <> {notifications && ( diff --git a/src/pages/utilities/Renamer.tsx b/src/pages/utilities/Renamer.tsx index 0c533009..6cd6fa6d 100644 --- a/src/pages/utilities/Renamer.tsx +++ b/src/pages/utilities/Renamer.tsx @@ -320,7 +320,11 @@ const Renamer = () => { const { isPending: settingsPatchPending, mutate: patchSettings } = usePatchSettingsMutation(); const [moveFiles, toggleMoveFiles] = useToggle(settings.Plugins.Renamer.MoveOnImport); - const [renameFiles, toggleRenameFiles] = useToggle(settings.Plugins.Renamer.RenameOnImport); + // In the case where move on import is not selected, we will assume the user wants to rename files when + // they open this page. Otherwise, why are they here? In most cases, it would be for renaming. + const [renameFiles, toggleRenameFiles] = useToggle( + settings.Plugins.Renamer.MoveOnImport ? settings.Plugins.Renamer.RenameOnImport : true, + ); const [showSettings, toggleSettings] = useToggle(false); const [showAddFilesModal, toggleAddFilesModal] = useToggle(false); const [showConfigModal, toggleConfigModal] = useToggle(false); @@ -484,6 +488,14 @@ const Renamer = () => { }); }); + const [renameDisabled, renameDisabledReason] = useMemo(() => { + if (relocatePending) return [true, 'Renaming in progress...']; + if (configEdited) return [true, 'Config has been edited, please save before renaming files']; + if (addedFiles.length === 0) return [true, 'No files added']; + if (!moveFiles && !renameFiles) return [true, 'Neither rename nor move is selected. No action to be performed']; + return [false, '']; + }, [addedFiles.length, configEdited, moveFiles, relocatePending, renameFiles]); + return (
@@ -521,8 +533,8 @@ const Renamer = () => { className="flex h-13 flex-wrap items-center gap-x-2" onClick={handleRename} loading={relocatePending} - disabled={configEdited || relocatePending || addedFiles.length === 0} - tooltip={configEdited ? 'Config has been edited, please save before relocating files' : ''} + disabled={renameDisabled} + tooltip={renameDisabledReason} > Rename Files