forked from ExplosionEngine/Explosion
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproject-hub.tsx
More file actions
112 lines (103 loc) · 3.96 KB
/
project-hub.tsx
File metadata and controls
112 lines (103 loc) · 3.96 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
import { useEffect, useState } from 'react';
import { Tabs, Tab } from '@heroui/tabs';
import { User } from '@heroui/user';
import { Form } from '@heroui/form';
import { Button, PressEvent } from '@heroui/button';
import { Input } from '@heroui/input';
import { Chip } from '@heroui/chip';
import { Listbox, ListboxItem } from '@heroui/listbox';
import { Avatar } from '@heroui/avatar';
import { ScrollShadow } from '@heroui/scroll-shadow';
import { Select, SelectItem } from '@heroui/react';
import { QWebChannel } from '@/qwebchannel';
interface RecentProjectInfo {
name: string;
path: string;
}
interface ProjectTemplateInfo {
name: string;
path: string;
}
export default function ProjectHubPage() {
const [engineVersion, setEngineVersion] = useState('');
const [recentProjects, setRecentProjects] = useState(Array<RecentProjectInfo>);
const [projectTemplates, setProjectTemplates] = useState(Array<ProjectTemplateInfo>);
useEffect(() => {
new QWebChannel(window.qt.webChannelTransport, (channel: QWebChannel): void => {
window.backend = channel.objects.backend;
setEngineVersion(window.backend.engineVersion);
setRecentProjects(window.backend.recentProjects);
setProjectTemplates(window.backend.projectTemplates);
});
}, []);
function onCreateProject(): void {
// TODO
console.error("onCreateProject()");
window.backend.CreateProject();
}
function onOpenProject(e: PressEvent): void {
// TODO
const index = parseInt(e.target.getAttribute('data-key') as string);
console.error('onOpenProject:', index);
}
async function onBrowseProjectPath(): Promise<void> {
// TODO
const dirHandle = await window.showDirectoryPicker({ startIn: 'desktop' });
console.error(dirHandle);
}
return (
<div className='h-screen p-6'>
<div className='mb-4'>
<User
avatarProps={{ src: '/logo.png' }}
description={
<div className='mt-1'>
<Chip className='ml-1' color='secondary' size='sm' variant='flat'>
{engineVersion}
</Chip>
</div>
}
name='Explosion Game Engine'
/>
</div>
<Tabs isVertical={true}>
<Tab className='w-full pr-6' title='Recently Projects'>
<ScrollShadow hideScrollBar className='h-[450px]' size={60}>
<Listbox items={recentProjects} variant='flat'>
{recentProjects.map((item, i) => (
<ListboxItem key={i} textValue={item.name} onPress={onOpenProject}>
<div className='flex gap-2 items-center'>
<Avatar alt={item.name} className='shrink-0' name={item.name} size='sm' />
<div className='flex flex-col'>
<span className='text-small'>{item.name}</span>
<span className='text-tiny text-default-400'>{item.path}</span>
</div>
</div>
</ListboxItem>
))}
</Listbox>
</ScrollShadow>
</Tab>
<Tab className='w-full pr-6' title='New Project'>
<Form className='w-full ml-4'>
<Input fullWidth isRequired label='Project Name' labelPlacement='outside' placeholder='HelloExplosion' />
<div className='flex w-full'>
<Input isRequired label='Project Path' labelPlacement='outside' placeholder='/path/to/your/project' />
<Button className='ml-2 mt-6' onPress={() => onBrowseProjectPath()}>
Browse
</Button>
</div>
<Select fullWidth isRequired defaultSelectedKeys={['0']} label='Project Template' labelPlacement='outside'>
{projectTemplates.map((item, i) => (
<SelectItem key={i}>{item.name}</SelectItem>
))}
</Select>
<Button color='primary' onPress={onCreateProject}>
Create
</Button>
</Form>
</Tab>
</Tabs>
</div>
);
}