sync media cache after file renames

This commit is contained in:
ngfchl
2026-07-18 21:03:03 +08:00
parent b505be1da8
commit a3a9ab9c8d
5 changed files with 153 additions and 9 deletions
+19 -2
View File
@@ -1407,7 +1407,14 @@ class _PrimaryFilePane extends ConsumerWidget {
onOpen: file.isDirectory
? () => notifier.navigateToFolder(file)
: () => _openCloudFile(context, ref, file),
onRenameConfirm: (name) => notifier.renameFile(file, name),
onRenameConfirm: (name) async {
final renamed = await notifier.renameFile(file, name);
if (renamed) {
await ref
.read(mediaLibraryProvider.notifier)
.synchronizeRenamedFiles([file.copyWith(name: name)]);
}
},
onCopy: () => notifier.copyToClipboard([file]),
onCut: () => notifier.cutToClipboard([file]),
onDownload: () => notifier.downloadFile(file),
@@ -2066,6 +2073,9 @@ class _ColumnFileBrowserState extends ConsumerState<_ColumnFileBrowser> {
controller.dispose();
if (newName == null || newName.isEmpty || newName == file.name) return;
await ref.read(authProvider.notifier).api.fsRename(file.id, newName);
await ref.read(mediaLibraryProvider.notifier).synchronizeRenamedFiles([
file.copyWith(name: newName),
]);
final affected = <int>{};
for (var index = 0; index < _columns.length; index++) {
if (_columns[index].files.any((item) => item.id == file.id)) {
@@ -3086,7 +3096,14 @@ class _SecondaryFilePaneState extends ConsumerState<_SecondaryFilePane> {
onCut: () =>
ref.read(fileProvider.notifier).cutToClipboard([file]),
onRenameConfirm: (name) async {
await ref.read(fileProvider.notifier).renameFile(file, name);
final renamed = await ref
.read(fileProvider.notifier)
.renameFile(file, name);
if (renamed) {
await ref
.read(mediaLibraryProvider.notifier)
.synchronizeRenamedFiles([file.copyWith(name: name)]);
}
if (!mounted) return;
setState(() {
_files = _files