From 28de4d4704c41e13fd6077093b6c59dac7b6bff3 Mon Sep 17 00:00:00 2001 From: hzrd149 Date: Mon, 23 Oct 2023 13:01:23 -0500 Subject: [PATCH] Add community create and edit modals --- .changeset/soft-eagles-smash.md | 5 + src/helpers/nostr/communities.ts | 3 + .../components/community-create-modal.tsx | 150 +++++++++++++++++ src/views/communities/index.tsx | 111 ++++++++++--- src/views/community/community-home.tsx | 157 ++++++++++-------- .../components/community-edit-modal.tsx | 88 ++++++++++ .../community/components/community-menu.tsx | 11 +- .../horizonal-community-details.tsx | 5 +- .../components/vertical-community-details.tsx | 5 +- 9 files changed, 432 insertions(+), 103 deletions(-) create mode 100644 .changeset/soft-eagles-smash.md create mode 100644 src/views/communities/components/community-create-modal.tsx create mode 100644 src/views/community/components/community-edit-modal.tsx diff --git a/.changeset/soft-eagles-smash.md b/.changeset/soft-eagles-smash.md new file mode 100644 index 000000000..21ec0f4c1 --- /dev/null +++ b/.changeset/soft-eagles-smash.md @@ -0,0 +1,5 @@ +--- +"nostrudel": minor +--- + +Add community create and edit modals diff --git a/src/helpers/nostr/communities.ts b/src/helpers/nostr/communities.ts index b0b48e337..a122ff4b5 100644 --- a/src/helpers/nostr/communities.ts +++ b/src/helpers/nostr/communities.ts @@ -29,6 +29,9 @@ export function getCommunityDescription(community: NostrEvent) { export function getCommunityRules(community: NostrEvent) { return community.tags.find((t) => t[0] === "rules")?.[1]; } +export function getCommunityRanking(community: NostrEvent) { + return community.tags.find((t) => t[0] === "rank_mode")?.[1]; +} export function getPostSubject(event: NostrEvent) { const subject = event.tags.find((t) => t[0] === "subject")?.[1]; diff --git a/src/views/communities/components/community-create-modal.tsx b/src/views/communities/components/community-create-modal.tsx new file mode 100644 index 000000000..cc2b50ff8 --- /dev/null +++ b/src/views/communities/components/community-create-modal.tsx @@ -0,0 +1,150 @@ +import { + Button, + Flex, + FormControl, + FormErrorMessage, + FormHelperText, + FormLabel, + Input, + Modal, + ModalBody, + ModalCloseButton, + ModalContent, + ModalFooter, + ModalHeader, + ModalOverlay, + ModalProps, + Radio, + RadioGroup, + Stack, + Textarea, +} from "@chakra-ui/react"; +import { SubmitHandler, useForm } from "react-hook-form"; +import { useCurrentAccount } from "../../../hooks/use-current-account"; +import UserAvatar from "../../../components/user-avatar"; +import { UserLink } from "../../../components/user-link"; + +export type FormValues = { + name: string; + banner: string; + description: string; + rules: string; + mods: string[]; + relays: string[]; + ranking: string; +}; + +export default function CommunityCreateModal({ + isOpen, + onClose, + onSubmit, + defaultValues, + isUpdate, + ...props +}: Omit & { + onSubmit: SubmitHandler; + defaultValues?: FormValues; + isUpdate?: boolean; +}) { + const account = useCurrentAccount(); + + const { + register, + formState: { errors }, + handleSubmit, + watch, + getValues, + setValue, + } = useForm({ + mode: "all", + defaultValues: defaultValues || { + name: "", + banner: "", + description: "", + rules: "", + mods: account ? [account.pubkey] : [], + relays: [], + ranking: "votes", + }, + }); + + watch("mods"); + watch("ranking"); + + return ( + + + + {isUpdate ? "Update Community" : "Create Community"} + + + {!isUpdate && ( + + Community Name + { + if (/\p{Z}/iu.test(v)) return "Must not have spaces"; + return true; + }, + })} + isReadOnly={isUpdate} + autoComplete="off" + /> + The name of your community (no-spaces) + {errors.name?.message && {errors.name?.message}} + + )} + + + Description +