Skip to content

Commit

Permalink
fix broken guild channel settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jay3332 committed Jul 13, 2024
1 parent 23b7781 commit 087701b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/components/ui/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,30 @@ export default function ModalContainer(

export function ModalProvider(props: ParentProps) {
const [stack, setStack] = createSignal<ModalDataPair[]>([])
const [hidden, setHidden] = createSignal(true)
const context = {
getModal: () => stack()[stack().length - 1] ?? null,
get id() { return this.getModal()?.[0] },
get data() { return this.getModal()?.[1] },

showModal<T extends ModalId>(id: T, data?: ModalMapping[T]) {
setHidden(false)
setStack(prev => [...prev, [id, data] as ModalDataPair])
},
hideModal() {
setStack(prev => prev.slice(0, -1))
let timeout = 0
if (stack().length === 1) {
setHidden(true)
timeout = 200
}
setTimeout(() => setStack(prev => prev.slice(0, -1)), timeout)
},
}

return (
<ModalContext.Provider value={context}>
{props.children}
<ModalContainer isShowing={() => context.getModal() != null} hide={() => context.hideModal()}>
<ModalContainer isShowing={() => !hidden()} hide={() => context.hideModal()}>
<Switch>
<Match when={context.id === ModalId.NewGuild}>
<NewGuildModal pageSignal={context.data as NewGuildModalPage} />
Expand Down
6 changes: 3 additions & 3 deletions src/pages/channels/settings/GuildChannelSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function GuildChannelSettingsSidebar() {

const guildId = createMemo(() => BigInt(params.guildId))
const channelId = createMemo(() => BigInt(params.channelId))
const channel = createMemo(() => api.cache!.channels.get(channelId())! as GuildChannel)
const channel = createMemo(() => api.cache!.channels.get(channelId()) as GuildChannel | undefined)
const root = createMemo(() => `/guilds/${guildId()}/${channelId()}/settings`)

const perms = createMemo(() => api.cache!.getClientPermissions(guildId(), channelId()))
Expand All @@ -26,7 +26,7 @@ function GuildChannelSettingsSidebar() {
return (
<>
<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>
<span class="font-title">Channel: {channel()?.name}</span>
</div>
<SidebarButton large href={root() + '/overview'} svg={CircleInfo} disabled={!hasModifyChannels()}>
Overview
Expand All @@ -47,7 +47,7 @@ function GuildChannelSettingsSidebar() {
large
svg={Trash}
danger
onClick={() => showModal(ModalId.DeleteChannel, channel())}
onClick={() => channel() && showModal(ModalId.DeleteChannel, channel()!)}
>
Delete Channel
</SidebarButton>
Expand Down

0 comments on commit 087701b

Please sign in to comment.