This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Poll history: detail screen (#10172)
* basic navigation to focused poll * add tooltip * drill permalinkCreator down to poll history * render poll tile and link to timeline * tidy and lint * unit test poll detail * add view poll link to ended pollliste item * strict fix * pr improvements * pass room as prop * permalinkcreator ts assertion
- Loading branch information
Kerry
authored
Feb 27, 2023
1 parent
9b2b3ca
commit f57495d
Showing
21 changed files
with
588 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
res/css/components/views/dialogs/polls/_PollDetailHeader.pcss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Copyright 2023 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. | ||
*/ | ||
|
||
.mx_PollDetailHeader { | ||
// override accessiblebutton style | ||
font-size: $font-15px !important; | ||
} | ||
|
||
.mx_PollDetailHeader_icon { | ||
height: 15px; | ||
width: 15px; | ||
margin-right: $spacing-8; | ||
vertical-align: middle; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Copyright 2023 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 from "react"; | ||
import { Poll } from "matrix-js-sdk/src/matrix"; | ||
|
||
import { _t } from "../../../../languageHandler"; | ||
import dispatcher from "../../../../dispatcher/dispatcher"; | ||
import { Action } from "../../../../dispatcher/actions"; | ||
import { ViewRoomPayload } from "../../../../dispatcher/payloads/ViewRoomPayload"; | ||
import { RoomPermalinkCreator } from "../../../../utils/permalinks/Permalinks"; | ||
import { MediaEventHelper } from "../../../../utils/MediaEventHelper"; | ||
import AccessibleButton, { ButtonEvent } from "../../elements/AccessibleButton"; | ||
import MPollBody from "../../messages/MPollBody"; | ||
|
||
interface Props { | ||
poll: Poll; | ||
requestModalClose: () => void; | ||
permalinkCreator: RoomPermalinkCreator; | ||
} | ||
|
||
const NOOP = (): void => {}; | ||
|
||
/** | ||
* Content of the PollHistoryDialog when a specific poll is selected | ||
*/ | ||
export const PollDetail: React.FC<Props> = ({ poll, permalinkCreator, requestModalClose }) => { | ||
// link to end event for ended polls | ||
const eventIdToLinkTo = poll.isEnded ? poll.endEventId! : poll.pollId; | ||
const linkToTimeline = permalinkCreator.forEvent(eventIdToLinkTo); | ||
|
||
const onLinkClick = (e: ButtonEvent): void => { | ||
if ((e as React.MouseEvent).ctrlKey || (e as React.MouseEvent).metaKey) { | ||
// native behavior for link on ctrl/cmd + click | ||
return; | ||
} | ||
// otherwise handle navigation in the app | ||
e.preventDefault(); | ||
dispatcher.dispatch<ViewRoomPayload>({ | ||
action: Action.ViewRoom, | ||
event_id: eventIdToLinkTo, | ||
highlighted: true, | ||
room_id: poll.roomId, | ||
metricsTrigger: undefined, // room doesn't change | ||
}); | ||
|
||
requestModalClose(); | ||
}; | ||
return ( | ||
<> | ||
<MPollBody | ||
mxEvent={poll.rootEvent} | ||
permalinkCreator={permalinkCreator} | ||
onHeightChanged={NOOP} | ||
onMessageAllowed={NOOP} | ||
// MPollBody doesn't use this | ||
// and MessageEvent only defines it for eligible events | ||
// should be fixed on IBodyProps types | ||
// cheat to fulfil the type here | ||
mediaEventHelper={{} as unknown as MediaEventHelper} | ||
/> | ||
<br /> | ||
<div> | ||
<AccessibleButton | ||
kind="link_inline" | ||
element="a" | ||
href={linkToTimeline} | ||
onClick={onLinkClick} | ||
rel="noreferrer noopener" | ||
> | ||
{_t("View poll in timeline")} | ||
</AccessibleButton> | ||
</div> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright 2023 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 from "react"; | ||
|
||
import { Icon as LeftCaretIcon } from "../../../../../res/img/element-icons/caret-left.svg"; | ||
import { _t } from "../../../../languageHandler"; | ||
import AccessibleButton from "../../elements/AccessibleButton"; | ||
import { PollHistoryFilter } from "./types"; | ||
|
||
interface Props { | ||
filter: PollHistoryFilter; | ||
onNavigateBack: () => void; | ||
} | ||
|
||
export const PollDetailHeader: React.FC<Props> = ({ filter, onNavigateBack }) => { | ||
return ( | ||
<AccessibleButton kind="content_inline" onClick={onNavigateBack} className="mx_PollDetailHeader"> | ||
<LeftCaretIcon className="mx_PollDetailHeader_icon" /> | ||
{filter === "ACTIVE" ? _t("Active polls") : _t("Past polls")} | ||
</AccessibleButton> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.