Skip to content

Commit

Permalink
fix bot modals
Browse files Browse the repository at this point in the history
  • Loading branch information
jay3332 committed Jul 13, 2024
1 parent 5c78b70 commit 23b7781
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
7 changes: 4 additions & 3 deletions src/components/settings/CreateBotModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ModalTemplate} from "../ui/Modal";
import {ModalTemplate, useModal} from "../ui/Modal";
import Icon from "../icons/Icon";
import RocketLaunch from "../icons/svg/RocketLaunch";
import {createEffect, createSignal, Setter} from "solid-js";
Expand All @@ -8,7 +8,6 @@ import {useNavigate} from "@solidjs/router";

export default function CreateBotModal(props: {
setBots: Setter<Bot[] | null>,
setShow: Setter<boolean>,
}) {
const api = getApi()!
const navigate = useNavigate()
Expand All @@ -24,6 +23,8 @@ export default function CreateBotModal(props: {
const [focused, setFocused] = createSignal(false)
const [submitting, setSubmitting] = createSignal(false)

const {hideModal} = useModal()

const createBot = async (e: SubmitEvent) => {
e.preventDefault()

Expand All @@ -37,7 +38,7 @@ export default function CreateBotModal(props: {

const data = response.jsonOrThrow() as Bot & { token: string }
props.setBots(bots => bots ? [...bots, data] : [data])
props.setShow(false)
hideModal()
navigate(`/settings/bots/${data.user.id}`, { state: { token: data.token } })
}

Expand Down
9 changes: 8 additions & 1 deletion src/components/ui/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
createEffect,
createSignal,
Match,
ParentProps,
ParentProps, Setter,
Switch,
useContext
} from "solid-js";
Expand All @@ -24,6 +24,8 @@ import CreateRoleModal from "../guilds/CreateRoleModal";
import ConfirmRoleDeleteModal from "../guilds/ConfirmRoleDeleteModal";
import AddFriendModal from "../friends/AddFriendModal";
import SetPresence from "../users/SetPresenceModal";
import CreateBotModal from "../settings/CreateBotModal";
import {Bot} from "../../types/user";

export enum ModalId {
NewGuild,
Expand All @@ -37,6 +39,7 @@ export enum ModalId {
DeleteRole,
AddFriend,
UpdatePresence,
CreateBot,
}

type ModalMapping = {
Expand All @@ -51,6 +54,7 @@ type ModalMapping = {
[ModalId.DeleteRole]: Role,
[ModalId.AddFriend]: undefined,
[ModalId.UpdatePresence]: undefined,
[ModalId.CreateBot]: Setter<Bot[] | null>,
}

type ModalDataPair = {
Expand Down Expand Up @@ -167,6 +171,9 @@ export function ModalProvider(props: ParentProps) {
<Match when={context.id === ModalId.UpdatePresence}>
<SetPresence />
</Match>
<Match when={context.id === ModalId.CreateBot}>
<CreateBotModal setBots={context.data as Setter<Bot[] | null>} />
</Match>
</Switch>
</ModalContainer>
</ModalContext.Provider>
Expand Down
12 changes: 4 additions & 8 deletions src/pages/channels/settings/GuildChannelSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import SidebarButton from "../../../components/ui/SidebarButton";
import {generateSettingsComponents} from "../../settings/SettingsLayout";
import {createMemo, createSignal, Show} from "solid-js";
import {createMemo, Show} from "solid-js";
import {useParams} from "@solidjs/router";
import {getApi} from "../../../api/Api";
import Trash from "../../../components/icons/svg/Trash";
import CircleInfo from "../../../components/icons/svg/CircleInfo";
import UserTag from "../../../components/icons/svg/UserTag";
import Modal from "../../../components/ui/Modal";
import ConfirmChannelDeleteModal from "../../../components/channels/ConfirmChannelDeleteModal";
import {GuildChannel} from "../../../types/channel";
import {ModalId, useModal} from "../../../components/ui/Modal";

function GuildChannelSettingsSidebar() {
const params = useParams()
Expand All @@ -22,13 +21,10 @@ function GuildChannelSettingsSidebar() {
const perms = createMemo(() => api.cache!.getClientPermissions(guildId(), channelId()))
const hasModifyChannels = () => perms().has('MODIFY_CHANNELS')

const [confirmDelete, setConfirmDelete] = createSignal(false)
const {showModal} = useModal()

return (
<>
<Modal get={confirmDelete} set={setConfirmDelete}>
<ConfirmChannelDeleteModal channel={channel()} setConfirmChannelDeleteModal={setConfirmDelete} />
</Modal>
<div class="flex px-1 py-2 text-fg/50 mobile:text-sm mobile:px-1 mobile:pt-0 items-center gap-x-1">
<span class="font-title">Channel: {channel().name}</span>
</div>
Expand All @@ -51,7 +47,7 @@ function GuildChannelSettingsSidebar() {
large
svg={Trash}
danger
onClick={() => setConfirmDelete(true)}
onClick={() => showModal(ModalId.DeleteChannel, channel())}
>
Delete Channel
</SidebarButton>
Expand Down
13 changes: 5 additions & 8 deletions src/pages/settings/Bots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import Fuse from "fuse.js";
import Xmark from "../../components/icons/svg/Xmark";
import Plus from "../../components/icons/svg/Plus";
import Robot from "../../components/icons/svg/Robot";
import Modal from "../../components/ui/Modal";
import CreateBotModal from "../../components/settings/CreateBotModal";
import {ModalId, useModal} from "../../components/ui/Modal";
import {displayName} from "../../utils";
import {A} from "@solidjs/router";
import {defaultAvatar} from "../../api/ApiCache";
Expand Down Expand Up @@ -56,14 +55,12 @@ export default function Bots() {
: bots()
)

const [showCreateBotModal, setShowCreateBotModal] = createSignal(false)
const {showModal} = useModal()
const showCreateBotModal = () => showModal(ModalId.CreateBot, setBots)

return (
<div class="p-4">
<Header>Bots</Header>
<Modal get={showCreateBotModal} set={setShowCreateBotModal}>
<CreateBotModal setBots={setBots} setShow={setShowCreateBotModal} />
</Modal>
<p class="text-sm font-light text-fg/60">
Bots are used to automate tasks and provide additional functionality throughout Adapt.
</p>
Expand Down Expand Up @@ -101,7 +98,7 @@ export default function Bots() {
/>
</Show>
</div>
<button class="btn btn-primary btn-sm rounded-xl flex gap-x-1" onClick={() => setShowCreateBotModal(true)}>
<button class="btn btn-primary btn-sm rounded-xl flex gap-x-1" onClick={showCreateBotModal}>
<Icon icon={Plus} class="w-4 h-4 fill-fg"/>
<span>New Bot</span>
</button>
Expand All @@ -122,7 +119,7 @@ export default function Bots() {
<Show when={searchQuery()} fallback={
<>
No bots yet...
<button class="btn btn-ghost btn-sm rounded-xl flex gap-x-1" onClick={() => setShowCreateBotModal(true)}>
<button class="btn btn-ghost btn-sm rounded-xl flex gap-x-1" onClick={showCreateBotModal}>
<span>Create one?</span>
</button>
</>
Expand Down

0 comments on commit 23b7781

Please sign in to comment.