Skip to content

Commit

Permalink
fix: selection history navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
devcatalin committed Aug 19, 2021
1 parent cc52e47 commit eaab450
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/components/organisms/ActionsPane/ActionsPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ const ActionsPane = (props: {contentHeight: string}) => {
const [key, setKey] = useState('source');
const dispatch = useAppDispatch();

const isLeftArrowEnabled = selectionHistory.length > 0 && currentSelectionHistoryIndex !== 0;
const isLeftArrowEnabled =
selectionHistory.length > 1 &&
(currentSelectionHistoryIndex === undefined || (currentSelectionHistoryIndex && currentSelectionHistoryIndex > 0));
const isRightArrowEnabled =
selectionHistory.length > 0 &&
currentSelectionHistoryIndex &&
currentSelectionHistoryIndex < selectionHistory.length - 2;
selectionHistory.length > 1 &&
currentSelectionHistoryIndex !== undefined &&
currentSelectionHistoryIndex < selectionHistory.length - 1;

const onClickLeftArrow = () => {
dispatch(selectFromHistory({direction: 'left'}));
Expand Down
2 changes: 1 addition & 1 deletion src/redux/reducers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export type StartPreviewLoaderPayload = {

function updateSelectionHistory(type: 'resource' | 'path', isVirtualSelection: boolean, state: AppState) {
if (isVirtualSelection) {
state.currentSelectionHistoryIndex = undefined;
return;
}
if (type === 'resource' && state.selectedResourceId) {
Expand All @@ -77,6 +76,7 @@ function updateSelectionHistory(type: 'resource' | 'path', isVirtualSelection: b
selectedPath: state.selectedPath,
});
}
state.currentSelectionHistoryIndex = undefined;
}

export const mainSlice = createSlice({
Expand Down
9 changes: 4 additions & 5 deletions src/redux/thunks/selectionHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ export const selectFromHistory = createAsyncThunk<
if (currentSelectionHistoryIndex === 0) {
return;
}
nextSelectionHistoryIndex = currentSelectionHistoryIndex
? currentSelectionHistoryIndex - 1
: selectionHistory.length - 2;
nextSelectionHistoryIndex =
currentSelectionHistoryIndex !== undefined ? currentSelectionHistoryIndex - 1 : selectionHistory.length - 2;
} else if (direction === 'right') {
if (!currentSelectionHistoryIndex || currentSelectionHistoryIndex === selectionHistory.length - 1) {
if (currentSelectionHistoryIndex === undefined || currentSelectionHistoryIndex === selectionHistory.length - 1) {
return;
}
nextSelectionHistoryIndex = currentSelectionHistoryIndex + 1;
}

if (!nextSelectionHistoryIndex) {
if (nextSelectionHistoryIndex === null) {
return;
}

Expand Down

0 comments on commit eaab450

Please sign in to comment.