Skip to content

Commit

Permalink
Switch publicAlbums to collections helpers and improve typing
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Feb 28, 2023
1 parent 4309168 commit f23dacf
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 328 deletions.
17 changes: 11 additions & 6 deletions src/mixins/FetchCollectionContentMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ export default {
]),
/**
* @param {string} collectionFileName
* @param {string[]} extraProps - Extra properties to add to the DAV request.
* @param {string[]} [extraProps] - Extra properties to add to the DAV request.
* @param {import('webdav').WebDAVClient} [client] - The DAV client to use.
* @return {Promise<import('../services/collectionFetcher.js').Collection|null>}
*/
async fetchCollection(collectionFileName, extraProps) {
async fetchCollection(collectionFileName, extraProps, client) {
if (this.loadingCollection) {
return null
}
Expand All @@ -68,7 +69,7 @@ export default {
this.loadingCollection = true
this.errorFetchingCollection = null

const collection = await fetchCollection(collectionFileName, { signal: this.abortController.signal }, extraProps)
const collection = await fetchCollection(collectionFileName, { signal: this.abortController.signal }, extraProps, client)
this.addCollections({ collections: [collection] })
return collection
} catch (error) {
Expand All @@ -89,10 +90,12 @@ export default {

/**
* @param {string} collectionFileName
* @param {string[]} extraProps - Extra properties to add to the DAV request.
* @param {string[]} [extraProps] - Extra properties to add to the DAV request.
* @param {import('webdav').WebDAVClient} [client] - The DAV client to use.
* @param {((value: import('../services/collectionFetcher.js').CollectionFile, index: number, array: import('../services/collectionFetcher.js').CollectionFile[]) => any)[]} [mappers] - Callback that can transform files before they are appended.
* @return {Promise<import('../services/collectionFetcher.js').CollectionFile[]>}
*/
async fetchCollectionFiles(collectionFileName, extraProps = []) {
async fetchCollectionFiles(collectionFileName, extraProps, client, mappers = []) {
if (this.loadingCollectionFiles) {
return []
}
Expand All @@ -105,9 +108,11 @@ export default {
this.loadingCollectionFiles = true
this.semaphoreSymbol = semaphoreSymbol

const fetchedFiles = await fetchCollectionFiles(collectionFileName, { signal: this.abortController.signal }, extraProps)
let fetchedFiles = await fetchCollectionFiles(collectionFileName, { signal: this.abortController.signal }, extraProps, client)
const fileIds = fetchedFiles.map(file => file.fileid.toString())

mappers.forEach(mapper => (fetchedFiles = fetchedFiles.map(mapper)))

this.appendFiles(fetchedFiles)

if (fetchedFiles.length > 0) {
Expand Down
7 changes: 4 additions & 3 deletions src/mixins/FetchCollectionsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ export default {

/**
* @param {string} collectionHome
* @param {string[]} extraProps - Extra properties to add to the DAV request.
* @param {string[]} [extraProps] - Extra properties to add to the DAV request.
* @param {import('webdav').WebDAVClient} [client] - The DAV client to use.
* @return {Promise<import('../services/collectionFetcher.js').Collection[]>}
*/
async fetchCollections(collectionHome, extraProps = []) {
async fetchCollections(collectionHome, extraProps, client) {
if (this.loadingCollections) {
return []
}
Expand All @@ -58,7 +59,7 @@ export default {
this.loadingCollections = true
this.errorFetchingCollections = null

const collections = await fetchCollections(collectionHome, { signal: this.abortController.signal }, extraProps)
const collections = await fetchCollections(collectionHome, { signal: this.abortController.signal }, extraProps, client)

this.addCollections({ collections })

Expand Down
211 changes: 0 additions & 211 deletions src/store/collectionStoreFactory.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import Vuex, { Store } from 'vuex'

import files from './files.js'
import albums from './albums.js'
import publicAlbums from './publicAlbums.js'
import sharedAlbums from './sharedAlbums.js'
import collections from './collections.js'
import places from './places.js'
import faces from './faces.js'
import folders from './folders.js'
import systemtags from './systemtags.js'
import collectionStoreFactory from './collectionStoreFactory.js'

Vue.use(Vuex)
export default new Store({
Expand All @@ -40,9 +40,9 @@ export default new Store({
folders,
albums,
sharedAlbums,
publicAlbums,
faces,
systemtags,
publicAlbums: collectionStoreFactory('publicAlbum'),
collections,
places,
},
Expand Down
41 changes: 41 additions & 0 deletions src/store/publicAlbums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @copyright Copyright (c) 2022 Louis Chemineau <louis@chmn.me>
*
* @author Louis Chemineau <louis@chmn.me>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* @typedef {object} _PublicAlbum
* @property {string} originalName - The original name of the album.
* @property {string} location - The user set location of the album.
*
* @typedef {import("../services/collectionFetcher").Collection&_PublicAlbum} PublicAlbum
*
* @typedef {Object<string, PublicAlbum>} IndexedPublicAlbums
*/

const publicAlbumsPrefix = '/photospublic/'

const getters = {
publicAlbums: (_, __, ___, rootGetters) => rootGetters.collectionsWithPrefix(publicAlbumsPrefix),
getPublicAlbum: (_, __, rootState) => publicAlbumName => rootState.collections.collections[`${publicAlbumsPrefix}${publicAlbumName}`] || null,
getPublicAlbumFiles: (_, __, rootState) => publicAlbumName => rootState.collections.collectionsFiles[`${publicAlbumsPrefix}${publicAlbumName}`] || [],
getPublicAlbumName: (_, __, ___) => publicAlbumName => `${publicAlbumsPrefix}${publicAlbumName}`,
}
export default { getters }
Loading

0 comments on commit f23dacf

Please sign in to comment.