forked from element-hq/element-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoomListItemNotificationMenu.tsx
More file actions
106 lines (100 loc) · 4.43 KB
/
RoomListItemNotificationMenu.tsx
File metadata and controls
106 lines (100 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import React, { useState, type JSX } from "react";
import { IconButton, Menu, MenuItem } from "@vector-im/compound-web";
import {
NotificationsSolidIcon,
NotificationsOffSolidIcon,
CheckIcon,
} from "@vector-im/compound-design-tokens/assets/web/icons";
import { _t } from "../../../../core/i18n/i18n";
import { RoomNotifState } from "./RoomNotifs";
import { useViewModel, type ViewModel } from "../../../../core/viewmodel";
import type { RoomListItemViewSnapshot, RoomListItemViewActions } from "./RoomListItemView";
/**
* View model type for room list item
*/
export type RoomListItemViewModel = ViewModel<RoomListItemViewSnapshot, RoomListItemViewActions>;
/**
* Props for RoomListItemNotificationMenu component
*/
export interface RoomListItemNotificationMenuProps {
/** The room item view model */
vm: RoomListItemViewModel;
}
/**
* The notification settings menu for room list items.
* Displays options to change notification settings.
*/
export function RoomListItemNotificationMenu({ vm }: RoomListItemNotificationMenuProps): JSX.Element {
const snapshot = useViewModel(vm);
const [open, setOpen] = useState(false);
const isMuted = snapshot.roomNotifState === RoomNotifState.Mute;
const checkComponent = <CheckIcon width="24px" height="24px" color="var(--cpd-color-icon-primary)" />;
return (
<Menu
open={open}
onOpenChange={setOpen}
title={_t("room_list|notification_options")}
showTitle={false}
align="start"
trigger={
<IconButton
size="24px"
style={{ padding: "2px" }}
tooltip={_t("room_list|notification_options")}
aria-label={_t("room_list|notification_options")}
>
{isMuted ? <NotificationsOffSolidIcon /> : <NotificationsSolidIcon />}
</IconButton>
}
>
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
<div
// We don't want keyboard navigation events to bubble up to the ListView changing the focused item
onKeyDown={(e) => e.stopPropagation()}
>
<MenuItem
aria-selected={snapshot.roomNotifState === RoomNotifState.AllMessages}
hideChevron={true}
label={_t("notifications|default_settings")}
onSelect={() => vm.onSetRoomNotifState(RoomNotifState.AllMessages)}
onClick={(evt) => evt.stopPropagation()}
>
{snapshot.roomNotifState === RoomNotifState.AllMessages && checkComponent}
</MenuItem>
<MenuItem
aria-selected={snapshot.roomNotifState === RoomNotifState.AllMessagesLoud}
hideChevron={true}
label={_t("notifications|all_messages")}
onSelect={() => vm.onSetRoomNotifState(RoomNotifState.AllMessagesLoud)}
onClick={(evt) => evt.stopPropagation()}
>
{snapshot.roomNotifState === RoomNotifState.AllMessagesLoud && checkComponent}
</MenuItem>
<MenuItem
aria-selected={snapshot.roomNotifState === RoomNotifState.MentionsOnly}
hideChevron={true}
label={_t("notifications|mentions_keywords")}
onSelect={() => vm.onSetRoomNotifState(RoomNotifState.MentionsOnly)}
onClick={(evt) => evt.stopPropagation()}
>
{snapshot.roomNotifState === RoomNotifState.MentionsOnly && checkComponent}
</MenuItem>
<MenuItem
aria-selected={snapshot.roomNotifState === RoomNotifState.Mute}
hideChevron={true}
label={_t("notifications|mute_room")}
onSelect={() => vm.onSetRoomNotifState(RoomNotifState.Mute)}
onClick={(evt) => evt.stopPropagation()}
>
{snapshot.roomNotifState === RoomNotifState.Mute && checkComponent}
</MenuItem>
</div>
</Menu>
);
}