Skip to content

Commit

Permalink
Fix update of conflicting files
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFlashAccount committed Sep 17, 2024
1 parent a753352 commit 2a61273
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
15 changes: 5 additions & 10 deletions app/dashboard/src/components/dashboard/AssetRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as setAssetHooks from '#/hooks/setAssetHooks'

import {
useDriveStore,
useNewestFolderId,
useSetAssetPanelProps,
useSetIsAssetPanelTemporarilyVisible,
useSetSelectedKeys,
Expand Down Expand Up @@ -161,16 +160,12 @@ export const AssetRow = React.memo(function AssetRow(props: AssetRowProps) {
const grabKeyboardFocusRef = useSyncRef(grabKeyboardFocus)
const asset = item.item
const [insertionVisibility, setInsertionVisibility] = React.useState(Visibility.visible)
const [innerRowState, setRowState] = React.useState<assetsTable.AssetRowState>(() =>
object.merge(assetRowUtils.INITIAL_ROW_STATE, { setVisibility: setInsertionVisibility }),
const [rowState, setRowState] = React.useState<assetsTable.AssetRowState>(() =>
object.merge(assetRowUtils.INITIAL_ROW_STATE, {
setVisibility: setInsertionVisibility,
isEditingName: driveStore.getState().newestFolderId === asset.id,
}),
)

const isEditingName = useNewestFolderId() === asset.id

const rowState = React.useMemo(() => {
return object.merge(innerRowState, { isEditingName })
}, [isEditingName, innerRowState])

const nodeParentKeysRef = React.useRef<{
readonly nodeMap: WeakRef<ReadonlyMap<backendModule.AssetId, assetTreeNode.AnyAssetTreeNode>>
readonly parentKeys: Map<backendModule.AssetId, backendModule.DirectoryId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ export default function DirectoryNameColumn(props: DirectoryNameColumnProps) {
if (isEditable) {
setRowState(object.merger({ isEditingName }))
}

if (!isEditingName) {
driveStore.setState({ newestFolderId: null })
}
}

const doRename = async (newTitle: string) => {
Expand Down
15 changes: 8 additions & 7 deletions app/dashboard/src/layouts/AssetsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1853,13 +1853,14 @@ export default function AssetsTable(props: AssetsTableProps) {

const asset = isUpdating ? conflict.current : conflict.new

fileMap.set(
asset.id,
new File([conflict.file], asset.title, {
type: conflict.file.type,
lastModified: conflict.file.lastModified,
}),
)
const renamedFile = new File([conflict.file], asset.title, {
type: conflict.file.type,
lastModified: conflict.file.lastModified,
})

renamedFile.path = conflict.file.path

fileMap.set(asset.id, renamedFile)

insertAssets([asset], event.parentId)
void doUploadFile(asset, isUpdating ? 'update' : 'new')
Expand Down

0 comments on commit 2a61273

Please sign in to comment.