Skip to content

Commit

Permalink
feat: add move instruction to top and bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
sohrab- committed Aug 15, 2022
1 parent 0b95f71 commit 760ef53
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
45 changes: 43 additions & 2 deletions src/components/client/InstructionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ import {
MenuList,
Tooltip,
} from "@chakra-ui/react";
import { arrayMove } from "@dnd-kit/sortable";
import React, { useContext } from "react";
import { FaEllipsisV, FaEraser, FaEye, FaEyeSlash } from "react-icons/fa";
import {
FaAngleDoubleDown,
FaAngleDoubleUp,
FaEllipsisV,
FaEraser,
FaEye,
FaEyeSlash,
} from "react-icons/fa";
import { useInstruction } from "../../hooks/useInstruction";
import { useSessionStoreWithUndo } from "../../hooks/useSessionStore";
import { removeFrom } from "../../utils/sortable";
Expand All @@ -28,7 +36,10 @@ export const InstructionHeader: React.FC<{ index: number }> = ({ index }) => {
const { instruction, update, reset } = useInstruction();
const { listeners, attributes } = useContext(SortableItemContext);

const set = useSessionStoreWithUndo((state) => state.set);
const [instructionOrder, set] = useSessionStoreWithUndo((state) => [
state.transaction.instructions.order,
state.set,
]);

return (
<Flex mb={instruction.expanded ? "4" : undefined} alignItems="center">
Expand Down Expand Up @@ -99,6 +110,36 @@ export const InstructionHeader: React.FC<{ index: number }> = ({ index }) => {
variant="ghost"
/>
<MenuList zIndex="modal">
<MenuItem
icon={<Icon as={FaAngleDoubleUp} />}
isDisabled={index === 0}
onClick={() => {
set((state) => {
state.transaction.instructions.order = arrayMove(
state.transaction.instructions.order,
index,
0
);
});
}}
>
Move to the top
</MenuItem>
<MenuItem
icon={<Icon as={FaAngleDoubleDown} />}
isDisabled={index === instructionOrder.length - 1}
onClick={() => {
set((state) => {
state.transaction.instructions.order = arrayMove(
state.transaction.instructions.order,
index,
instructionOrder.length - 1
);
});
}}
>
Move to the bottom
</MenuItem>
<MenuItem
icon={<Icon as={FaEraser} />}
onClick={() => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/client/TransactionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import {
import { useWallet } from "@solana/wallet-adapter-react";
import React from "react";
import {
FaCompress,
FaEllipsisV,
FaEraser,
FaExpand,
FaExpandAlt,
FaFileImport,
FaPlay,
FaShareAlt,
Expand Down Expand Up @@ -147,15 +147,15 @@ export const TransactionHeader: React.FC<{ transaction: ITransaction }> = ({
/>
<MenuList zIndex="modal">
<MenuItem
icon={<Icon as={FaExpandAlt} />}
icon={<Icon as={FaExpand} />}
onClick={() => {
setAllExpanded(true);
}}
>
Expand All
</MenuItem>
<MenuItem
icon={<Icon as={FaExpand} />}
icon={<Icon as={FaCompress} />}
onClick={() => {
setAllExpanded(false);
}}
Expand Down

0 comments on commit 760ef53

Please sign in to comment.