mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-09 04:56:45 +03:00
refactor: remove problematic useEffect to prevent circular dependencies and optimize user data fetching
This commit is contained in:
@@ -68,26 +68,8 @@ export function ConfigTabs() {
|
|||||||
return isGitHubValid && isGiteaValid;
|
return isGitHubValid && isGiteaValid;
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
// Removed the problematic useEffect that was causing circular dependencies
|
||||||
const updateLastAndNextRun = () => {
|
// The lastRun and nextRun should be managed by the backend and fetched via API
|
||||||
const lastRun = config.scheduleConfig.lastRun
|
|
||||||
? new Date(config.scheduleConfig.lastRun)
|
|
||||||
: new Date();
|
|
||||||
const intervalInSeconds = config.scheduleConfig.interval;
|
|
||||||
const nextRun = new Date(
|
|
||||||
lastRun.getTime() + intervalInSeconds * 1000,
|
|
||||||
);
|
|
||||||
setConfig(prev => ({
|
|
||||||
...prev,
|
|
||||||
scheduleConfig: {
|
|
||||||
...prev.scheduleConfig,
|
|
||||||
lastRun,
|
|
||||||
nextRun,
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
updateLastAndNextRun();
|
|
||||||
}, [config.scheduleConfig.interval]);
|
|
||||||
|
|
||||||
const handleImportGitHubData = async () => {
|
const handleImportGitHubData = async () => {
|
||||||
if (!user?.id) return;
|
if (!user?.id) return;
|
||||||
@@ -182,7 +164,7 @@ export function ConfigTabs() {
|
|||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
// Silent success - no toast for auto-save
|
// Silent success - no toast for auto-save
|
||||||
await refreshUser();
|
// Removed refreshUser() call to prevent page reload
|
||||||
} else {
|
} else {
|
||||||
toast.error(
|
toast.error(
|
||||||
`Auto-save failed: ${result.message || 'Unknown error'}`,
|
`Auto-save failed: ${result.message || 'Unknown error'}`,
|
||||||
@@ -200,7 +182,7 @@ export function ConfigTabs() {
|
|||||||
setIsAutoSaving(false);
|
setIsAutoSaving(false);
|
||||||
}
|
}
|
||||||
}, 500); // 500ms debounce
|
}, 500); // 500ms debounce
|
||||||
}, [user?.id, isConfigSaved, config.githubConfig, config.giteaConfig, refreshUser]);
|
}, [user?.id, isConfigSaved, config.githubConfig, config.giteaConfig]);
|
||||||
|
|
||||||
// Cleanup timeout on unmount
|
// Cleanup timeout on unmount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -212,7 +194,7 @@ export function ConfigTabs() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!user) return;
|
if (!user?.id) return;
|
||||||
|
|
||||||
const fetchConfig = async () => {
|
const fetchConfig = async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
@@ -242,7 +224,7 @@ export function ConfigTabs() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchConfig();
|
fetchConfig();
|
||||||
}, [user]);
|
}, [user?.id]); // Only depend on user.id, not the entire user object
|
||||||
|
|
||||||
function ConfigCardSkeleton() {
|
function ConfigCardSkeleton() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user