feat(web): add Favorites page (#1397)

* Duplicate photos page and rename to favorites

* Implement basic functionality to page

* Sort imports

* Add missing sharing code

* Remove unused import

* Fix formatting

* Use GalleryViewer and new api endpoint

* Merge useFavorites into page

* Run prettier

* Move favorites in side-bar

* Remove favorites when unfavorited

* Fix close shared link model

* Add favorite count to side-bar

* Add add to favorites option

* Fix formatting

* Add favorite icon to image thumbnails

* Change var to let
This commit is contained in:
James
2023-01-27 09:32:26 -05:00
committed by GitHub
parent d377cf0d02
commit de0e218440
10 changed files with 312 additions and 47 deletions

View File

@@ -1,8 +1,8 @@
import { writable } from 'svelte/store';
import lodash from 'lodash-es';
import { api, AssetCountByTimeBucketResponseDto } from '@api';
import { AssetGridState } from '$lib/models/asset-grid-state';
import { calculateViewportHeightByNumberOfAsset } from '$lib/utils/viewport-utils';
import { api, AssetCountByTimeBucketResponseDto } from '@api';
import lodash from 'lodash-es';
import { writable } from 'svelte/store';
/**
* The state that holds information about the asset grid
@@ -141,12 +141,24 @@ function createAssetStore() {
});
};
const updateAsset = (assetId: string, isFavorite: boolean) => {
assetGridState.update((state) => {
const bucketIndex = state.buckets.findIndex((b) => b.assets.some((a) => a.id === assetId));
const assetIndex = state.buckets[bucketIndex].assets.findIndex((a) => a.id === assetId);
state.buckets[bucketIndex].assets[assetIndex].isFavorite = isFavorite;
state.assets = lodash.flatMap(state.buckets, (b) => b.assets);
return state;
});
};
return {
setInitialState,
getAssetsByBucket,
removeAsset,
updateBucketHeight,
cancelBucketRequest
cancelBucketRequest,
updateAsset
};
}