diff --git a/src/components/servers/customize-pane/ServerCustomizePane.tsx b/src/components/servers/customize-pane/ServerCustomizePane.tsx index ea9831cf..4f0d5c27 100644 --- a/src/components/servers/customize-pane/ServerCustomizePane.tsx +++ b/src/components/servers/customize-pane/ServerCustomizePane.tsx @@ -1,10 +1,27 @@ import styles from "./styles.module.scss"; import { useParams } from "solid-navigator"; -import { For, Setter, Show, batch, createEffect, createSignal, on, onMount } from "solid-js"; +import { + For, + Setter, + Show, + batch, + createEffect, + createSignal, + on, + onMount, +} from "solid-js"; import useStore from "@/chat-api/store/useStore"; -import { addAnswerToMember, getWelcomeQuestions, removeAnswerFromMember, updateWelcomeQuestion } from "@/chat-api/services/ServerService"; -import { RawServerWelcomeAnswer, RawServerWelcomeQuestion } from "@/chat-api/RawData"; +import { + addAnswerToMember, + getWelcomeQuestions, + removeAnswerFromMember, + updateWelcomeQuestion, +} from "@/chat-api/services/ServerService"; +import { + RawServerWelcomeAnswer, + RawServerWelcomeQuestion, +} from "@/chat-api/RawData"; import Checkbox from "@/components/ui/Checkbox"; import Icon from "@/components/ui/icon/Icon"; import Text from "@/components/ui/Text"; @@ -15,105 +32,157 @@ import { RadioBoxItem } from "@/components/ui/RadioBox"; import { SetStoreFunction, createStore, reconcile } from "solid-js/store"; export default function Pane() { - const params = useParams<{serverId: string}>(); + const params = useParams<{ serverId: string }>(); const { header } = useStore(); const [questions, setQuestions] = createStore([]); - - createEffect(on(() => params.serverId, async () => { - const questions = await getWelcomeQuestions(params.serverId!); - setQuestions(reconcile(questions)); - })); + createEffect( + on( + () => params.serverId, + async () => { + const questions = await getWelcomeQuestions(params.serverId!); + setQuestions(reconcile(questions)); + } + ) + ); onMount(() => { header.updateHeader({ title: "Customize", serverId: params.serverId!, - iconName: "tune" + iconName: "tune", }); }); return ( <> -
- +
+
- + ); } const WelcomeMessage = () => { - const params = useParams<{serverId: string}>(); + const params = useParams<{ serverId: string }>(); const store = useStore(); const server = () => store.servers.get(params.serverId!); return (
- {server()?.name} - Complete these questions: + + {server()?.name} + + + Complete these questions: +
); }; -const QuestionList = (props: {questions: RawServerWelcomeQuestion[], updateQuestions: SetStoreFunction}) => { +const QuestionList = (props: { + questions: RawServerWelcomeQuestion[]; + updateQuestions: SetStoreFunction; +}) => { return (
a.order - b.order)}> - {(question) => } + {(question) => ( + + )}
); }; -const QuestionItem = (props: {question: RawServerWelcomeQuestion; questions: RawServerWelcomeQuestion[], updateQuestions: SetStoreFunction}) => { +const QuestionItem = (props: { + question: RawServerWelcomeQuestion; + questions: RawServerWelcomeQuestion[]; + updateQuestions: SetStoreFunction; +}) => { return (
{props.question.title}
- + + +
); }; -const AnswerList = (props: {answers: RawServerWelcomeAnswer[], multiselect: boolean, questions: RawServerWelcomeQuestion[], updateQuestions: SetStoreFunction}) => { +const AnswerList = (props: { + answers: RawServerWelcomeAnswer[]; + multiselect: boolean; + questions: RawServerWelcomeQuestion[]; + updateQuestions: SetStoreFunction; +}) => { return (
a.order - b.order)}> - {(answer) => } + {(answer) => ( + + )}
); }; -const AnswerItem = (props: {answer: RawServerWelcomeAnswer, questions: RawServerWelcomeQuestion[], multiselect: boolean, updateQuestions: SetStoreFunction}) => { - const params = useParams<{serverId: string}>(); +const AnswerItem = (props: { + answer: RawServerWelcomeAnswer; + questions: RawServerWelcomeQuestion[]; + multiselect: boolean; + updateQuestions: SetStoreFunction; +}) => { + const params = useParams<{ serverId: string }>(); + const { serverRoles } = useStore(); const onChange = async (newVal: boolean) => { if (newVal) { await addAnswerToMember(params.serverId, props.answer.id); if (!props.multiselect) { - - const index = props.questions.findIndex(q => q.id === props.answer.questionId); + const index = props.questions.findIndex( + (q) => q.id === props.answer.questionId + ); if (index === -1) return; const answers = props.questions[index]?.answers!; - batch(() => { for (let i = 0; i < answers.length; i++) { const answer = answers[i]; - props.updateQuestions(index, "answers", i, "answered", answer?.id === props.answer.id); + props.updateQuestions( + index, + "answers", + i, + "answered", + answer?.id === props.answer.id + ); } }); } - } - else { + } else { await removeAnswerFromMember(params.serverId, props.answer.id); if (!props.multiselect) { - - const index = props.questions.findIndex(q => q.id === props.answer.questionId); + const index = props.questions.findIndex( + (q) => q.id === props.answer.questionId + ); if (index === -1) return; @@ -127,16 +196,59 @@ const AnswerItem = (props: {answer: RawServerWelcomeAnswer, questions: RawServer } } }; + + const roles = () => + props.answer.roleIds + .map((roleId) => serverRoles.get(params.serverId, roleId)!) + .sort((a, b) => a?.order - b?.order) + .filter((r) => r); return ( -
- onChange(!props.answer.answered)} selected={props.answer.answered} item={{label: props.answer.title, id: props.answer.id}} labelSize={14} class={styles.radioBox} /> - - +
+
+ + onChange(!props.answer.answered)} + selected={props.answer.answered} + item={{ label: props.answer.title, id: props.answer.id }} + labelSize={14} + class={styles.radioBox} + /> + + + + + + + +
+ +
+ + + {(role) => ( +
+
{role.name}
+
+ )} +
+
+
); }; -const UserCount = (props: {count: number}) => { +const UserCount = (props: { count: number }) => { return (
@@ -145,17 +257,28 @@ const UserCount = (props: {count: number}) => { ); }; - const ContinueFooter = () => { - const params = useParams<{serverId: string}>(); + const params = useParams<{ serverId: string }>(); const store = useStore(); const server = () => store.servers.get(params.serverId!); const defaultChannel = () => store.channels.get(server()?.defaultChannelId); return ( - -