Skip to content

Commit

Permalink
Merge branch 'master' into relocate_files_from_collection
Browse files Browse the repository at this point in the history
  • Loading branch information
ElementalCrisis authored Feb 8, 2025
2 parents 43dd990 + 21bfb2c commit 926e82f
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 60 deletions.
14 changes: 7 additions & 7 deletions src/components/Dialogs/ImportFolderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import type { ImportFolderType } from '@/core/types/api/import-folder';

const defaultImportFolder = {
WatchForNewFiles: false,
DropFolderType: 0 as 0 | 1 | 2 | 3,
DropFolderType: 'Excluded',
Path: '',
Name: '',
ID: 0,
};
} as ImportFolderType;

function ImportFolderModal() {
const dispatch = useDispatch();
Expand Down Expand Up @@ -127,14 +127,14 @@ function ImportFolderModal() {
<Select
label="Drop Type"
id="DropFolderType"
value={importFolder.DropFolderType}
value={importFolder.DropFolderType ?? 'Excluded'}
onChange={handleInputChange}
className="w-full"
>
<option value={0}>None</option>
<option value={1}>Source</option>
<option value={2}>Destination</option>
<option value={3}>Both</option>
<option value="Excluded">None</option>
<option value="Source">Source</option>
<option value="Destination">Destination</option>
<option value="Both">Both</option>
</Select>
<Select
label="Watch For New Files"
Expand Down
4 changes: 2 additions & 2 deletions src/core/router/AuthenticatedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function AuthenticatedRoute(props: Props) {
const from = encodeURIComponent(location.pathname + location.search + location.hash);
const isAuthenticated = useSelector((state: RootState) => state.apiSession.apikey !== '');
const serverStatusQuery = useServerStatusQuery();
const serverState = serverStatusQuery.data?.State ?? 2;
const serverState = serverStatusQuery.data?.State ?? 'Started';

return (serverState === 2 && isAuthenticated)
return (serverState === 'Started' && isAuthenticated)
? props.children
: <Navigate to={from === '/' || from === '/webui/' ? '/webui/login' : `/webui/login?redirectTo=${from}`} replace />;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/types/api/import-folder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type ImportFolderType = {
ID: number;
WatchForNewFiles?: boolean;
DropFolderType?: 0 | 1 | 2 | 3;
DropFolderType?: 'Excluded' | 'Source' | 'Destination' | 'Both';
Path: string;
Name: string;
Size?: number;
Expand Down
2 changes: 1 addition & 1 deletion src/core/types/api/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type UserType = {

export type ServerStatusType = {
StartupMessage: string;
State: 1 | 2 | 3 | 4;
State: 'Starting' | 'Started' | 'Failed' | 'Waiting';
Uptime: string;
DatabaseBlocked: {
Progress: number;
Expand Down
2 changes: 1 addition & 1 deletion src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function isDebug() {
return DEV;
}

export const minimumSupportedServerVersion = '5.0.0.89';
export const minimumSupportedServerVersion = '5.1.0.28';

export const parseServerVersion = (version: string) => {
const semverVersion = semver.coerce(version)?.raw;
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useIsFeatureSupported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { VersionType } from '@/core/types/api/init';

export enum FeatureType {
Placeholder = '5.0.0.0', // This is as a placeholder so the string conversion for `parseServerVersion` works and also serves as an example
ReleaseManagementQuickSelect = '5.1.0.6',
}

const useIsFeatureSupported = (feature: FeatureType) => {
Expand Down
16 changes: 4 additions & 12 deletions src/pages/dashboard/panels/ImportFolders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,10 @@ function ImportFolders() {

const renderFolder = (folder: ImportFolderType) => {
let flags = '';
switch (folder.DropFolderType) {
case 1:
flags = 'Source';
break;
case 2:
flags = 'Destination';
break;
case 3:
flags = 'Source, Destination';
break;
default:
}

if (folder.DropFolderType === 'Both') flags = 'Source, Destination';
else if (folder.DropFolderType !== 'Excluded') flags = folder.DropFolderType ?? '';

if (folder.WatchForNewFiles) flags += folder.DropFolderType ? ', Watch' : 'Watch';

return (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/firstrun/Acknowledgement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Acknowledgement() {
onClick={handleNext}
buttonType="primary"
className="py-2 font-semibold"
disabled={serverStatusQuery.data?.State !== 4}
disabled={serverStatusQuery.data?.State !== 'Waiting'}
>
Continue
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/firstrun/FirstRunPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function FirstRunPage() {
useEffect(() => {
if (
(serverStatusQuery.isSuccess || serverStatusQuery.isError) && !isPersistent && !serverStatusQuery.isPending
&& serverStatusQuery.data?.State !== 4
&& serverStatusQuery.data?.State !== 'Waiting'
) {
navigate('../login', { replace: true });
}
Expand Down
21 changes: 6 additions & 15 deletions src/pages/firstrun/ImportFolders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,12 @@ const Folder = (props: ImportFolderType) => {

const flags = useMemo(() => {
let tempFlags = '';
switch (DropFolderType) {
case 1:
tempFlags = 'Source';
break;
case 2:
tempFlags = 'Destination';
break;
case 3:
tempFlags = 'Source, Destination';
break;
default:
}
if (WatchForNewFiles) {
tempFlags += DropFolderType ? ', Watch' : 'Watch';
}

if (DropFolderType === 'Both') tempFlags = 'Source, Destination';
else if (DropFolderType !== 'Excluded') tempFlags = DropFolderType ?? '';

if (WatchForNewFiles) tempFlags += DropFolderType ? ', Watch' : 'Watch';

return tempFlags;
}, [DropFolderType, WatchForNewFiles]);

Expand Down
13 changes: 8 additions & 5 deletions src/pages/firstrun/StartServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ function StartServer() {
};

useEffect(() => {
if (serverStatusQuery.data?.State === 2 || serverStatusQuery.data?.State === 3) setPollingInterval(0);
if (serverStatusQuery.data?.State === 'Started' || serverStatusQuery.data?.State === 'Failed') {
setPollingInterval(0);
}
}, [serverStatusQuery.data]);

return (
Expand All @@ -69,13 +71,14 @@ function StartServer() {
<div className="flex flex-col">
<div className="flex gap-x-2">
<span className="font-semibold">Status:</span>
{serverStatusQuery.data?.State === 2
{serverStatusQuery.data?.State === 'Started'
? <span className="font-semibold">Started!</span>
: (serverStatusQuery.data?.StartupMessage ?? <span className="font-semibold">Not Started!</span>)}
</div>
<div className="mt-24 flex items-center justify-center">
{pollingInterval === 0
&& ((!serverStatusQuery.isSuccess && !serverStatusQuery.isError) || serverStatusQuery.data?.State === 4)
&& ((!serverStatusQuery.isSuccess && !serverStatusQuery.isError)
|| serverStatusQuery.data?.State === 'Failed')
&& (
<Button onClick={() => handleStart()} buttonType="primary" className="w-64 py-2 font-semibold">
Start Server
Expand All @@ -84,8 +87,8 @@ function StartServer() {
</div>
</div>
<Footer
prevDisabled={serverStatusQuery.data?.State !== 4}
nextDisabled={serverStatusQuery.data?.State !== 2}
prevDisabled={serverStatusQuery.data?.State !== 'Failed'}
nextDisabled={serverStatusQuery.data?.State !== 'Started'}
saveFunction={handleNext}
/>
</TransitionDiv>
Expand Down
18 changes: 10 additions & 8 deletions src/pages/login/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ function LoginPage() {

useEffect(() => {
if (!serverStatusQuery.data) setPollingInterval(500);
else if (serverStatusQuery.data?.State !== 1) setPollingInterval(0);
else if (serverStatusQuery.data?.State !== 'Starting') setPollingInterval(0);

if (serverStatusQuery.data?.State === 2 && apiSession.apikey !== '') {
if (serverStatusQuery.data?.State === 'Started' && apiSession.apikey !== '') {
navigate(searchParams.get('redirectTo') ?? '/webui', { replace: true });
}
}, [serverStatusQuery.data, apiSession, navigate, searchParams]);
Expand Down Expand Up @@ -146,7 +146,7 @@ function LoginPage() {
<Icon path={mdiLoading} spin className="text-panel-text-primary" size={4} />
</div>
)}
{serverStatusQuery.data?.State === 1 && (
{serverStatusQuery.data?.State === 'Starting' && (
<div className="flex flex-col items-center justify-center gap-y-2">
<Icon path={mdiLoading} spin className="text-panel-text-primary" size={4} />
<div className="mt-2 text-xl font-semibold">Server is starting. Please wait!</div>
Expand All @@ -156,7 +156,7 @@ function LoginPage() {
</div>
</div>
)}
{serverStatusQuery.data?.State === 2 && (
{serverStatusQuery.data?.State === 'Started' && (
<form onSubmit={handleSignIn} className="flex flex-col gap-y-6">
<Input
autoFocus
Expand All @@ -165,15 +165,17 @@ function LoginPage() {
label="Username"
type="text"
placeholder="Username"
onChange={event => setUsername(event.target.value)}
onChange={event =>
setUsername(event.target.value)}
/>
<Input
id="password"
value={password}
label="Password"
type="password"
placeholder="Password"
onChange={event => setPassword(event.target.value)}
onChange={event =>
setPassword(event.target.value)}
/>
<Checkbox
id="rememberUser"
Expand All @@ -195,7 +197,7 @@ function LoginPage() {
</Button>
</form>
)}
{serverStatusQuery.data?.State === 3 && (
{serverStatusQuery.data?.State === 'Failed' && (
<div className="flex max-h-80 flex-col items-center justify-center gap-y-2 pb-2">
<Icon path={mdiCloseCircleOutline} className="shrink-0 text-panel-text-warning" size={4} />
<div className="mt-2 text-xl font-semibold">Server startup failed!</div>
Expand All @@ -205,7 +207,7 @@ function LoginPage() {
</div>
</div>
)}
{serverStatusQuery.data?.State === 4 && (
{serverStatusQuery.data?.State === 'Waiting' && (
<div className="flex flex-col gap-y-6">
<div className="flex flex-col gap-y-4">
<div>Welcome, and thank you for installing Shoko!</div>
Expand Down
6 changes: 1 addition & 5 deletions src/pages/utilities/ReleaseManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
import { invalidateQueries, resetQueries } from '@/core/react-query/queryClient';
import { ReleaseManagementItemType } from '@/core/react-query/release-management/types';
import useEventCallback from '@/hooks/useEventCallback';
import useIsFeatureSupported, { FeatureType } from '@/hooks/useIsFeatureSupported';

import type { ReleaseManagementOptionsType } from '@/components/Utilities/constants';
import type { EpisodeType } from '@/core/types/api/episode';
Expand Down Expand Up @@ -135,8 +134,6 @@ const ReleaseManagement = () => {
});
});

const isQuickSelectSupported = useIsFeatureSupported(FeatureType.ReleaseManagementQuickSelect);

return (
<>
<title>{`${titleMap[type]} | Shoko`}</title>
Expand Down Expand Up @@ -200,9 +197,8 @@ const ReleaseManagement = () => {
<Button
buttonType="secondary"
className="flex gap-x-2.5 px-4 py-3 font-semibold"
disabled={!selectedSeries || !isQuickSelectSupported}
disabled={!selectedSeries}
onClick={toggleShowQuickSelectModal}
tooltip={isQuickSelectSupported ? '' : 'Only supported on server version >=5.1.0.6'}
>
<Icon path={mdiSelectMultiple} size={0.8333} />
Quick Select
Expand Down

0 comments on commit 926e82f

Please sign in to comment.