Skip to content

Commit df77959

Browse files
committed
Add project viewer in web
1 parent aa2ed41 commit df77959

File tree

28 files changed

+499
-286
lines changed

28 files changed

+499
-286
lines changed

.changeset/hot-windows-march.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@pulse-editor/shared-utils": patch
3+
"@pulse-editor/react-api": patch
4+
---
5+
6+
Update types

.changeset/pre.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"fruity-goats-look",
3030
"full-beans-stop",
3131
"hot-symbols-fry",
32+
"hot-windows-march",
3233
"large-moose-tap",
3334
"lazy-zebras-mate",
3435
"mighty-ghosts-crash",

desktop/main.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ async function handleCreateProject(event, uri) {
188188
await fs.promises.mkdir(uri);
189189
}
190190

191+
async function handleDeleteProject(event, uri) {
192+
await fs.promises.rm(uri, { recursive: true, force: true });
193+
}
194+
195+
async function handleUpdateProject(event, uri, updatedInfo) {
196+
const newUri = path.join(path.dirname(uri), updatedInfo.name);
197+
await fs.promises.rename(uri, newUri);
198+
}
199+
191200
async function handleCreateFolder(event, uri) {
192201
// Create a folder at the uri
193202
await fs.promises.mkdir(uri);
@@ -272,6 +281,9 @@ app.whenReady().then(() => {
272281
ipcMain.handle("list-path-content", handleListPathContent);
273282

274283
ipcMain.handle("create-project", handleCreateProject);
284+
ipcMain.handle("delete-project", handleDeleteProject);
285+
ipcMain.handle("update-project", handleUpdateProject);
286+
275287
ipcMain.handle("create-folder", handleCreateFolder);
276288
ipcMain.handle("create-file", handleCreateFile);
277289

desktop/preload.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ contextBridge.exposeInMainWorld("electronAPI", {
1010
ipcRenderer.invoke("list-path-content", uri, options),
1111

1212
createProject: (uri) => ipcRenderer.invoke("create-project", uri),
13+
deleteProject: (uri) => ipcRenderer.invoke("delete-project", uri),
14+
updateProject: (uri, updatedInfo) => ipcRenderer.invoke("update-project", uri, updatedInfo),
15+
1316
createFolder: (uri) => ipcRenderer.invoke("create-folder", uri),
1417
createFile: (uri) => ipcRenderer.invoke("create-file", uri),
1518

npm-packages/react-api/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @pulse-editor/react-api
22

3+
## 0.1.1-alpha.33
4+
5+
### Patch Changes
6+
7+
- Update types
8+
- Updated dependencies
9+
- @pulse-editor/shared-utils@0.1.1-alpha.33
10+
311
## 0.1.1-alpha.32
412

513
### Patch Changes

npm-packages/react-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pulse-editor/react-api",
3-
"version": "0.1.1-alpha.32",
3+
"version": "0.1.1-alpha.33",
44
"main": "dist/main.js",
55
"files": [
66
"dist"
@@ -38,7 +38,7 @@
3838
"typescript-eslint": "^8.30.1"
3939
},
4040
"peerDependencies": {
41-
"@pulse-editor/shared-utils": "0.1.1-alpha.32",
41+
"@pulse-editor/shared-utils": "0.1.1-alpha.33",
4242
"react": "^19.0.0",
4343
"react-dom": "^19.0.0"
4444
}

npm-packages/shared-utils/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @pulse-editor/shared-utils
22

3+
## 0.1.1-alpha.33
4+
5+
### Patch Changes
6+
7+
- Update types
8+
39
## 0.1.1-alpha.32
410

511
### Patch Changes

npm-packages/shared-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pulse-editor/shared-utils",
3-
"version": "0.1.1-alpha.32",
3+
"version": "0.1.1-alpha.33",
44
"main": "dist/main.js",
55
"files": [
66
"dist"

web/components/explorer/explorer.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { TreeViewGroupRef } from "@/lib/types";
44
import { useContext, useEffect, useRef, useState } from "react";
55
import { EditorContext } from "../providers/editor-context-provider";
66
import { PlatformEnum } from "@/lib/types";
7-
import { getPlatform } from "@/lib/platform-api/platform-checker";
7+
import { getPlatform, isWeb } from "@/lib/platform-api/platform-checker";
88
import { Button } from "@heroui/react";
99
import useExplorer from "@/lib/hooks/use-explorer";
1010
import { usePlatformApi } from "@/lib/hooks/use-platform-api";
@@ -35,16 +35,15 @@ export default function Explorer({
3535
useEffect(() => {
3636
if (platformApi) {
3737
const homePath = editorContext?.persistSettings?.projectHomePath;
38-
if (homePath) {
39-
platformApi.listProjects(homePath).then((projects) => {
40-
editorContext?.setEditorStates((prev) => {
41-
return {
42-
...prev,
43-
projectsInfo: projects,
44-
};
45-
});
38+
39+
platformApi.listProjects(homePath).then((projects) => {
40+
editorContext?.setEditorStates((prev) => {
41+
return {
42+
...prev,
43+
projectsInfo: projects,
44+
};
4645
});
47-
}
46+
});
4847
}
4948
}, [editorContext?.persistSettings, platformApi]);
5049

@@ -124,7 +123,7 @@ export default function Explorer({
124123
}
125124

126125
// Choose project home path
127-
if (!editorContext?.persistSettings?.projectHomePath) {
126+
if (!isWeb() && !editorContext?.persistSettings?.projectHomePath) {
128127
return (
129128
<div className="bg-content2 h-full w-full space-y-2 p-4">
130129
<p>
@@ -210,7 +209,8 @@ export default function Explorer({
210209
// Pick project
211210
else {
212211
return (
213-
<div className="bg-content2 h-full w-full space-y-2 overflow-y-auto p-4">
212+
<div className="bg-content2 h-full w-full space-y-2 overflow-y-auto px-4">
213+
<p className="text-center text-lg font-medium">View Projects</p>
214214
<Button
215215
className="w-full"
216216
onPress={() => {
@@ -219,11 +219,11 @@ export default function Explorer({
219219
>
220220
New Project
221221
</Button>
222+
<ProjectList />
222223
<ProjectSettingsModal
223224
isOpen={isProjectSettingsModalOpen}
224225
setIsOpen={setIsProjectSettingsModalOpen}
225226
/>
226-
<ProjectList />
227227
</div>
228228
);
229229
}

web/components/explorer/project-list.tsx

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,32 @@ import { ContextMenuState, ProjectInfo } from "@/lib/types";
88
import ContextMenu from "../interface/context-menu";
99
import ProjectSettingsModal from "../modals/project-settings-modal";
1010

11+
export default function ProjectList() {
12+
const editorContext = useContext(EditorContext);
13+
const [settingsOpen, setSettingsOpen] = useState(false);
14+
const [settingsProject, setSettingsProject] = useState<
15+
ProjectInfo | undefined
16+
>(undefined);
17+
18+
return (
19+
<div className="flex w-full flex-col gap-2">
20+
{editorContext?.editorStates.projectsInfo?.map((project, index) => (
21+
<ProjectTab
22+
key={index}
23+
project={project}
24+
setSettingsOpen={setSettingsOpen}
25+
setSettingsProject={setSettingsProject}
26+
/>
27+
))}
28+
<ProjectSettingsModal
29+
isOpen={settingsOpen}
30+
setIsOpen={setSettingsOpen}
31+
projectInfo={settingsProject}
32+
/>
33+
</div>
34+
);
35+
}
36+
1137
function ProjectTab({
1238
project,
1339
setSettingsOpen,
@@ -90,7 +116,7 @@ function ProjectTab({
90116
<ContextMenu state={contextMenuState} setState={setContextMenuState}>
91117
<div className="flex flex-col">
92118
<Button
93-
className="h-12 text-medium sm:h-8 sm:text-sm"
119+
className="text-medium h-12 sm:h-8 sm:text-sm"
94120
variant="light"
95121
onPress={(e) => {
96122
setSettingsOpen(true);
@@ -101,7 +127,7 @@ function ProjectTab({
101127
<p className="w-full text-start">Project Settings</p>
102128
</Button>
103129
<Button
104-
className="h-12 text-medium sm:h-8 sm:text-sm"
130+
className="text-medium h-12 sm:h-8 sm:text-sm"
105131
variant="light"
106132
>
107133
<p className="w-full text-start">Select Multiple</p>
@@ -111,29 +137,3 @@ function ProjectTab({
111137
</div>
112138
);
113139
}
114-
115-
export default function ProjectList() {
116-
const editorContext = useContext(EditorContext);
117-
const [settingsOpen, setSettingsOpen] = useState(false);
118-
const [settingsProject, setSettingsProject] = useState<
119-
ProjectInfo | undefined
120-
>(undefined);
121-
122-
return (
123-
<div className="flex w-full flex-col gap-2">
124-
{editorContext?.editorStates.projectsInfo?.map((project, index) => (
125-
<ProjectTab
126-
key={index}
127-
project={project}
128-
setSettingsOpen={setSettingsOpen}
129-
setSettingsProject={setSettingsProject}
130-
/>
131-
))}
132-
<ProjectSettingsModal
133-
isOpen={settingsOpen}
134-
setIsOpen={setSettingsOpen}
135-
projectInfo={settingsProject}
136-
/>
137-
</div>
138-
);
139-
}

0 commit comments

Comments
 (0)