Files
ThreadNet-Web/src/components/structures/NotificationPanel.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
3.6 KiB
TypeScript
Raw Normal View History

2016-08-23 14:30:15 +01:00
/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
Copyright 2016-2022 The Matrix.org Foundation C.I.C.
2016-08-23 14:30:15 +01:00
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
2024-09-09 14:57:16 +01:00
Please see LICENSE files in the repository root for full details.
2016-08-23 14:30:15 +01:00
*/
2021-05-25 12:15:37 +01:00
import React from "react";
2021-10-22 17:23:32 -05:00
import { logger } from "matrix-js-sdk/src/logger";
import NotificationsIcon from "@vector-im/compound-design-tokens/assets/web/icons/notifications";
2020-09-08 10:19:51 +01:00
2017-05-25 11:39:08 +01:00
import { _t } from "../../languageHandler";
2021-06-03 08:41:22 +01:00
import { MatrixClientPeg } from "../../MatrixClientPeg";
2020-09-08 10:19:51 +01:00
import BaseCard from "../views/right_panel/BaseCard";
2021-05-25 12:15:37 +01:00
import TimelinePanel from "./TimelinePanel";
import Spinner from "../views/elements/Spinner";
import { Layout } from "../../settings/enums/Layout";
2021-10-11 11:26:05 +02:00
import RoomContext, { TimelineRenderingType } from "../../contexts/RoomContext";
import Measured from "../views/elements/Measured";
import EmptyState from "../views/right_panel/EmptyState";
import { ScopedRoomContextProvider } from "../../contexts/ScopedRoomContext.tsx";
2021-05-25 12:15:37 +01:00
interface IProps {
onClose(): void;
}
2016-08-23 14:30:15 +01:00
interface IState {
narrow: boolean;
}
2016-08-23 14:30:15 +01:00
/*
* Component which shows the global notification list using a TimelinePanel
2016-08-23 14:30:15 +01:00
*/
export default class NotificationPanel extends React.PureComponent<IProps, IState> {
public static contextType = RoomContext;
2024-12-02 09:39:36 +00:00
declare public context: React.ContextType<typeof RoomContext>;
private card = React.createRef<HTMLDivElement>();
2024-08-01 13:01:05 +01:00
public constructor(props: IProps, context: React.ContextType<typeof RoomContext>) {
super(props, context);
this.state = {
narrow: false,
};
}
private onMeasurement = (narrow: boolean): void => {
this.setState({ narrow });
};
public render(): React.ReactNode {
const emptyState = (
<EmptyState
Icon={NotificationsIcon}
title={_t("notif_panel|empty_heading")}
description={_t("notif_panel|empty_description")}
/>
);
let content: JSX.Element;
const timelineSet = MatrixClientPeg.safeGet().getNotifTimelineSet();
2016-09-08 03:02:31 +01:00
if (timelineSet) {
2021-05-25 12:15:37 +01:00
// wrap a TimelinePanel with the jump-to-event bits turned off.
2020-09-08 10:19:51 +01:00
content = (
<TimelinePanel
manageReadReceipts={false}
manageReadMarkers={false}
timelineSet={timelineSet}
showUrlPreview={false}
empty={emptyState}
alwaysShowTimestamps={true}
layout={Layout.Group}
2020-09-08 10:19:51 +01:00
/>
2016-09-08 03:02:31 +01:00
);
2017-10-11 17:56:17 +01:00
} else {
2021-10-15 16:30:53 +02:00
logger.error("No notifTimelineSet available!");
2021-05-25 12:15:37 +01:00
content = <Spinner />;
2016-09-08 03:02:31 +01:00
}
2020-09-08 10:19:51 +01:00
2021-10-11 11:26:05 +02:00
return (
<ScopedRoomContextProvider
{...this.context}
timelineRenderingType={TimelineRenderingType.Notification}
narrow={this.state.narrow}
2021-10-11 11:26:05 +02:00
>
<BaseCard
header={_t("notifications|enable_prompt_toast_title")}
/**
* Need to rename this CSS class to something more generic
* Will be done once all the panels are using a similar layout
*/
className="mx_ThreadPanel"
onClose={this.props.onClose}
withoutScrollContainer={true}
>
{this.card.current && <Measured sensor={this.card.current} onMeasurement={this.onMeasurement} />}
2021-10-11 11:26:05 +02:00
{content}
2021-10-11 14:33:40 -04:00
</BaseCard>
</ScopedRoomContextProvider>
2021-10-11 11:26:05 +02:00
);
2020-08-29 12:14:16 +01:00
}
}