mirror of
https://github.com/jeffvli/feishin.git
synced 2026-07-23 02:46:40 +02:00
more potential fixes for server lock duplication
This commit is contained in:
@@ -2,12 +2,11 @@ import { useEffect, useMemo } from 'react';
|
||||
import { Navigate, Outlet } from 'react-router';
|
||||
import { shallow } from 'zustand/shallow';
|
||||
|
||||
import { normalizeServerUrl } from '/@/renderer/features/action-required/utils/server-lock';
|
||||
import { isServerLock } from '/@/renderer/features/action-required/utils/window-properties';
|
||||
import { AppRoute } from '/@/renderer/router/routes';
|
||||
import { useAuthStore, useAuthStoreActions } from '/@/renderer/store';
|
||||
|
||||
const normalizeUrl = (url: string) => url.replace(/\/$/, '');
|
||||
|
||||
export const AppOutlet = () => {
|
||||
const currentServer = useAuthStore(
|
||||
(state) =>
|
||||
@@ -19,25 +18,27 @@ export const AppOutlet = () => {
|
||||
: null,
|
||||
shallow,
|
||||
);
|
||||
const { deleteServer, setCurrentServer } = useAuthStoreActions();
|
||||
const { setCurrentServer, updateServer } = useAuthStoreActions();
|
||||
|
||||
const hasServerLockMismatch = useMemo(() => {
|
||||
if (!isServerLock() || !currentServer || !window.SERVER_URL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const configuredUrl = normalizeUrl(window.SERVER_URL);
|
||||
const persistedUrl = normalizeUrl(currentServer.url);
|
||||
const configuredUrl = normalizeServerUrl(window.SERVER_URL);
|
||||
const persistedUrl = normalizeServerUrl(currentServer.url);
|
||||
|
||||
return configuredUrl !== persistedUrl;
|
||||
}, [currentServer]);
|
||||
|
||||
useEffect(() => {
|
||||
if (hasServerLockMismatch && currentServer) {
|
||||
deleteServer(currentServer.id);
|
||||
if (hasServerLockMismatch && currentServer && window.SERVER_URL) {
|
||||
updateServer(currentServer.id, {
|
||||
url: normalizeServerUrl(window.SERVER_URL),
|
||||
});
|
||||
setCurrentServer(null);
|
||||
}
|
||||
}, [currentServer, deleteServer, hasServerLockMismatch, setCurrentServer]);
|
||||
}, [currentServer, hasServerLockMismatch, setCurrentServer, updateServer]);
|
||||
|
||||
const isActionsRequired = !currentServer || hasServerLockMismatch;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user