Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit ef0843d

Browse files
committed
Iterate to match design
1 parent 0fe6ce1 commit ef0843d

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

res/css/views/right_panel/_WidgetCard.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,20 @@ limitations under the License.
2222
height: 100%;
2323
border: 0;
2424
}
25+
26+
&.mx_WidgetCard_noEdit {
27+
.mx_AccessibleButton_kind_secondary {
28+
margin: 0 12px;
29+
30+
&:first-child {
31+
// expand the Pin to room primary action
32+
flex-grow: 1;
33+
}
34+
}
35+
}
36+
}
37+
38+
.mx_WidgetCard_maxPinnedTooltip {
39+
background-color: $notice-primary-color;
40+
color: #ffffff;
2541
}

src/components/views/right_panel/WidgetCard.tsx

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import IconizedContextMenu, {
3737
} from "../context_menus/IconizedContextMenu";
3838
import {AppTileActionPayload} from "../../../dispatcher/payloads/AppTileActionPayload";
3939
import {Capability} from "../../../widgets/WidgetApi";
40+
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
41+
import classNames from "classnames";
4042

4143
interface IProps {
4244
room: Room;
@@ -134,13 +136,39 @@ const WidgetCard: React.FC<IProps> = ({ room, widgetId, onClose }) => {
134136
WidgetUtils.editWidget(room, app);
135137
};
136138

137-
const footer = <React.Fragment>
138-
<AccessibleButton kind="secondary" onClick={onEditClick} disabled={!canModify}>
139+
let editButton;
140+
if (canModify) {
141+
editButton = <AccessibleButton kind="secondary" onClick={onEditClick}>
139142
{ _t("Edit") }
140-
</AccessibleButton>
141-
<AccessibleButton kind="secondary" onClick={onPinClick} disabled={!WidgetStore.instance.canPin(app.id)}>
143+
</AccessibleButton>;
144+
}
145+
146+
const pinButtonClasses = canModify ? "" : "mx_WidgetCard_widePinButton";
147+
148+
let pinButton;
149+
if (WidgetStore.instance.canPin(app.id)) {
150+
pinButton = <AccessibleButton
151+
kind="secondary"
152+
onClick={onPinClick}
153+
className={pinButtonClasses}
154+
>
142155
{ _t("Pin to room") }
143-
</AccessibleButton>
156+
</AccessibleButton>;
157+
} else {
158+
pinButton = <AccessibleTooltipButton
159+
title={_t("You can only pin 2 apps at a time")}
160+
tooltipClassName="mx_WidgetCard_maxPinnedTooltip"
161+
kind="secondary"
162+
className={pinButtonClasses}
163+
disabled
164+
>
165+
{ _t("Pin to room") }
166+
</AccessibleTooltipButton>;
167+
}
168+
169+
const footer = <React.Fragment>
170+
{ editButton }
171+
{ pinButton }
144172
<ContextMenuButton
145173
kind="secondary"
146174
className={""}
@@ -158,7 +186,9 @@ const WidgetCard: React.FC<IProps> = ({ room, widgetId, onClose }) => {
158186
return <BaseCard
159187
header={header}
160188
footer={footer}
161-
className="mx_WidgetCard"
189+
className={classNames("mx_WidgetCard", {
190+
mx_WidgetCard_noEdit: !canModify,
191+
})}
162192
onClose={onClose}
163193
previousPhase={RightPanelPhases.RoomSummary}
164194
withoutScrollContainer

src/stores/WidgetStore.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import defaultDispatcher from "../dispatcher/dispatcher";
2323
import SettingsStore from "../settings/SettingsStore";
2424
import WidgetEchoStore from "../stores/WidgetEchoStore";
2525
import WidgetUtils from "../utils/WidgetUtils";
26-
import {IRRELEVANT_ROOM} from "../settings/WatchManager";
2726
import {SettingLevel} from "../settings/SettingLevel";
2827

2928
interface IState {}
@@ -55,7 +54,7 @@ export default class WidgetStore extends AsyncStoreWithClient<IState> {
5554
private constructor() {
5655
super(defaultDispatcher, {});
5756

58-
SettingsStore.watchSetting("Widgets.pinned", IRRELEVANT_ROOM, this.onPinnedWidgetsChange);
57+
SettingsStore.watchSetting("Widgets.pinned", null, this.onPinnedWidgetsChange);
5958
WidgetEchoStore.on("update", this.onWidgetEchoStoreUpdate);
6059
}
6160

0 commit comments

Comments
 (0)