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
18 changes: 14 additions & 4 deletions packages/client/components/app/menus/CategoryContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ export function CategoryContextMenu(props: {
.forEach((channel) => channel.ack());
}

/**
* Create a new channel
*/
function createChannel() {
openModal({
type: "create_channel",
server: props.server,
categoryId: props.category.id,
});
}

/**
* Create a new category
*/
Expand Down Expand Up @@ -95,19 +106,18 @@ export function CategoryContextMenu(props: {
</Show>

<Show when={props.server.havePermission("ManageChannel")}>
<ContextMenuButton icon={MdLibraryAdd} onClick={createChannel}>
<Trans>Create channel</Trans>
</ContextMenuButton>
<ContextMenuButton icon={MdLibraryAdd} onClick={createCategory}>
<Trans>Create category</Trans>
</ContextMenuButton>
</Show>
<Show when={props.server.havePermission("ManageChannel")}>
<ContextMenuButton
icon={<Symbol size={16}>edit</Symbol>}
onClick={editCategoryName}
>
<Trans>Rename category</Trans>
</ContextMenuButton>
</Show>
<Show when={props.server.havePermission("ManageChannel")}>
<ContextMenuButton icon={MdDelete} onClick={deleteCategory} destructive>
<Trans>Delete category</Trans>
</ContextMenuButton>
Expand Down
21 changes: 21 additions & 0 deletions packages/client/components/app/menus/ChannelContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,31 @@ export function ChannelContextMenu(props: { channel: Channel }) {
});
}

function getCategory(channel: Channel) {
const cats = channel.server!.orderedChannels;
let cat, ch;
for (cat of cats)
for (ch of cat.channels) if (ch.id === channel.id) return cat.id;
}

/**
* Create a new channel
*/
function createChannel() {
openModal({
type: "create_channel",
server: props.channel.server!,
categoryId: getCategory(props.channel),
});
}

/**
* Create a new category
*/
function createCategory() {
openModal({
type: "create_category",
server: props.channel.server!,
});
}

Expand Down Expand Up @@ -134,6 +152,9 @@ export function ChannelContextMenu(props: { channel: Channel }) {
<ContextMenuButton icon={MdLibraryAdd} onClick={createChannel}>
<Trans>Create channel</Trans>
</ContextMenuButton>
<ContextMenuButton icon={MdLibraryAdd} onClick={createCategory}>
<Trans>Create category</Trans>
</ContextMenuButton>
</Show>
<Show when={props.channel.havePermission("ManageChannel")}>
<ContextMenuButton icon={MdSettings} onClick={editChannel}>
Expand Down
17 changes: 16 additions & 1 deletion packages/client/components/modal/modals/CreateChannel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,25 @@ export function CreateChannelModal(
name: group.controls.name.value,
});

//Reorder categories
const newChId = channel.id,
catId = props.categoryId;
if (catId && catId !== "default") {
let ch, chIds;
props.server.edit({
categories: props.server.orderedChannels.map((cat) => {
chIds = [];
for (ch of cat.channels) if (ch.id !== newChId) chIds.push(ch.id);
if (cat.id === catId) chIds.push(newChId);
return { ...cat, channels: chIds };
}),
});
}

if (props.cb) {
props.cb(channel);
} else {
navigate(`/server/${props.server.id}/channel/${channel.id}`);
navigate(`/server/${props.server.id}/channel/${newChId}`);
}

props.onClose();
Expand Down
1 change: 1 addition & 0 deletions packages/client/components/modal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export type Modals =
| {
type: "create_channel";
server: Server;
categoryId?: string;
cb?: (channel: Channel) => void;
}
| {
Expand Down
Loading