Collections #383
1
dist/flow-typed/Collections.js
vendored
|
@ -37,4 +37,5 @@ declare type CollectionEditParams = {
|
||||||
typo? typo?
|
|||||||
replace?: boolean,
|
replace?: boolean,
|
||||||
order?: { from: number, to: number },
|
order?: { from: number, to: number },
|
||||||
type?: string,
|
type?: string,
|
||||||
|
name?: string,
|
||||||
typo? typo?
|
|||||||
}
|
}
|
||||||
|
|
||||||
typo? typo?
typo? typo?
|
|
@ -179,6 +179,7 @@ export {
|
||||||
makeSelectNameForCollectionId,
|
makeSelectNameForCollectionId,
|
||||||
makeSelectIsResolvingCollectionForId,
|
makeSelectIsResolvingCollectionForId,
|
||||||
makeSelectNextUrlForCollection,
|
makeSelectNextUrlForCollection,
|
||||||
|
makeSelectCollectionForIdHasClaimUrl,
|
||||||
} from 'redux/selectors/collections';
|
} from 'redux/selectors/collections';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
makeSelectCollectionForId,
|
makeSelectCollectionForId,
|
||||||
// makeSelectPublishedCollectionForId, // for "save" or "copy" action
|
// makeSelectPublishedCollectionForId, // for "save" or "copy" action
|
||||||
makeSelectMyPublishedCollectionForId,
|
makeSelectMyPublishedCollectionForId,
|
||||||
Unused Unused
|
|||||||
|
makeSelectPublishedCollectionForId,
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
makeSelectUnpublishedCollectionForId,
|
makeSelectUnpublishedCollectionForId,
|
||||||
makeSelectEditedCollectionForId,
|
makeSelectEditedCollectionForId,
|
||||||
} from 'redux/selectors/collections';
|
} from 'redux/selectors/collections';
|
||||||
|
@ -24,6 +25,7 @@ const getTimestamp = () => {
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
export const doLocalCollectionCreate = (
|
export const doLocalCollectionCreate = (
|
||||||
name: string,
|
name: string,
|
||||||
collectionItems: string,
|
collectionItems: string,
|
||||||
|
type: string,
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
sourceId: string
|
sourceId: string
|
||||||
) => (dispatch: Dispatch) => {
|
) => (dispatch: Dispatch) => {
|
||||||
return dispatch({
|
return dispatch({
|
||||||
|
@ -35,6 +37,7 @@ export const doLocalCollectionCreate = (
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
updatedAt: getTimestamp(),
|
updatedAt: getTimestamp(),
|
||||||
items: collectionItems || [],
|
items: collectionItems || [],
|
||||||
sourceId: sourceId,
|
sourceId: sourceId,
|
||||||
|
type: type || 'collection',
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -79,7 +82,7 @@ export const doFetchItemsInCollections = (
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
pageSize?: number,
|
pageSize?: number,
|
||||||
},
|
},
|
||||||
resolveStartedCallback?: () => void
|
resolveStartedCallback?: () => void
|
||||||
) => async (dispatch: Dispatch, getState: GetState) => {
|
) => async(dispatch: Dispatch, getState: GetState) => {
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
let state = getState();
|
let state = getState();
|
||||||
// for each collection id,
|
// for each collection id,
|
||||||
// make sure the collection is resolved, the items are resolved, and build the collection objects
|
// make sure the collection is resolved, the items are resolved, and build the collection objects
|
||||||
|
@ -284,7 +287,7 @@ export const doFetchItemsInCollection = (
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
return doFetchItemsInCollections(newOptions, cb);
|
return doFetchItemsInCollections(newOptions, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const doCollectionEdit = (collectionId: string, params: CollectionEditParams) => async (
|
export const doCollectionEdit = (collectionId: string, params: CollectionEditParams) => async(
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
dispatch: Dispatch,
|
dispatch: Dispatch,
|
||||||
getState: GetState
|
getState: GetState
|
||||||
) => {
|
) => {
|
||||||
|
@ -294,7 +297,7 @@ export const doCollectionEdit = (collectionId: string, params: CollectionEditPar
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
const unpublishedCollection: Collection = makeSelectUnpublishedCollectionForId(collectionId)(
|
const unpublishedCollection: Collection = makeSelectUnpublishedCollectionForId(collectionId)(
|
||||||
state
|
state
|
||||||
);
|
);
|
||||||
const publishedCollection: Collection = makeSelectMyPublishedCollectionForId(collectionId)(state);
|
const publishedCollection: Collection = makeSelectPublishedCollectionForId(collectionId)(state); // needs to be published only
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
|
|
||||||
const generateCollectionItemsFromSearchResult = results => {
|
const generateCollectionItemsFromSearchResult = results => {
|
||||||
return (
|
return (
|
||||||
|
@ -383,8 +386,11 @@ export const doCollectionEdit = (collectionId: string, params: CollectionEditPar
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
currentItems.splice(order.to, 0, movedItem);
|
currentItems.splice(order.to, 0, movedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// console.log('p&e', publishedCollection.items, newItems, publishedCollection.items.join(','), newItems.join(','))
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
if (editedCollection) {
|
if (editedCollection) {
|
||||||
if (publishedCollection.items.join(',') === newItems.join(',')) {
|
if (publishedCollection.items.join(',') === newItems.join(',')) {
|
||||||
|
// print these
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
|
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
// delete edited if newItems are the same as publishedItems
|
// delete edited if newItems are the same as publishedItems
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.COLLECTION_DELETE,
|
type: ACTIONS.COLLECTION_DELETE,
|
||||||
|
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|
@ -26,7 +26,6 @@ export const buildSharedStateMiddleware = (
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
const actionResult = next(action);
|
const actionResult = next(action);
|
||||||
// Call `getState` after calling `next` to ensure the state has updated in response to the action
|
// Call `getState` after calling `next` to ensure the state has updated in response to the action
|
||||||
|
|
||||||
function runPreferences() {
|
function runPreferences() {
|
||||||
const nextState: { user: any, settings: any } = getState();
|
const nextState: { user: any, settings: any } = getState();
|
||||||
const syncEnabled =
|
const syncEnabled =
|
||||||
|
|
|
@ -69,7 +69,12 @@ const collectionsReducer = handleActions(
|
||||||
const newPendingList = Object.assign({}, pendingList);
|
const newPendingList = Object.assign({}, pendingList);
|
||||||
|
|
||||||
if (collectionKey && state[collectionKey] && state[collectionKey][id]) {
|
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 {
|
} else {
|
||||||
if (newEditList[id]) {
|
if (newEditList[id]) {
|
||||||
delete newEditList[id];
|
delete newEditList[id];
|
||||||
|
@ -178,40 +183,38 @@ const collectionsReducer = handleActions(
|
||||||
},
|
},
|
||||||
[ACTIONS.COLLECTION_ITEMS_RESOLVE_COMPLETED]: (state, action) => {
|
[ACTIONS.COLLECTION_ITEMS_RESOLVE_COMPLETED]: (state, action) => {
|
||||||
const { resolvedCollections, failedCollectionIds } = action.data;
|
const { resolvedCollections, failedCollectionIds } = action.data;
|
||||||
const {
|
const { pending, edited, isResolvingCollectionById, resolved } = state;
|
||||||
pending: pendingList,
|
const newPending = Object.assign({}, pending);
|
||||||
edited: editList,
|
const newEdited = Object.assign({}, edited);
|
||||||
isResolvingCollectionById,
|
const newResolved = Object.assign({}, resolved, resolvedCollections);
|
||||||
resolved: lists,
|
|
||||||
} = state;
|
|
||||||
const resolvedIds = Object.keys(resolvedCollections);
|
const resolvedIds = Object.keys(resolvedCollections);
|
||||||
const newResolving = Object.assign({}, isResolvingCollectionById);
|
const newResolving = Object.assign({}, isResolvingCollectionById);
|
||||||
if (resolvedCollections && resolvedCollections.length) {
|
if (resolvedCollections && Object.keys(resolvedCollections).length) {
|
||||||
resolvedIds.forEach(resolvedId => {
|
resolvedIds.forEach(resolvedId => {
|
||||||
if (editList[resolvedId]) {
|
if (newEdited[resolvedId]) {
|
||||||
if (editList[resolvedId]['updatedAt'] < resolvedCollections[resolvedId]['updatedAt']) {
|
if (newEdited[resolvedId]['updatedAt'] < resolvedCollections[resolvedId]['updatedAt']) {
|
||||||
delete editList[resolvedId];
|
delete newEdited[resolvedId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete newResolving[resolvedId];
|
delete newResolving[resolvedId];
|
||||||
if (pendingList[resolvedId]) {
|
if (newPending[resolvedId]) {
|
||||||
delete pendingList[resolvedId];
|
delete newPending[resolvedId];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (failedCollectionIds && failedCollectionIds.length) {
|
if (failedCollectionIds && Object.keys(failedCollectionIds).length) {
|
||||||
failedCollectionIds.forEach(failedId => {
|
failedCollectionIds.forEach(failedId => {
|
||||||
delete newResolving[failedId];
|
delete newResolving[failedId];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const newLists = Object.assign({}, lists, resolvedCollections);
|
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
...state,
|
...state,
|
||||||
pending: pendingList,
|
pending: newPending,
|
||||||
resolved: newLists,
|
resolved: newResolved,
|
||||||
|
edited: newEdited,
|
||||||
isResolvingCollectionById: newResolving,
|
isResolvingCollectionById: newResolving,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -68,7 +68,6 @@ export const makeSelectCollectionIsMine = (id: string) =>
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// for library page, we want all published
|
|
||||||
export const selectMyPublishedCollections = createSelector(
|
export const selectMyPublishedCollections = createSelector(
|
||||||
selectResolvedCollections,
|
selectResolvedCollections,
|
||||||
selectPendingCollections,
|
selectPendingCollections,
|
||||||
|
@ -78,21 +77,18 @@ export const selectMyPublishedCollections = createSelector(
|
||||||
// all resolved in myIds, plus those in pending and edited
|
// all resolved in myIds, plus those in pending and edited
|
||||||
const myPublishedCollections = Object.fromEntries(
|
const myPublishedCollections = Object.fromEntries(
|
||||||
Object.entries(pending).concat(
|
Object.entries(pending).concat(
|
||||||
Object.entries(edited)
|
|
||||||
.filter(
|
|
||||||
([key, val]) => myIds.includes(key)
|
|
||||||
// $FlowFixMe
|
|
||||||
)
|
|
||||||
.concat(
|
|
||||||
Object.entries(resolved).filter(
|
Object.entries(resolved).filter(
|
||||||
([key, val]) =>
|
([key, val]) =>
|
||||||
myIds.includes(key) &&
|
myIds.includes(key) &&
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
(!pending[key] && !edited[key])
|
!pending[key]
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
// now add in edited:
|
||||||
|
Object.entries(edited).forEach(([id, item]) => {
|
||||||
|
myPublishedCollections[id] = item;
|
||||||
|
});
|
||||||
return myPublishedCollections;
|
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) =>
|
export const makeSelectUrlsForCollectionId = (id: string) =>
|
||||||
createSelector(
|
createSelector(
|
||||||
makeSelectCollectionForId(id),
|
makeSelectCollectionForId(id),
|
||||||
|
|
typo?