-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
636 additions
and
279 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
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
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,3 @@ | ||
export * from './use-mutation-create-community' | ||
export * from './use-query-get-communities' | ||
export * from './use-query-get-community-by-slug' |
23 changes: 23 additions & 0 deletions
23
web/src/app/features/pubkey-community/data-access/use-mutation-create-community.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,23 @@ | ||
import { CreateCommunityOptions } from '@pubkey-protocol/sdk' | ||
import { useMutation } from '@tanstack/react-query' | ||
import { usePubKeyProtocol } from '../../pubkey-protocol' | ||
|
||
export type PubKeyCommunityCreateInput = Omit<CreateCommunityOptions, 'authority' | 'feePayer'> | ||
|
||
export function useMutationCreateCommunity() { | ||
const { authority, feePayer, sdk, signAndConfirmTransaction, onError, onSuccess } = usePubKeyProtocol() | ||
|
||
return useMutation({ | ||
mutationFn: (options: PubKeyCommunityCreateInput) => | ||
sdk | ||
.createCommunity({ | ||
...options, | ||
avatarUrl: options.avatarUrl || `https://api.dicebear.com/9.x/bottts-neutral/svg?seed=${options.slug}`, | ||
authority, | ||
feePayer, | ||
}) | ||
.then(signAndConfirmTransaction), | ||
onError, | ||
onSuccess, | ||
}) | ||
} |
11 changes: 11 additions & 0 deletions
11
web/src/app/features/pubkey-community/data-access/use-query-get-communities.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,11 @@ | ||
import { useQuery } from '@tanstack/react-query' | ||
import { usePubKeyProtocol } from '../../pubkey-protocol' | ||
|
||
export function useQueryGetCommunities() { | ||
const { cluster, sdk } = usePubKeyProtocol() | ||
|
||
return useQuery({ | ||
queryKey: ['pubkey-protocol', 'getCommunities', { cluster }], | ||
queryFn: () => sdk.getCommunities(), | ||
}) | ||
} |
11 changes: 11 additions & 0 deletions
11
web/src/app/features/pubkey-community/data-access/use-query-get-community-by-slug.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,11 @@ | ||
import { useQuery } from '@tanstack/react-query' | ||
import { usePubKeyProtocol } from '../../pubkey-protocol' | ||
|
||
export function useQueryGetCommunityBySlug({ slug }: { slug: string }) { | ||
const { sdk, cluster } = usePubKeyProtocol() | ||
|
||
return useQuery({ | ||
queryKey: ['pubkey-protocol', 'getCommunityBySlug', { cluster, slug }], | ||
queryFn: () => sdk.getCommunityBySlug({ slug }), | ||
}) | ||
} |
23 changes: 23 additions & 0 deletions
23
web/src/app/features/pubkey-community/feature/pubkey-community-feature-create.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,23 @@ | ||
import { toastError, toastSuccess, UiCard, UiPage } from '@pubkey-ui/core' | ||
import { IconUserPlus } from '@tabler/icons-react' | ||
import { useMutationCreateCommunity } from '../data-access' | ||
import { PubkeyProtocolUiCommunityCreateForm } from '../ui' | ||
|
||
export function PubkeyCommunityFeatureCreate() { | ||
const mutation = useMutationCreateCommunity() | ||
|
||
return ( | ||
<UiPage leftAction={<IconUserPlus />} title="Create Community"> | ||
<UiCard title="Create Community"> | ||
<PubkeyProtocolUiCommunityCreateForm | ||
submit={(input) => | ||
mutation | ||
.mutateAsync(input) | ||
.then(() => toastSuccess(`Community created`)) | ||
.catch((err) => toastError(`Error: ${err}`)) | ||
} | ||
/> | ||
</UiCard> | ||
</UiPage> | ||
) | ||
} |
23 changes: 23 additions & 0 deletions
23
web/src/app/features/pubkey-community/feature/pubkey-community-feature-detail.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,23 @@ | ||
import { UiLoader, UiPage, UiWarning } from '@pubkey-ui/core' | ||
import { IconUsers } from '@tabler/icons-react' | ||
import { useParams } from 'react-router-dom' | ||
import { useQueryGetCommunityBySlug } from '../data-access' | ||
import { PubkeyProtocolUiCommunityCard } from '../ui' | ||
|
||
export function PubkeyCommunityFeatureDetail() { | ||
const { slug } = useParams() as { slug: string } | ||
|
||
const query = useQueryGetCommunityBySlug({ slug }) | ||
|
||
return ( | ||
<UiPage leftAction={<IconUsers />} title={slug}> | ||
{query.isLoading ? ( | ||
<UiLoader /> | ||
) : query.data ? ( | ||
<PubkeyProtocolUiCommunityCard community={query.data} /> | ||
) : ( | ||
<UiWarning message="User not found" /> | ||
)} | ||
</UiPage> | ||
) | ||
} |
21 changes: 21 additions & 0 deletions
21
web/src/app/features/pubkey-community/feature/pubkey-community-feature-list.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,21 @@ | ||
import { UiDebug, UiLoader, UiPage, UiStack } from '@pubkey-ui/core' | ||
import { IconUsers } from '@tabler/icons-react' | ||
import { useQueryGetCommunities } from '../data-access' | ||
import { PubkeyProtocolUiCommunityGrid } from '../ui/pubkey-protocol-ui-community-grid' | ||
|
||
export function PubkeyCommunityFeatureList({ basePath }: { basePath: string }) { | ||
const query = useQueryGetCommunities() | ||
|
||
return ( | ||
<UiPage leftAction={<IconUsers />} title="Communities"> | ||
{query.isLoading ? ( | ||
<UiLoader /> | ||
) : ( | ||
<UiStack> | ||
<PubkeyProtocolUiCommunityGrid communities={query.data ?? []} basePath={basePath} /> | ||
<UiDebug data={query.data ?? []} /> | ||
</UiStack> | ||
)} | ||
</UiPage> | ||
) | ||
} |
36 changes: 36 additions & 0 deletions
36
web/src/app/features/pubkey-community/feature/pubkey-community.routes.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,36 @@ | ||
import { IconUsers, IconUsersPlus } from '@tabler/icons-react' | ||
import { Navigate, useRoutes } from 'react-router-dom' | ||
import { KeypairUiGridItem } from '../../keypair/ui' | ||
import { PubkeyCommunityFeatureList } from './pubkey-community-feature-list' | ||
import { PubkeyCommunityFeatureCreate } from './pubkey-community-feature-create' | ||
import { PubkeyCommunityFeatureDetail } from './pubkey-community-feature-detail' | ||
import { PubkeyProtocolProvider, PubkeyProtocolUiSidebar } from '../../pubkey-protocol' | ||
|
||
export default function PubkeyCommunityRoutes({ basePath }: { basePath: string }) { | ||
const sidebar: KeypairUiGridItem[] = [ | ||
{ | ||
label: 'Communities', | ||
path: 'list', | ||
leftSection: <IconUsers size={16} />, | ||
}, | ||
{ | ||
label: 'Create', | ||
path: 'create', | ||
leftSection: <IconUsersPlus size={16} />, | ||
}, | ||
] | ||
const routes = useRoutes([ | ||
{ index: true, element: <Navigate to="list" replace /> }, | ||
{ path: 'list', element: <PubkeyCommunityFeatureList basePath={`${basePath}/profiles`} /> }, | ||
{ path: 'create', element: <PubkeyCommunityFeatureCreate /> }, | ||
{ path: ':username', element: <PubkeyCommunityFeatureDetail /> }, | ||
]) | ||
|
||
return ( | ||
<PubkeyProtocolProvider> | ||
<PubkeyProtocolUiSidebar basePath={basePath} routes={sidebar}> | ||
{routes} | ||
</PubkeyProtocolUiSidebar> | ||
</PubkeyProtocolProvider> | ||
) | ||
} |
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,4 @@ | ||
export * from './pubkey-protocol-ui-community-anchor' | ||
export * from './pubkey-protocol-ui-community-avatar' | ||
export * from './pubkey-protocol-ui-community-card' | ||
export * from './pubkey-protocol-ui-community-create-form' |
14 changes: 14 additions & 0 deletions
14
web/src/app/features/pubkey-community/ui/pubkey-protocol-ui-community-anchor.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,14 @@ | ||
import { Anchor, Text } from '@mantine/core' | ||
import { Link } from 'react-router-dom' | ||
|
||
export function PubkeyProtocolUiCommunityAnchor({ slug, basePath }: { slug: string; basePath?: string }) { | ||
return basePath ? ( | ||
<Anchor component={Link} to={`${basePath}/communities/${slug}`} size="xl" fw="bold"> | ||
{slug} | ||
</Anchor> | ||
) : ( | ||
<Text size="xl" fw="bold"> | ||
{slug} | ||
</Text> | ||
) | ||
} |
6 changes: 6 additions & 0 deletions
6
web/src/app/features/pubkey-community/ui/pubkey-protocol-ui-community-avatar.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,6 @@ | ||
import { PubKeyCommunity } from '@pubkey-protocol/anchor' | ||
import { UiAvatar } from '../../../ui/ui-avatar' | ||
|
||
export function PubkeyProtocolUiCommunityAvatar({ community: { avatarUrl, slug } }: { community: PubKeyCommunity }) { | ||
return <UiAvatar url={avatarUrl ? avatarUrl : null} name={slug} radius={100} size="lg" /> | ||
} |
17 changes: 17 additions & 0 deletions
17
web/src/app/features/pubkey-community/ui/pubkey-protocol-ui-community-card.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,17 @@ | ||
import { PubKeyCommunity } from '@pubkey-protocol/anchor' | ||
import { UiDebug } from '@pubkey-ui/core' | ||
import { PubkeyProtocolUiCommunityListItem } from './pubkey-protocol-ui-community-list-item' | ||
|
||
export function PubkeyProtocolUiCommunityCard({ | ||
community, | ||
basePath, | ||
}: { | ||
community: PubKeyCommunity | ||
basePath?: string | ||
}) { | ||
return ( | ||
<PubkeyProtocolUiCommunityListItem community={community} basePath={basePath}> | ||
<UiDebug data={{ basePath, community }} open /> | ||
</PubkeyProtocolUiCommunityListItem> | ||
) | ||
} |
23 changes: 23 additions & 0 deletions
23
web/src/app/features/pubkey-community/ui/pubkey-protocol-ui-community-create-form.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,23 @@ | ||
import { PubKeyCommunityCreateInput } from '../data-access' | ||
import { useForm } from '@mantine/form' | ||
import { UiStack } from '@pubkey-ui/core' | ||
import { Button, Group, TextInput } from '@mantine/core' | ||
|
||
export function PubkeyProtocolUiCommunityCreateForm({ | ||
submit, | ||
}: { | ||
submit: (input: PubKeyCommunityCreateInput) => Promise<void> | ||
}) { | ||
const form = useForm<PubKeyCommunityCreateInput>({ initialValues: { avatarUrl: '', name: '', slug: '' } }) | ||
|
||
return ( | ||
<form onSubmit={form.onSubmit((values) => submit({ ...values, name: values.slug }))}> | ||
<UiStack> | ||
<TextInput name="slug" label="Slug" {...form.getInputProps('slug')} /> | ||
<Group justify="right"> | ||
<Button type="submit">Save</Button> | ||
</Group> | ||
</UiStack> | ||
</form> | ||
) | ||
} |
Oops, something went wrong.