/* Copyright 2022 Michael Telatynski <7t3chguy@gmail.com> 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, { useContext, useMemo, useState } from "react"; import { IContent, MatrixEvent } from "matrix-js-sdk/src/models/event"; import BaseTool, { DevtoolsContext, IDevtoolsProps } from "./BaseTool"; import MatrixClientContext from "../../../../contexts/MatrixClientContext"; import { EventEditor, EventViewer, eventTypeField, IEditorProps, stringify } from "./Event"; import FilteredList from "./FilteredList"; import { _t } from "../../../../languageHandler"; export const AccountDataEventEditor: React.FC = ({ mxEvent, onBack }) => { const cli = useContext(MatrixClientContext); const fields = useMemo(() => [eventTypeField(mxEvent?.getType())], [mxEvent]); const onSend = async ([eventType]: string[], content?: IContent): Promise => { await cli.setAccountData(eventType, content); }; const defaultContent = mxEvent ? stringify(mxEvent.getContent()) : undefined; return ; }; export const RoomAccountDataEventEditor: React.FC = ({ mxEvent, onBack }) => { const context = useContext(DevtoolsContext); const cli = useContext(MatrixClientContext); const fields = useMemo(() => [eventTypeField(mxEvent?.getType())], [mxEvent]); const onSend = async ([eventType]: string[], content?: IContent): Promise => { await cli.setRoomAccountData(context.room.roomId, eventType, content); }; const defaultContent = mxEvent ? stringify(mxEvent.getContent()) : undefined; return ; }; interface IProps extends IDevtoolsProps { events: Record; Editor: React.FC; actionLabel: string; } const BaseAccountDataExplorer: React.FC = ({ events, Editor, actionLabel, onBack, setTool }) => { const [query, setQuery] = useState(""); const [event, setEvent] = useState(null); if (event) { const onBack = (): void => { setEvent(null); }; return ; } const onAction = async (): Promise => { setTool(actionLabel, Editor); }; return ( {Object.entries(events).map(([eventType, ev]) => { const onClick = (): void => { setEvent(ev); }; return ( ); })} ); }; export const AccountDataExplorer: React.FC = ({ onBack, setTool }) => { const cli = useContext(MatrixClientContext); return ( ); }; export const RoomAccountDataExplorer: React.FC = ({ onBack, setTool }) => { const context = useContext(DevtoolsContext); return ( ); };