forked from onlook-dev/onlook
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathindex.tsx
More file actions
186 lines (175 loc) · 7.45 KB
/
index.tsx
File metadata and controls
186 lines (175 loc) · 7.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import { useProjectsManager } from '@/components/Context';
import { invokeMainChannel } from '@/lib/utils';
import { DefaultSettings, MainChannels } from '@onlook/models/constants';
import { Button } from '@onlook/ui/button';
import { Icons } from '@onlook/ui/icons';
import { Input } from '@onlook/ui/input';
import { Separator } from '@onlook/ui/separator';
import { observer } from 'mobx-react-lite';
import { ReinstallButton } from './ReinstallButon';
const ProjectTab = observer(() => {
const projectsManager = useProjectsManager();
const project = projectsManager.project;
const installCommand = project?.commands?.install || DefaultSettings.COMMANDS.install;
const runCommand = project?.commands?.run || DefaultSettings.COMMANDS.run;
const buildCommand = project?.commands?.build || DefaultSettings.COMMANDS.build;
const folderPath = project?.folderPath || '';
const name = project?.name || '';
const url = project?.url || '';
const handleUpdatePath = async () => {
const path = (await invokeMainChannel(MainChannels.PICK_COMPONENTS_DIRECTORY)) as
| string
| null;
if (!path) {
console.error('No path selected');
return;
}
projectsManager.updatePartialProject({
folderPath: path,
});
};
const handleUpdateUrl = (url: string) => {
let port = url.split(':').pop();
try {
const parsedUrl = new URL(url);
port = parsedUrl.port;
} catch (error) {
console.error('Invalid URL');
return;
}
projectsManager.updatePartialProject({
url,
commands: {
...project?.commands,
run: 'npx next dev -p ' + port,
build: 'npx next build -p ' + port,
},
});
projectsManager.editorEngine?.canvas.saveFrames(
projectsManager.editorEngine?.canvas.frames.map((frame) => ({
...frame,
url,
})),
);
};
return (
<div className="text-sm">
<div className="flex flex-col gap-4 p-6">
<h2 className="text-lg">Metadata</h2>
<div className="space-y-4">
<div className="flex justify-between items-center">
<p className=" text-muted-foreground">Name</p>
<Input
id="name"
value={name}
onChange={(e) =>
projectsManager.updatePartialProject({
name: e.target.value,
})
}
className="w-2/3"
/>
</div>
<div className="flex justify-between items-center">
<p className=" text-muted-foreground">URL</p>
<Input
id="url"
value={url}
onChange={(e) => handleUpdateUrl(e.target.value)}
onBlur={() => projectsManager.runner?.restart()}
className="w-2/3"
/>
</div>
<div className="flex justify-between items-center">
<p className=" text-muted-foreground">Path</p>
<div className="flex items-center gap-2 w-2/3">
<Input
id="folderPath"
value={folderPath}
readOnly={true}
onChange={(e) =>
projectsManager.updatePartialProject({
folderPath: e.target.value,
})
}
/>
<Button size={'icon'} variant={'outline'} onClick={handleUpdatePath}>
<Icons.Directory />
</Button>
</div>
</div>
</div>
</div>
<Separator />
<div className="flex flex-col gap-4 p-6">
<div className="flex flex-col gap-2">
<h2 className="text-lg">Commands</h2>
<p className="text-small text-foreground-secondary">
{"Only update these if you know what you're doing!"}
</p>
</div>
<div className="space-y-4">
<div className="flex justify-between items-center">
<p className="text-muted-foreground">Install</p>
<Input
id="install"
value={installCommand}
className="w-2/3"
onChange={(e) =>
projectsManager.updatePartialProject({
commands: {
...project?.commands,
install: e.target.value,
},
})
}
/>
</div>
<div className="flex justify-between items-center">
<p className=" text-muted-foreground">Run</p>
<Input
id="run"
value={runCommand}
className="w-2/3"
onChange={(e) =>
projectsManager.updatePartialProject({
commands: {
...project?.commands,
run: e.target.value,
},
})
}
/>
</div>
<div className="flex justify-between items-center">
<p className=" text-muted-foreground">Build</p>
<Input
id="build"
value={buildCommand}
onChange={(e) =>
projectsManager.updatePartialProject({
commands: {
...project?.commands,
build: e.target.value,
},
})
}
className="w-2/3"
/>
</div>
</div>
</div>
<Separator />
<div className="flex justify-between items-center p-6">
<div className="flex flex-col gap-2">
<p className="text-largePlus">Reinstall Dependencies</p>
<p className="text-foreground-onlook text-small">
For when project failed to install dependencies
</p>
</div>
<ReinstallButton />
</div>
</div>
);
});
export default ProjectTab;