element-portable/src/components/views/dialogs/UnpinAllDialog.tsx
David Langley 491f0cd08a
Change license (#13)
* Copyright headers 1

* Licence headers 2

* Copyright Headers 3

* Copyright Headers 4

* Copyright Headers 5

* Copyright Headers 6

* Copyright headers 7

* Add copyright headers for html and config file

* Replace license files and update package.json

* Update with CLA

* lint
2024-09-09 13:57:16 +00:00

72 lines
2.3 KiB
TypeScript

/*
* Copyright 2024 New Vector Ltd.
* Copyright 2024 The Matrix.org Foundation C.I.C.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
* Please see LICENSE files in the repository root for full details.
*/
import React, { JSX } from "react";
import { Button, Text } from "@vector-im/compound-web";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger";
import BaseDialog from "../dialogs/BaseDialog";
import { _t } from "../../../languageHandler";
import PinningUtils from "../../../utils/PinningUtils.ts";
import PosthogTrackers from "../../../PosthogTrackers.ts";
/**
* Properties for {@link UnpinAllDialog}.
*/
interface UnpinAllDialogProps {
/*
* The matrix client to use.
*/
matrixClient: MatrixClient;
/*
* The room ID to unpin all events in.
*/
roomId: string;
/*
* Callback for when the dialog is closed.
*/
onFinished: () => void;
}
/**
* A dialog that asks the user to confirm unpinning all events in a room.
*/
export function UnpinAllDialog({ matrixClient, roomId, onFinished }: UnpinAllDialogProps): JSX.Element {
return (
<BaseDialog
hasCancel={true}
title={_t("right_panel|pinned_messages|unpin_all|title")}
titleClass="mx_UnpinAllDialog_title"
className="mx_UnpinAllDialog"
onFinished={onFinished}
fixedWidth={false}
>
<Text as="span">{_t("right_panel|pinned_messages|unpin_all|content")}</Text>
<div className="mx_UnpinAllDialog_buttons">
<Button
destructive={true}
onClick={async () => {
try {
await PinningUtils.unpinAllEvents(matrixClient, roomId);
PosthogTrackers.trackPinUnpinMessage("Unpin", "UnpinAll");
} catch (e) {
logger.error("Failed to unpin all events:", e);
}
onFinished();
}}
>
{_t("action|continue")}
</Button>
<Button kind="tertiary" onClick={onFinished}>
{_t("action|cancel")}
</Button>
</div>
</BaseDialog>
);
}