Collections #383

Merged
jessopb merged 20 commits from collections into master 2021-06-08 17:51:49 +02:00
6 changed files with 47 additions and 35 deletions
Showing only changes of commit 211266cdd8 - Show all commits

View file

@ -37,4 +37,5 @@ declare type CollectionEditParams = {
infinite-persistence commented 2021-06-04 14:08:06 +02:00 (Migrated from github.com)
Review

typo?

typo?
infinite-persistence commented 2021-06-04 14:08:06 +02:00 (Migrated from github.com)
Review

typo?

typo?
replace?: boolean,
order?: { from: number, to: number },
type?: string,
name?: string,
infinite-persistence commented 2021-06-04 14:08:06 +02:00 (Migrated from github.com)
Review

typo?

typo?
}

infinite-persistence commented 2021-06-04 14:08:06 +02:00 (Migrated from github.com)
Review

typo?

typo?
infinite-persistence commented 2021-06-04 14:08:06 +02:00 (Migrated from github.com)
Review

typo?

typo?

View file

@ -179,6 +179,7 @@ export {
makeSelectNameForCollectionId,
makeSelectIsResolvingCollectionForId,
makeSelectNextUrlForCollection,
makeSelectCollectionForIdHasClaimUrl,
} from 'redux/selectors/collections';
export {

View file

@ -8,6 +8,7 @@ import {
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
makeSelectCollectionForId,
// makeSelectPublishedCollectionForId, // for "save" or "copy" action
makeSelectMyPublishedCollectionForId,
infinite-persistence commented 2021-06-04 14:19:23 +02:00 (Migrated from github.com)
Review

Unused

Unused
makeSelectPublishedCollectionForId,
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
makeSelectUnpublishedCollectionForId,
makeSelectEditedCollectionForId,
} from 'redux/selectors/collections';
@ -24,6 +25,7 @@ const getTimestamp = () => {
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
export const doLocalCollectionCreate = (
name: string,
collectionItems: string,
type: string,
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
sourceId: string
) => (dispatch: Dispatch) => {
return dispatch({
@ -35,6 +37,7 @@ export const doLocalCollectionCreate = (
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
updatedAt: getTimestamp(),
items: collectionItems || [],
sourceId: sourceId,
type: type || 'collection',
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
},
},
});
@ -79,7 +82,7 @@ export const doFetchItemsInCollections = (
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
pageSize?: number,
},
resolveStartedCallback?: () => void
) => async (dispatch: Dispatch, getState: GetState) => {
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
) => async(dispatch: Dispatch, getState: GetState) => {
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
let state = getState();
// for each collection id,
// make sure the collection is resolved, the items are resolved, and build the collection objects
@ -284,7 +287,7 @@ export const doFetchItemsInCollection = (
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
return doFetchItemsInCollections(newOptions, cb);
};
export const doCollectionEdit = (collectionId: string, params: CollectionEditParams) => async (
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
export const doCollectionEdit = (collectionId: string, params: CollectionEditParams) => async(
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
dispatch: Dispatch,
getState: GetState
) => {
@ -294,7 +297,7 @@ export const doCollectionEdit = (collectionId: string, params: CollectionEditPar
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
const unpublishedCollection: Collection = makeSelectUnpublishedCollectionForId(collectionId)(
state
);
const publishedCollection: Collection = makeSelectMyPublishedCollectionForId(collectionId)(state);
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
const publishedCollection: Collection = makeSelectPublishedCollectionForId(collectionId)(state); // needs to be published only
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
const generateCollectionItemsFromSearchResult = results => {
return (
@ -383,8 +386,11 @@ export const doCollectionEdit = (collectionId: string, params: CollectionEditPar
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
currentItems.splice(order.to, 0, movedItem);
}
// console.log('p&e', publishedCollection.items, newItems, publishedCollection.items.join(','), newItems.join(','))
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
if (editedCollection) {
if (publishedCollection.items.join(',') === newItems.join(',')) {
// print these
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
// delete edited if newItems are the same as publishedItems
dispatch({
type: ACTIONS.COLLECTION_DELETE,

jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >

View file

@ -26,7 +26,6 @@ export const buildSharedStateMiddleware = (
clearTimeout(timeout);
const actionResult = next(action);
// Call `getState` after calling `next` to ensure the state has updated in response to the action
function runPreferences() {
const nextState: { user: any, settings: any } = getState();
const syncEnabled =

View file

@ -69,7 +69,12 @@ const collectionsReducer = handleActions(
const newPendingList = Object.assign({}, pendingList);
if (collectionKey && state[collectionKey] && state[collectionKey][id]) {
delete state[collectionKey][id];
const newList = Object.assign({}, state[collectionKey]);
delete newList[id];
return {
...state,
[collectionKey]: newList,
};
} else {
if (newEditList[id]) {
delete newEditList[id];
@ -178,40 +183,38 @@ const collectionsReducer = handleActions(
},
[ACTIONS.COLLECTION_ITEMS_RESOLVE_COMPLETED]: (state, action) => {
const { resolvedCollections, failedCollectionIds } = action.data;
const {
pending: pendingList,
edited: editList,
isResolvingCollectionById,
resolved: lists,
} = state;
const { pending, edited, isResolvingCollectionById, resolved } = state;
const newPending = Object.assign({}, pending);
const newEdited = Object.assign({}, edited);
const newResolved = Object.assign({}, resolved, resolvedCollections);
const resolvedIds = Object.keys(resolvedCollections);
const newResolving = Object.assign({}, isResolvingCollectionById);
if (resolvedCollections && resolvedCollections.length) {
if (resolvedCollections && Object.keys(resolvedCollections).length) {
resolvedIds.forEach(resolvedId => {
if (editList[resolvedId]) {
if (editList[resolvedId]['updatedAt'] < resolvedCollections[resolvedId]['updatedAt']) {
delete editList[resolvedId];
if (newEdited[resolvedId]) {
if (newEdited[resolvedId]['updatedAt'] < resolvedCollections[resolvedId]['updatedAt']) {
delete newEdited[resolvedId];
}
}
delete newResolving[resolvedId];
if (pendingList[resolvedId]) {
delete pendingList[resolvedId];
if (newPending[resolvedId]) {
delete newPending[resolvedId];
}
});
}
if (failedCollectionIds && failedCollectionIds.length) {
if (failedCollectionIds && Object.keys(failedCollectionIds).length) {
failedCollectionIds.forEach(failedId => {
delete newResolving[failedId];
});
}
const newLists = Object.assign({}, lists, resolvedCollections);
return Object.assign({}, state, {
...state,
pending: pendingList,
resolved: newLists,
pending: newPending,
resolved: newResolved,
edited: newEdited,
isResolvingCollectionById: newResolving,
});
},

View file

@ -68,7 +68,6 @@ export const makeSelectCollectionIsMine = (id: string) =>
}
);
// for library page, we want all published
export const selectMyPublishedCollections = createSelector(
selectResolvedCollections,
selectPendingCollections,
@ -78,21 +77,18 @@ export const selectMyPublishedCollections = createSelector(
// all resolved in myIds, plus those in pending and edited
const myPublishedCollections = Object.fromEntries(
Object.entries(pending).concat(
Object.entries(edited)
.filter(
([key, val]) => myIds.includes(key)
Object.entries(resolved).filter(
([key, val]) =>
myIds.includes(key) &&
// $FlowFixMe
)
.concat(
Object.entries(resolved).filter(
([key, val]) =>
myIds.includes(key) &&
// $FlowFixMe
(!pending[key] && !edited[key])
)
)
!pending[key]
)
)
);
// now add in edited:
Object.entries(edited).forEach(([id, item]) => {
myPublishedCollections[id] = item;
});
return myPublishedCollections;
}
);
@ -163,6 +159,12 @@ export const makeSelectCollectionForId = (id: string) =>
}
);
export const makeSelectCollectionForIdHasClaimUrl = (id: string, url: string) =>
createSelector(
makeSelectCollectionForId(id),
collection => collection.items.includes(url)
);
export const makeSelectUrlsForCollectionId = (id: string) =>
createSelector(
makeSelectCollectionForId(id),