* Remove duplicate declarations and add height and overflow properties Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Move mx_TimelineCard__header under mx_BaseCard_header for normalization Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Normalize mx_BaseCard_close position Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Normalize className of header - mx_BaseCard_header__ThreadPanel - mx_BaseCard_header__TimelineCard Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Normalize header's button size Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Normalize inline start header margin Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * normalize header bottom margin for PinnedMessagesCard and TimelineCard Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Normalize header declarations Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Add mixin RightPanelCard Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Move common declarations - top level Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Move common declarations - mx_BaseCard_header Remove specific declarations on PinnedMessagesCard Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Move common declarations - mx_BaseCard_back and mx_BaseCard_close Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Create a common class name - mx_BaseCard_header_title Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Create a common class name - mx_BaseCard_header_title - ThreadPanel Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Move common declarations - mx_BaseCard_header_title Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Move common declarations - span:first-of-type Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Remove redundant declarations Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Rename a variable to remove --ThreadPanel_header-button-size Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Remove class name - mx_BaseCard_header_title Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Remove mx_BaseCard_header_title--ThreadPanel and h2 declarations from PinnedMessagesCard Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Headers need Heading Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Use spacing variables Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Move common style rules of mx_ContextualMenu inside mx_BaseCard_header_title to BaseCard leaving style rules specific to ThreadPanel. Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Hide long header title with ellipsis Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Merge style rules - BaseCard_header-button-size Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Merge style rules - BaseCard_header margin-bottom Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Merge style rules - BaseCard back and close margin Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Merge style rules - BaseCard back ~ mx_BaseCard_header_title Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Merge style rules - mx_BaseCard_header_title Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Return special declarations to _ThreadPanel.scss Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Remove the mixin Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Add mx_BaseCard_header_title_button--option Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Remove redundant margin from AppTileFullWidth Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Header on mx_RoomSummaryCard - remove default declarations Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Remove default declarations from mx_UserInfo Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Use variables - _BaseCard.scss Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>
104 lines
3.5 KiB
TypeScript
104 lines
3.5 KiB
TypeScript
/*
|
|
Copyright 2020 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, { useContext, useEffect } from "react";
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
|
|
|
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
|
import BaseCard from "./BaseCard";
|
|
import WidgetUtils from "../../../utils/WidgetUtils";
|
|
import AppTile from "../elements/AppTile";
|
|
import { _t } from "../../../languageHandler";
|
|
import { useWidgets } from "./RoomSummaryCard";
|
|
import { ChevronFace, ContextMenuButton, useContextMenu } from "../../structures/ContextMenu";
|
|
import WidgetContextMenu from "../context_menus/WidgetContextMenu";
|
|
import { Container, WidgetLayoutStore } from "../../../stores/widgets/WidgetLayoutStore";
|
|
import UIStore from "../../../stores/UIStore";
|
|
import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
|
|
import Heading from '../typography/Heading';
|
|
|
|
interface IProps {
|
|
room: Room;
|
|
widgetId: string;
|
|
onClose(): void;
|
|
}
|
|
|
|
const WidgetCard: React.FC<IProps> = ({ room, widgetId, onClose }) => {
|
|
const cli = useContext(MatrixClientContext);
|
|
|
|
const apps = useWidgets(room);
|
|
const app = apps.find(a => a.id === widgetId);
|
|
const isRight = app && WidgetLayoutStore.instance.isInContainer(room, app, Container.Right);
|
|
|
|
const [menuDisplayed, handle, openMenu, closeMenu] = useContextMenu();
|
|
|
|
useEffect(() => {
|
|
if (!app || !isRight) {
|
|
// stop showing this card
|
|
RightPanelStore.instance.popCard();
|
|
}
|
|
}, [app, isRight]);
|
|
|
|
// Don't render anything as we are about to transition
|
|
if (!app || !isRight) return null;
|
|
|
|
let contextMenu;
|
|
if (menuDisplayed) {
|
|
const rect = handle.current.getBoundingClientRect();
|
|
contextMenu = (
|
|
<WidgetContextMenu
|
|
chevronFace={ChevronFace.None}
|
|
right={UIStore.instance.windowWidth - rect.right - 12}
|
|
top={rect.bottom + 12}
|
|
onFinished={closeMenu}
|
|
app={app}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const header = <div className="mx_BaseCard_header_title">
|
|
<Heading size="h4" className="mx_BaseCard_header_title_heading">{ WidgetUtils.getWidgetName(app) }</Heading>
|
|
<ContextMenuButton
|
|
className="mx_BaseCard_header_title_button--option"
|
|
inputRef={handle}
|
|
onClick={openMenu}
|
|
isExpanded={menuDisplayed}
|
|
label={_t("Options")}
|
|
/>
|
|
{ contextMenu }
|
|
</div>;
|
|
|
|
return <BaseCard
|
|
header={header}
|
|
className="mx_WidgetCard"
|
|
onClose={onClose}
|
|
withoutScrollContainer
|
|
>
|
|
<AppTile
|
|
app={app}
|
|
fullWidth
|
|
showMenubar={false}
|
|
room={room}
|
|
userId={cli.getUserId()}
|
|
creatorUserId={app.creatorUserId}
|
|
widgetPageTitle={WidgetUtils.getWidgetDataTitle(app)}
|
|
waitForIframeLoad={app.waitForIframeLoad}
|
|
/>
|
|
</BaseCard>;
|
|
};
|
|
|
|
export default WidgetCard;
|