Skip to content

Commit

Permalink
Fix reselecting another surrounding document
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Nov 4, 2021
1 parent 37571a4 commit a438726
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const ContextApp = ({ indexPattern, anchorId }: ContextAppProps) => {
*/
useEffect(() => {
if (!prevAppState.current || fetchedState.anchor._id !== anchorId) {
fetchAllRows();
fetchAllRows(!!prevAppState.current);
} else if (prevAppState.current.predecessorCount !== appState.predecessorCount) {
fetchSurroundingRows(SurrDocType.PREDECESSORS);
} else if (prevAppState.current.successorCount !== appState.successorCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,22 @@ export function useContextAppFetch({
);

const fetchAllRows = useCallback(
() => fetchAnchorRow().then((anchor) => anchor && fetchContextRows(anchor)),
[fetchAnchorRow, fetchContextRows]
(reset: boolean = false) => {
if (reset) {
const resetState = {
...fetchedState,
predecessors: [],
successors: [],
anchorStatus: { value: LoadingStatus.LOADING },
predecessorsStatus: { value: LoadingStatus.LOADING },
successorsStatus: { value: LoadingStatus.LOADING },
};
setFetchedState(resetState);
}

fetchAnchorRow().then((anchor) => anchor && fetchContextRows(anchor));
},
[fetchAnchorRow, fetchContextRows, setFetchedState, fetchedState]
);

return {
Expand Down

0 comments on commit a438726

Please sign in to comment.