Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { For, Show, createMemo, createSignal } from "solid-js";
import { For, createMemo } from "solid-js";

import { Trans, useLingui } from "@lingui/solid/macro";
import { createFormControl, createFormGroup } from "solid-forms";
Expand All @@ -10,12 +10,11 @@ import { useInstance } from "@revolt/instance";
import { useModals } from "@revolt/modal";
import { useState } from "@revolt/state";
import {
Button,
CategoryButton,
ColourPicker,
ColouredText,
Column,
Form2,
Ripple,
Text,
typography,
} from "@revolt/ui";
Expand All @@ -25,60 +24,13 @@ import { createMaterialColourVariables } from "@revolt/ui/themes";
import { useSettingsNavigation } from "../../Settings";
import { ChannelPermissionsEditor } from "../../channel/permissions/ChannelPermissionsEditor";

const ROLE_COLOUR_PALETTE = [
[
"#fca5a5",
"#fdba74",
"#fcd34d",
"#86efac",
"#6ee7b7",
"#67e8f9",
"#93c5fd",
"#c4b5fd",
"#f0abfc",
"#f9a8d4",
"#cbd5e1",
],
[
"#ef4444",
"#f97316",
"#f59e0b",
"#22c55e",
"#10b981",
"#06b6d4",
"#3b82f6",
"#8b5cf6",
"#d946ef",
"#ec4899",
"#64748b",
],
[
"#991b1b",
"#9a3412",
"#92400e",
"#166534",
"#065f46",
"#155e75",
"#1e40af",
"#5b21b6",
"#86198f",
"#9d174d",
"#1e293b",
],
] as const;

const ROLE_COLOUR_VALUES: ReadonlySet<string> = new Set(
ROLE_COLOUR_PALETTE.flat(),
);

function RoleColourPicker(props: {
colour: string | null;
roleName: string;
onChange: (colour: string | null) => void;
}) {
const { t } = useLingui();
const state = useState();
const [pickerRef, setPickerRef] = createSignal<HTMLInputElement>();

const colourPreviews = createMemo(() => {
const theme = state.theme.activeTheme;
Expand All @@ -101,90 +53,14 @@ function RoleColourPicker(props: {
];
});

function isSelectedColour(colour: string) {
return props.colour?.toLowerCase() === colour;
}

function isCustomColour() {
const colour = props.colour?.toLowerCase();
return !!colour && !ROLE_COLOUR_VALUES.has(colour);
}

return (
<RoleColourControls>
<ColourSelector gap="md">
<Text class="label">
<Trans>Role Colour</Trans>
</Text>

<ColourPalette>
<For each={ROLE_COLOUR_PALETTE}>
{(row) => (
<For each={row}>
{(colour) => (
<ColourSwatch
type="button"
selected={isSelectedColour(colour)}
aria-label={t`Set role colour to ${colour}`}
aria-pressed={isSelectedColour(colour)}
style={{ background: colour }}
onClick={() => props.onChange(colour)}
>
<Ripple />
</ColourSwatch>
)}
</For>
)}
</For>
</ColourPalette>

<ColourActions>
<Button
size="sm"
variant={isCustomColour() ? "tonal" : "outlined"}
onPress={() => pickerRef()?.click()}
>
<ColourActionContent>
<Show
when={isCustomColour()}
fallback={
<Symbol size={20} marginRight="var(--gap-sm)">
palette
</Symbol>
}
>
<CustomColourIndicator
style={{ background: props.colour ?? "transparent" }}
/>
</Show>{" "}
<Trans>Custom colour</Trans>
</ColourActionContent>
</Button>
<input
ref={setPickerRef}
type="color"
value={props.colour ?? "#ffffff"}
onInput={(event) => props.onChange(event.currentTarget.value)}
style={{
position: "absolute",
opacity: 0,
width: "0px",
height: "0px",
padding: 0,
border: "none",
}}
/>
<Button
size="sm"
variant={props.colour === null ? "tonal" : "outlined"}
onPress={() => props.onChange(null)}
>
<ColourActionContent>
<NoColourIndicator /> <Trans>Default</Trans>
</ColourActionContent>
</Button>
</ColourActions>
</ColourSelector>
<ColourPicker
label={<Trans>Role Colour</Trans>}
colour={props.colour}
swatchLabel={(colour) => t`Set role colour to ${colour}`}
onChange={props.onChange}
/>

<ColourPreview>
<Text class="label">
Expand Down Expand Up @@ -390,27 +266,6 @@ export const Divider = styled("div", {
},
});

const NoColourIndicator = styled("span", {
base: {
width: "18px",
height: "18px",
flexShrink: 0,
borderRadius: "var(--borderRadius-full)",
border: "2px dashed var(--md-sys-color-on-surface-variant)",
marginRight: "var(--gap-sm)",
},
});

const CustomColourIndicator = styled("span", {
base: {
width: "18px",
height: "18px",
flexShrink: 0,
borderRadius: "50%",
marginRight: "var(--gap-sm)",
},
});

const RoleColourControls = styled("div", {
base: {
width: "100%",
Expand All @@ -421,14 +276,6 @@ const RoleColourControls = styled("div", {
},
});

const ColourSelector = styled(Column, {
base: {
width: "fit-content",
maxWidth: "100%",
flexShrink: 0,
},
});

const ColourPreview = styled("div", {
base: {
width: "220px",
Expand Down Expand Up @@ -493,62 +340,3 @@ const PreviewBody = styled("span", {
...typography.raw({ class: "_messages" }),
},
});

const ColourPalette = styled("div", {
base: {
width: "100%",
display: "grid",
gridTemplateColumns: "repeat(11, minmax(0, 36px))",
gap: "var(--gap-sm)",
},
});

const ColourSwatch = styled("button", {
base: {
width: "100%",
aspectRatio: "1 / 1",
padding: 0,
border: 0,
borderRadius: "50%",
cursor: "pointer",
position: "relative",
overflow: "hidden",
transition: "border-radius 200ms cubic-bezier(0.2, 0, 0, 1)",

_focusVisible: {
outline: "2px solid var(--md-sys-color-on-surface)",
outlineOffset: "2px",
},
},
variants: {
selected: {
true: {
borderRadius: "var(--borderRadius-md)",
},
},
},
});

const ColourActions = styled("div", {
base: {
width: "100%",
display: "grid",
gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
gap: "var(--gap-sm)",
position: "relative",
},
});

const ColourActionContent = styled("span", {
base: {
display: "flex",
alignItems: "center",
justifyContent: "center",
gap: "var(--gap-sm)",

"& svg": {
width: "20px",
height: "20px",
},
},
});
44 changes: 44 additions & 0 deletions packages/client/components/app/menus/ServerContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import MdFolder from "@material-design-icons/svg/outlined/folder.svg?component-solid";
import { For, Show } from "solid-js";

import { Trans } from "@lingui/solid/macro";
Expand All @@ -11,7 +12,9 @@ import { Column, Text, Time } from "@revolt/ui";

import MdAlternateEmail from "@material-design-icons/svg/outlined/alternate_email.svg?component-solid";
import MdBadge from "@material-design-icons/svg/outlined/badge.svg?component-solid";
import MdCreateNewFolder from "@material-design-icons/svg/outlined/create_new_folder.svg?component-solid";
import MdFace from "@material-design-icons/svg/outlined/face.svg?component-solid";
import MdFolderOff from "@material-design-icons/svg/outlined/folder_off.svg?component-solid";
import MdLogout from "@material-design-icons/svg/outlined/logout.svg?component-solid";
import MdMarkChatRead from "@material-design-icons/svg/outlined/mark_chat_read.svg?component-solid";
import MdNotificationsActive from "@material-design-icons/svg/outlined/notifications_active.svg?component-solid";
Expand Down Expand Up @@ -233,6 +236,47 @@ export function ServerContextMenu(props: { server: Server }) {
</ContextMenuSubMenu>
</Show>

<ContextMenuSubMenu
onClick={() =>
state.ordering.createFolder("New Folder", [props.server.id])
}
icon={MdFolder}
buttonContent={<Trans>Add to folder</Trans>}
>
<For each={state.ordering.folders()}>
{(folder) => (
<ContextMenuButton
onClick={() =>
state.ordering.addToFolder(folder.id, props.server.id)
}
>
<Show when={folder.name} fallback={<Trans>Unnamed folder</Trans>}>
{folder.name}
</Show>
</ContextMenuButton>
)}
</For>
<ContextMenuButton
icon={MdCreateNewFolder}
onClick={() =>
state.ordering.createFolder("New Folder", [props.server.id])
}
>
<Trans>New folder</Trans>
</ContextMenuButton>
</ContextMenuSubMenu>

<Show when={state.ordering.folderOf(props.server.id)}>
<ContextMenuButton
icon={MdFolderOff}
onClick={() => state.ordering.removeFromFolder(props.server.id)}
>
<Trans>Remove from folder</Trans>
</ContextMenuButton>
</Show>

<ContextMenuDivider />

<ContextMenuSubMenu
symbol={MdNotificationSettings}
buttonContent={<Trans>Notifications</Trans>}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Trans } from "@lingui/solid/macro";

import { useModals } from "@revolt/modal";
import { ServerFolder, useState } from "@revolt/state";

import MdDelete from "@material-design-icons/svg/outlined/delete.svg?component-solid";
import MdDriveFileRenameOutline from "@material-design-icons/svg/outlined/drive_file_rename_outline.svg?component-solid";

import {
ContextMenu,
ContextMenuButton,
ContextMenuDivider,
} from "./ContextMenu";

/**
* Context menu for server folders
*/
export function ServerFolderContextMenu(props: { folder: ServerFolder }) {
const state = useState();
const { openModal } = useModals();

/**
* Rename the folder
*/
function rename() {
openModal({
type: "edit_server_folder",
folder: props.folder,
});
}

/**
* Remove the folder, keeping its servers
*/
function remove() {
state.ordering.deleteFolder(props.folder.id);
}

return (
<ContextMenu>
<ContextMenuButton icon={MdDriveFileRenameOutline} onClick={rename}>
<Trans>Edit folder</Trans>
</ContextMenuButton>
<ContextMenuDivider />
<ContextMenuButton icon={MdDelete} destructive onClick={remove}>
<Trans>Delete folder</Trans>
</ContextMenuButton>
</ContextMenu>
);
}
Loading
Loading