/* * Copyright 2024 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import React, { JSX, useEffect, useState } from "react"; import { Field, HelpMessage, InlineField, Label, RadioControl, Root, ToggleControl } from "@vector-im/compound-web"; import SettingsSubsection from "./shared/SettingsSubsection"; import { _t } from "../../../languageHandler"; import SettingsStore from "../../../settings/SettingsStore"; import { SettingLevel } from "../../../settings/SettingLevel"; import { useSettingValue } from "../../../hooks/useSettings"; import { Layout } from "../../../settings/enums/Layout"; import EventTilePreview from "../elements/EventTilePreview"; import { useMatrixClientContext } from "../../../contexts/MatrixClientContext"; /** * A section to switch between different message layouts. */ export function LayoutSwitcher(): JSX.Element { return ( ); } /** * A selector to choose the layout of the messages. */ function LayoutSelector(): JSX.Element { return ( { // We don't have any file in the form, we can cast it as string safely const newLayout = new FormData(evt.currentTarget).get("layout") as string | null; await SettingsStore.setValue("layout", null, SettingLevel.DEVICE, newLayout); }} > ); } /** * A radio button to select a layout. */ interface LayoutRadioProps { /** * The value of the layout. */ layout: Layout; /** * The label to display for the layout. */ label: string; } /** * A radio button to select a layout. * @param layout * @param label */ function LayoutRadio({ layout, label }: LayoutRadioProps): JSX.Element { const currentLayout = useSettingValue("layout"); const eventTileInfo = useEventTileInfo(); return ( ); } type EventTileInfo = { /** * The ID of the user to display. */ userId: string; /** * The display name of the user to display. */ displayName?: string; /** * The avatar URL of the user to display. */ avatarUrl?: string; }; /** * Fetch the information to display in the event tile preview. */ function useEventTileInfo(): EventTileInfo { const matrixClient = useMatrixClientContext(); const userId = matrixClient.getSafeUserId(); const [eventTileInfo, setEventTileInfo] = useState({ userId }); useEffect(() => { const run = async (): Promise => { const profileInfo = await matrixClient.getProfileInfo(userId); setEventTileInfo({ userId, displayName: profileInfo.displayname, avatarUrl: profileInfo.avatar_url, }); }; run(); }, [userId, matrixClient, setEventTileInfo]); return eventTileInfo; } /** * A toggleable setting to enable or disable the compact layout. */ function ToggleCompactLayout(): JSX.Element { const compactLayoutEnabled = useSettingValue("useCompactLayout"); const layout = useSettingValue("layout"); return ( { const checked = new FormData(evt.currentTarget).get("compactLayout") === "on"; await SettingsStore.setValue("useCompactLayout", null, SettingLevel.DEVICE, checked); }} > } > {_t("settings|appearance|compact_layout_description")} ); }