import { At, Bell, BellOff, Check, CheckSquare, Block, Square, LeftArrowAlt, } from "@styled-icons/boxicons-regular"; import { observer } from "mobx-react-lite"; import { Channel } from "revolt.js/dist/maps/Channels"; import { Server } from "revolt.js/dist/maps/Servers"; import { ContextMenuWithData, MenuItem } from "preact-context-menu"; import { Text } from "preact-i18n"; import { useApplicationState } from "../../mobx/State"; import { NotificationState } from "../../mobx/stores/NotificationOptions"; import LineDivider from "../../components/ui/LineDivider"; import { Children } from "../../types/Preact"; interface Action { key: string; type: "channel" | "server"; state?: NotificationState; } /** * Provides a context menu for controlling notification options. */ export default observer(() => { const notifications = useApplicationState().notifications; const contextClick = (data?: Action) => data && (data.type === "channel" ? notifications.setChannelState(data.key, data.state) : notifications.setServerState(data.key, data.state)); return ( {({ channel, server }: { channel?: Channel; server?: Server }) => { // Find the computed and actual state values for channel / server. const state = channel ? notifications.getChannelState(channel._id) : notifications.computeForServer(server!._id); const actual = channel ? notifications.computeForChannel(channel) : undefined; // If we're editing channel, show a default option too. const elements: Children[] = channel ? [
{state !== undefined && } {state === undefined && ( )}
, , ] : []; /** * Generate a new entry we can select. * @param key Notification state * @param icon Icon for this state */ function generate(key: string, icon: Children) { elements.push( {icon} {state === undefined && actual === key && (
)} {state === key && (
)}
, ); } generate("all", ); generate("mention", ); generate("none", ); generate("muted", ); return elements; }}
); });