diff --git a/src/components/common/AgeGate.tsx b/src/components/common/AgeGate.tsx index 324005bb..adfb365d 100644 --- a/src/components/common/AgeGate.tsx +++ b/src/components/common/AgeGate.tsx @@ -1,10 +1,11 @@ +import { observer } from "mobx-react-lite"; import { useHistory } from "react-router-dom"; -import { Channel } from "revolt.js"; import styled from "styled-components"; import { Text } from "preact-i18n"; import { useState } from "preact/hooks"; +import { Channel } from "../../mobx"; import { dispatch, getState } from "../../redux"; import Button from "../ui/Button"; @@ -46,7 +47,7 @@ type Props = { channel: Channel; }; -export default function AgeGate(props: Props) { +export default observer((props: Props) => { const history = useHistory(); const [consent, setConsent] = useState( getState().sectionToggle["nsfw"] ?? false, @@ -105,4 +106,4 @@ export default function AgeGate(props: Props) { ); -} +}); diff --git a/src/components/common/AutoComplete.tsx b/src/components/common/AutoComplete.tsx index faca2ffb..e457cbf8 100644 --- a/src/components/common/AutoComplete.tsx +++ b/src/components/common/AutoComplete.tsx @@ -5,7 +5,7 @@ import styled, { css } from "styled-components"; import { StateUpdater, useState } from "preact/hooks"; -import { User } from "../../mobx"; +import { Channel, User } from "../../mobx"; import { useData } from "../../mobx/State"; import { useClient } from "../../context/revoltjs/RevoltClient"; @@ -28,7 +28,7 @@ export type AutoCompleteState = } | { type: "channel"; - matches: Channels.TextChannel[]; + matches: Channel[]; } )); @@ -197,15 +197,13 @@ export function useAutoComplete( if (type === "channel" && searchClues?.channels) { const channels = client.servers .get(searchClues.channels.server) - ?.channels.map((x) => client.channels.get(x)) - .filter( - (x) => typeof x !== "undefined", - ) as Channels.TextChannel[]; + ?.channels.map((x) => store.channels.get(x)) + .filter((x) => typeof x !== "undefined") as Channel[]; const matches = ( search.length > 0 ? channels.filter((channel) => - channel.name.toLowerCase().match(regex), + channel.name!.toLowerCase().match(regex), ) : channels ) diff --git a/src/components/common/ChannelIcon.tsx b/src/components/common/ChannelIcon.tsx index fb605c7a..301b009a 100644 --- a/src/components/common/ChannelIcon.tsx +++ b/src/components/common/ChannelIcon.tsx @@ -1,65 +1,67 @@ import { Hash, VolumeFull } from "@styled-icons/boxicons-regular"; +import { observer } from "mobx-react-lite"; import { Channels } from "revolt.js/dist/api/objects"; import { useContext } from "preact/hooks"; +import { Channel } from "../../mobx"; + import { AppContext } from "../../context/revoltjs/RevoltClient"; import { ImageIconBase, IconBaseProps } from "./IconBase"; import fallback from "./assets/group.png"; -interface Props - extends IconBaseProps< - Channels.GroupChannel | Channels.TextChannel | Channels.VoiceChannel - > { +interface Props extends IconBaseProps { isServerChannel?: boolean; } -export default function ChannelIcon( - props: Props & Omit, keyof Props>, -) { - const client = useContext(AppContext); +export default observer( + ( + props: Props & Omit, keyof Props>, + ) => { + const client = useContext(AppContext); - const { - size, - target, - attachment, - isServerChannel: server, - animate, - children, - as, - ...imgProps - } = props; - const iconURL = client.generateFileURL( - target?.icon ?? attachment, - { max_side: 256 }, - animate, - ); - const isServerChannel = - server || - (target && - (target.channel_type === "TextChannel" || - target.channel_type === "VoiceChannel")); + const { + size, + target, + attachment, + isServerChannel: server, + animate, + children, + as, + ...imgProps + } = props; + const iconURL = client.generateFileURL( + target?.icon ?? attachment, + { max_side: 256 }, + animate, + ); + const isServerChannel = + server || + (target && + (target.channel_type === "TextChannel" || + target.channel_type === "VoiceChannel")); - if (typeof iconURL === "undefined") { - if (isServerChannel) { - if (target?.channel_type === "VoiceChannel") { - return ; + if (typeof iconURL === "undefined") { + if (isServerChannel) { + if (target?.channel_type === "VoiceChannel") { + return ; + } + return ; } - return ; } - } - return ( - // ! fixme: replace fallback with + -