-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add router to group forms and placeholder page for members view
Add a router to the group forms using Wouter to enable client-side transitions, and use it to enable switching between group settings and group members in the group edit forms. The "Members" page is currently just a placeholder.
- Loading branch information
1 parent
fd57a81
commit 539216c
Showing
7 changed files
with
148 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Route, Switch } from 'wouter-preact'; | ||
import { useMemo } from 'preact/hooks'; | ||
|
||
import CreateEditGroupForm from './CreateEditGroupForm'; | ||
import EditGroupMembersForm from './EditGroupMembersForm'; | ||
import type { ConfigObject } from '../config'; | ||
import { Config } from '../config'; | ||
|
||
export type AppRootProps = { | ||
config: ConfigObject; | ||
}; | ||
|
||
export default function AppRoot({ config }: AppRootProps) { | ||
const stylesheetLinks = useMemo( | ||
() => | ||
config.styles.map((stylesheetURL, index) => ( | ||
<link | ||
key={`${stylesheetURL}${index}`} | ||
rel="stylesheet" | ||
href={stylesheetURL} | ||
/> | ||
)), | ||
[config], | ||
); | ||
|
||
return ( | ||
<> | ||
{stylesheetLinks} | ||
<Config.Provider value={config}> | ||
<Switch> | ||
<Route path="/groups/new"> | ||
<CreateEditGroupForm /> | ||
</Route> | ||
<Route path="/groups/:pubid/edit"> | ||
<CreateEditGroupForm /> | ||
</Route> | ||
<Route path="/groups/:pubid/edit/members"> | ||
<EditGroupMembersForm /> | ||
</Route> | ||
</Switch> | ||
</Config.Provider> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
h/static/scripts/group-forms/components/EditGroupMembersForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useContext } from 'preact/hooks'; | ||
|
||
import { Config } from '../config'; | ||
import FormContainer from './forms/FormContainer'; | ||
import GroupFormHeader from './GroupFormHeader'; | ||
|
||
export default function EditGroupMembersForm() { | ||
const config = useContext(Config)!; | ||
const group = config.context.group!; | ||
|
||
return ( | ||
<FormContainer title="Edit group members"> | ||
<GroupFormHeader group={group} /> | ||
<hr /> | ||
<div className="my-2">Group members will appear here.</div> | ||
</FormContainer> | ||
); | ||
} |
42 changes: 42 additions & 0 deletions
42
h/static/scripts/group-forms/components/GroupFormHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import classnames from 'classnames'; | ||
import type { ComponentChildren } from 'preact'; | ||
import { Link as RouterLink, useRoute } from 'wouter-preact'; | ||
|
||
import type { Group } from '../config'; | ||
|
||
type TabLinkProps = { | ||
href: string; | ||
children: ComponentChildren; | ||
}; | ||
|
||
function TabLink({ children, href }: TabLinkProps) { | ||
const [selected] = useRoute(href); | ||
return ( | ||
<RouterLink | ||
href={href} | ||
className={classnames({ | ||
'focus-visible-ring whitespace-nowrap flex items-center font-semibold rounded px-2 py-1 gap-x-2': | ||
true, | ||
'text-grey-1 bg-grey-7': selected, | ||
})} | ||
> | ||
{children} | ||
</RouterLink> | ||
); | ||
} | ||
|
||
export type GroupFormHeaderProps = { | ||
group: Group; | ||
}; | ||
|
||
export default function GroupFormHeader({ group }: GroupFormHeaderProps) { | ||
const editLink = `/groups/${group.pubid}/edit`; | ||
const editMembersLinks = `/groups/${group.pubid}/edit/members`; | ||
|
||
return ( | ||
<div className="flex gap-x-2 justify-end py-2"> | ||
<TabLink href={editLink}>Settings</TabLink> | ||
<TabLink href={editMembersLinks}>Members</TabLink> | ||
</div> | ||
); | ||
} |
18 changes: 18 additions & 0 deletions
18
h/static/scripts/group-forms/components/forms/FormContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { ComponentChildren } from 'preact'; | ||
|
||
export type FormContainerProps = { | ||
title: string; | ||
children: ComponentChildren; | ||
}; | ||
|
||
/** A container for a form with a title. */ | ||
export default function FormContainer({ children, title }: FormContainerProps) { | ||
return ( | ||
<div className="text-grey-6 text-sm/relaxed"> | ||
<h1 className="mt-14 mb-8 text-grey-7 text-xl/none" data-testid="header"> | ||
{title} | ||
</h1> | ||
{children} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,13 @@ | ||
import { render } from 'preact'; | ||
|
||
import CreateEditGroupForm from './components/CreateEditGroupForm'; | ||
import AppRoot from './components/AppRoot'; | ||
import { readConfig } from './config'; | ||
|
||
function init() { | ||
const shadowHost = document.querySelector('#create-group-form')!; | ||
const shadowRoot = shadowHost.attachShadow({ mode: 'open' }); | ||
const config = readConfig(); | ||
const stylesheetLinks = config.styles.map((stylesheetURL, index) => ( | ||
<link | ||
key={`${stylesheetURL}${index}`} | ||
rel="stylesheet" | ||
href={stylesheetURL} | ||
/> | ||
)); | ||
render( | ||
<> | ||
{stylesheetLinks} | ||
<CreateEditGroupForm /> | ||
</>, | ||
shadowRoot, | ||
); | ||
render(<AppRoot config={config} />, shadowRoot); | ||
} | ||
|
||
init(); |