Skip to content

Commit 9acc04a

Browse files
committed
Move newComponentButton logic to FilePanel for simplicity
1 parent c975cb4 commit 9acc04a

File tree

2 files changed

+19
-32
lines changed

2 files changed

+19
-32
lines changed

src/components/Menus/Sidebar/FilePanel/FilePanel.jsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import React from "react";
22
import { useDispatch, useSelector } from "react-redux";
33
import { useTranslation } from "react-i18next";
4-
import useNewComponentButton from "../../../../hooks/useNewComponentButton";
54

65
import FileMenu from "../../FileMenu/FileMenu";
76
import DesignSystemButton from "../../../DesignSystemButton/DesignSystemButton";
87
import {
98
openFile,
109
setFocussedFileIndex,
1110
hideSidebar,
11+
showNewFileModal,
1212
} from "../../../../redux/EditorSlice";
1313

1414
import "../../../../assets/stylesheets/FilePanel.scss";
1515
import "../../../../assets/stylesheets/Sidebar.scss";
1616
import SidebarPanel from "../SidebarPanel";
1717
import FileIcon from "../../../../utils/FileIcon";
18+
import PlusIcon from "../../../../assets/icons/plus.svg";
1819

1920
const FilePanel = ({ isMobile }) => {
2021
const project = useSelector((state) => state.editor.project);
2122
const openFiles = useSelector((state) => state.editor.openFiles);
2223
const readOnly = useSelector((state) => state.editor.readOnly);
23-
24+
const { t } = useTranslation();
2425
const dispatch = useDispatch();
25-
const newFileButtons = useNewComponentButton();
2626

2727
const switchToFileTab = (panelIndex, fileIndex) => {
2828
dispatch(setFocussedFileIndex({ panelIndex, fileIndex }));
@@ -43,9 +43,23 @@ const FilePanel = ({ isMobile }) => {
4343
dispatch(hideSidebar());
4444
}
4545
};
46-
const { t } = useTranslation();
4746

48-
const buttons = readOnly ? [] : newFileButtons;
47+
const openNewFileModal = () => {
48+
dispatch(showNewFileModal());
49+
};
50+
51+
const buttons = readOnly
52+
? []
53+
: [
54+
{
55+
text: t("filePanel.newFileButton"),
56+
textAlways: true,
57+
icon: <PlusIcon />,
58+
onClick: openNewFileModal,
59+
className: "btn--primary",
60+
fill: true,
61+
},
62+
];
4963

5064
if (!project || !project.components) {
5165
return null;

src/hooks/useNewComponentButton.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)