Equicord/src/plugins/betterSessions/components/RenameModal.tsx
V 3b9292d3bc
Migrate to Discord's new Modals (#4206)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-05-10 13:58:48 +02:00

84 lines
3 KiB
TypeScript

/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { TextButton } from "@components/Button";
import { SessionInfo } from "@plugins/betterSessions/types";
import { getDefaultName, savedSessionsCache, saveSessionsToDataStore } from "@plugins/betterSessions/utils";
import { RenderModalProps } from "@vencord/discord-types";
import { Forms, Modal,React, TextInput } from "@webpack/common";
import { KeyboardEvent } from "react";
export function RenameModal({ props, session, state }: { props: RenderModalProps, session: SessionInfo["session"], state: [string, React.Dispatch<React.SetStateAction<string>>]; }) {
const [title, setTitle] = state;
const [value, setValue] = React.useState(savedSessionsCache.get(session.id_hash)?.name ?? "");
function onSaveClick() {
savedSessionsCache.set(session.id_hash, { name: value, isNew: false });
if (value !== "") {
setTitle(`${value}*`);
} else {
setTitle(getDefaultName(session.client_info));
}
saveSessionsToDataStore();
props.onClose();
}
return (
<Modal
{...props}
title="Rename"
actions={[
{
text: "Cancel",
variant: "secondary",
onClick: () => props.onClose()
},
{
text: "Save",
variant: "primary",
onClick: onSaveClick
}
]}
>
<div>
<Forms.FormTitle tag="h5">New device name</Forms.FormTitle>
<TextInput
style={{ marginBottom: "10px" }}
placeholder={getDefaultName(session.client_info)}
value={value}
onChange={setValue}
onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter") {
onSaveClick();
}
}}
/>
<TextButton
style={{
paddingLeft: "1px",
opacity: 0.6
}}
onClick={() => setValue("")}
>
Reset Name
</TextButton>
</div>
</Modal>
);
}