Skip to content

Commit 6bf2103

Browse files
committed
refactor(ProjectsPage.tsx): Revamp project management interface with enhanced dialogs and improved data handling
1 parent 5b2e731 commit 6bf2103

File tree

6 files changed

+741
-338
lines changed

6 files changed

+741
-338
lines changed

api/schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { OBJ, optional, STR } from './lib/validator.ts'
1+
import { BOOL, OBJ, optional, STR } from './lib/validator.ts'
22
import { Asserted } from './lib/router.ts'
33
import { createCollection } from './lib/json_store.ts'
44

55
export const userDef = OBJ({
66
userEmail: STR('The user email address'),
77
userFullName: STR('The user login name'),
88
userPicture: optional(STR('The user profile picture URL')),
9+
isAdmin: optional(BOOL('Is the user an admin?')),
910
})
1011

1112
export const User = await createCollection<

api/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export async function authenticateOauthUser(
6060

6161
let userEmail: string
6262
if (!existingUser) {
63-
const newUser = await User.insert(oauthInfo)
63+
const newUser = await User.insert({...oauthInfo, isAdmin: false})
6464
userEmail = newUser.userEmail
6565
} else {
6666
userEmail = existingUser.userEmail

web/components/Dialog.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import type { JSX } from 'preact'
2+
import { useState } from 'preact/hooks'
3+
4+
import { navigate, url } from '../lib/router.tsx'
5+
6+
type DialogProps = {
7+
id: string
8+
children: preact.ComponentChildren
9+
} & JSX.HTMLAttributes<HTMLDialogElement>
10+
11+
export const Dialog = ({
12+
id,
13+
onClick,
14+
onClose,
15+
...props
16+
}: DialogProps) => {
17+
const [dialogElem, setRef] = useState<HTMLDialogElement | null>(null)
18+
19+
const isOpen = url.params.dialog === id
20+
if (dialogElem) {
21+
if (!isOpen && dialogElem.open) {
22+
dialogElem.close()
23+
} else if (isOpen && !dialogElem.open) {
24+
dialogElem.showModal()
25+
}
26+
}
27+
28+
return (
29+
<dialog
30+
{...props}
31+
id={id}
32+
onClick={(event) => {
33+
dialogElem === event.target && dialogElem?.close()
34+
typeof onClick === 'function' && onClick(event)
35+
}}
36+
onClose={(event) => {
37+
typeof onClose === 'function' && onClose(event)
38+
if (!isOpen) return
39+
navigate({ params: { dialog: null } })
40+
}}
41+
ref={setRef}
42+
>
43+
</dialog>
44+
)
45+
}
46+
47+
export const DialogModal = ({ children, ...props }: DialogProps) => {
48+
return (
49+
<Dialog class='modal' {...props}>
50+
<div class='modal-box w-auto'>
51+
<form method='dialog'>
52+
<button
53+
type='submit'
54+
class='btn btn-sm btn-circle btn-ghost absolute right-2 top-2'
55+
>
56+
57+
</button>
58+
</form>
59+
{children}
60+
</div>
61+
</Dialog>
62+
)
63+
}

web/components/Modal.tsx

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

web/lib/modal-config.ts

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

0 commit comments

Comments
 (0)