Skip to content

Commit

Permalink
feat: soft pop
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukaii committed Aug 20, 2023
1 parent 571e8b7 commit 7c4c8d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/electron-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blast",
"version": "0.0.12",
"version": "0.0.13",
"description": "Blast Launcher Electron Client",
"keywords": [],
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions apps/electron-client/src/renderer/components/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export function getListIndexFromValue(value: string) {
export const List = ({ children, props }: { children: BlastComponent[]; props: ListProps }): JSX.Element => {
const listItems = children.filter((child) => child.elementType === "ListItem");
const emptyView = children.find((child) => child.elementType === "EmptyView");
const { pop } = useNavigationContext();
const { softPop, pop } = useNavigationContext();

const emptyViewActionPanel = emptyView
? emptyView.children.find((child) => child.elementType === "ActionPanel")
Expand Down Expand Up @@ -196,7 +196,7 @@ export const List = ({ children, props }: { children: BlastComponent[]; props: L
}
} else if (e.key === "Backspace" && !inputRef.current.value) {
e.preventDefault();
pop();
softPop();
}
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { createContext, useContext } from "react";

export const NavigationContext = createContext<{
pop: () => void;
softPop: () => void;
canPop: boolean;
}>({
pop: () => {
/* noop */
},
softPop: () => {
/* noop */
},
canPop: false,
});

Expand Down
7 changes: 7 additions & 0 deletions apps/electron-client/src/renderer/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,18 @@ export const TreeComponent = ({ blastProps }: { blastProps: BlastComponent }) =>
}
}, [canPop, ws]);

const softPop = useCallback(() => {
if (canPop) {
ws.call("blast-global:pop");
}
}, [canPop, ws]);

return (
<NavigationContext.Provider
value={{
pop,
canPop,
softPop
}}
>
{elementType === "List" ? <List children={firstChild.children} props={props as ListProps} /> : null}
Expand Down

0 comments on commit 7c4c8d0

Please sign in to comment.