@@ -37,29 +37,29 @@ import { getAssociatedCollections } from '$lib/services/contents/entry';
3737 * Update the asset and entry stores after moving or renaming assets.
3838 * @param {object } args Arguments.
3939 * @param {'move' | 'rename' } args.action The action performed, either 'move' or 'rename'.
40- * @param {MovingAsset[] } args.movingAssets The list of assets being moved or renamed.
41- * @param {Asset[] } args.savingAssets The updated asset objects to be saved in the store .
42- * @param {Entry[] } args.savingEntries The updated entry objects to be saved in the store .
40+ * @param {MovingAsset[] } args.movedAssets The assets that have been moved or renamed.
41+ * @param {Asset[] } args.savedAssets The assets that have been saved.
42+ * @param {Entry[] } args.savedEntries The entries that have been saved.
4343 */
44- const updateStores = ( { action, movingAssets , savingAssets , savingEntries } ) => {
45- const savingAssetsPaths = movingAssets . map ( ( a ) => a . asset . path ) ; // old paths
46- const savingEntryIds = savingEntries . map ( ( e ) => e . id ) ;
44+ const updateStores = ( { action, movedAssets , savedAssets , savedEntries } ) => {
45+ const savedAssetsPaths = movedAssets . map ( ( a ) => a . asset . path ) ; // old paths
46+ const savedEntryIds = savedEntries . map ( ( e ) => e . id ) ;
4747
4848 allAssets . update ( ( assets ) => [
49- ...assets . filter ( ( a ) => ! savingAssetsPaths . includes ( a . path ) ) ,
50- ...savingAssets ,
49+ ...assets . filter ( ( a ) => ! savedAssetsPaths . includes ( a . path ) ) ,
50+ ...savedAssets ,
5151 ] ) ;
5252
5353 allEntries . update ( ( entries ) => [
54- ...entries . filter ( ( e ) => ! savingEntryIds . includes ( e . id ) ) ,
55- ...savingEntries ,
54+ ...entries . filter ( ( e ) => ! savedEntryIds . includes ( e . id ) ) ,
55+ ...savedEntries ,
5656 ] ) ;
5757
5858 const _allAssets = get ( allAssets ) ;
5959 const focusedAssetPath = get ( focusedAsset ) ?. path ;
60- const _focusedAsset = movingAssets . find ( ( a ) => a . asset . path === focusedAssetPath ) ;
60+ const _focusedAsset = movedAssets . find ( ( a ) => a . asset . path === focusedAssetPath ) ;
6161 const overlaidAssetPath = get ( overlaidAsset ) ?. path ;
62- const _overlaidAsset = movingAssets . find ( ( a ) => a . asset . path === overlaidAssetPath ) ;
62+ const _overlaidAsset = movedAssets . find ( ( a ) => a . asset . path === overlaidAssetPath ) ;
6363
6464 // Replace the existing asset
6565 if ( _focusedAsset ) {
@@ -75,7 +75,7 @@ const updateStores = ({ action, movingAssets, savingAssets, savingEntries }) =>
7575 ...UPDATE_TOAST_DEFAULT_STATE ,
7676 moved : action === 'move' ,
7777 renamed : action === 'rename' ,
78- count : movingAssets . length ,
78+ count : movedAssets . length ,
7979 } ) ;
8080} ;
8181
@@ -214,14 +214,15 @@ export const moveAssets = async (action, movingAssets) => {
214214
215215 const results = await get ( backend ) ?. commitChanges ( changes , { commitType : 'uploadMedia' } ) ;
216216
217- // Update blob URLs for the local backend
218- if ( Array . isArray ( results ) ) {
219- savingAssets . forEach ( ( asset , index ) => {
220- if ( results [ index ] instanceof File ) {
221- asset . blobURL = URL . createObjectURL ( /** @type {File } */ ( results [ index ] ) ) ;
222- }
223- } ) ;
224- }
217+ updateStores ( {
218+ action,
219+ movedAssets : [ ...movingAssets ] ,
220+ savedAssets : savingAssets . map ( ( asset , index ) => {
221+ const result = results ?. [ index ] ;
222+ const blobURL = result instanceof File ? URL . createObjectURL ( result ) : undefined ;
225223
226- updateStores ( { action, movingAssets, savingAssets, savingEntries } ) ;
224+ return { ...asset , blobURL } ;
225+ } ) ,
226+ savedEntries : [ ...savingEntries ] ,
227+ } ) ;
227228} ;
0 commit comments