refactor: simplify upload rules and remove destination flow
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
import { useState, useRef, useCallback } from 'react'
|
||||
import type { Destination } from '@/lib/constants'
|
||||
import type { FolderEntry } from '@/lib/client-types'
|
||||
import type { FileDiff } from '@/lib/types'
|
||||
import { checkFolderDiffs, uploadDrive, uploadGit } from '@/lib/upload-api'
|
||||
@@ -28,7 +27,6 @@ export function useUploadOrchestrator({
|
||||
}: UseUploadOrchestratorParams) {
|
||||
const [isUploading, setIsUploading] = useState(false)
|
||||
const [globalError, setGlobalError] = useState<string | null>(null)
|
||||
const [destination, setDestination] = useState<Destination | null>(null)
|
||||
const [overwriteConfirm, setOverwriteConfirm] = useState<{
|
||||
folderName: string
|
||||
diffs: FileDiff[]
|
||||
@@ -45,20 +43,16 @@ export function useUploadOrchestrator({
|
||||
// Refs for values used inside callbacks to avoid stale closures
|
||||
const secretRef = useRef(secret)
|
||||
secretRef.current = secret
|
||||
const destinationRef = useRef(destination)
|
||||
destinationRef.current = destination
|
||||
const entriesRef = useRef(entries)
|
||||
entriesRef.current = entries
|
||||
|
||||
// ---- Internal: push a single folder to Git ----
|
||||
const pushGit = useCallback(async (index: number, signal?: AbortSignal) => {
|
||||
const folderEntry = entriesRef.current[index]
|
||||
const dest = destinationRef.current
|
||||
|
||||
const gitResult = await uploadGit(
|
||||
folderEntry,
|
||||
secretRef.current,
|
||||
dest!,
|
||||
(pct) => updateEntry(index, { progress: 50 + Math.round(pct / 2) }),
|
||||
signal,
|
||||
)
|
||||
@@ -101,7 +95,6 @@ export function useUploadOrchestrator({
|
||||
const driveResult = await uploadDrive(
|
||||
folderEntry,
|
||||
secretRef.current,
|
||||
destinationRef.current!,
|
||||
driveAction as 'new' | 'replace',
|
||||
controller.signal,
|
||||
)
|
||||
@@ -129,10 +122,6 @@ export function useUploadOrchestrator({
|
||||
setSecretError("La cle d'acces est requise")
|
||||
return
|
||||
}
|
||||
if (!destinationRef.current) {
|
||||
setGlobalError('Veuillez choisir une destination')
|
||||
return
|
||||
}
|
||||
if (entriesRef.current.length === 0) return
|
||||
|
||||
setSecretError(null)
|
||||
@@ -143,7 +132,6 @@ export function useUploadOrchestrator({
|
||||
try {
|
||||
const check = await checkFolderDiffs(
|
||||
folder,
|
||||
destinationRef.current,
|
||||
secretRef.current,
|
||||
abortRef.current?.signal,
|
||||
)
|
||||
@@ -230,8 +218,6 @@ export function useUploadOrchestrator({
|
||||
isUploading,
|
||||
globalError,
|
||||
setGlobalError,
|
||||
destination,
|
||||
setDestination,
|
||||
overwriteConfirm,
|
||||
setOverwriteConfirm,
|
||||
noChangesFolder,
|
||||
|
||||
Reference in New Issue
Block a user