This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 819
Allow ending polls #7305
Merged
Merged
Allow ending polls #7305
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ef162b1
Allow sending end poll event
andybalaam f36ac13
Rename pollRelations->voteRelations
andybalaam 74e6378
Allow ending polls
andybalaam e130403
Fix relative imports
andybalaam fc9b951
Add space after comma in CSS
andybalaam 5605afb
Add space after comma in CSS
andybalaam 006b645
Add space after comma in CSS
andybalaam d69196b
Fix incorrect whitespace
andybalaam 41d71c6
Add type declaration to canEndPoll
andybalaam ed8a531
Fix incorrect whitespace
andybalaam a3bf7f5
Add return type to isOnOrBeforeEnd
andybalaam ee129db
Provide return type for pollEndTs
andybalaam f90b28d
Refactor poll options into functional React components
andybalaam 9e8786c
Fix whitespace of OptionsButton and add a type declaration
andybalaam 9fb0bc4
Set the radio button colour to quinary
andybalaam c85f4e1
Line up ended poll vote counts
andybalaam bfd594a
Re-order imports in EndPollDialog
andybalaam 61c048b
Apply suggestions from code review
andybalaam f697a17
Revert "Set the radio button colour to quinary"
andybalaam 79e1d45
Use the classNames utility package in MPollBody
andybalaam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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,103 @@ | ||
/* | ||
Copyright 2021 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 { MatrixEvent } from "matrix-js-sdk/src/models/event"; | ||
import { MatrixClient } from "matrix-js-sdk/src/client"; | ||
|
||
import { _t } from "../../../languageHandler"; | ||
import { IDialogProps } from "./IDialogProps"; | ||
import QuestionDialog from "./QuestionDialog"; | ||
import { IPollEndContent, POLL_END_EVENT_TYPE, TEXT_NODE_TYPE } from "../../../polls/consts"; | ||
import { findTopAnswer } from "../messages/MPollBody"; | ||
import Modal from "../../../Modal"; | ||
import ErrorDialog from "./ErrorDialog"; | ||
import { Relations } from "matrix-js-sdk/src/models/relations"; | ||
andybalaam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
interface IProps extends IDialogProps { | ||
matrixClient: MatrixClient; | ||
event: MatrixEvent; | ||
onFinished: (success: boolean) => void; | ||
getRelationsForEvent?: ( | ||
eventId: string, | ||
relationType: string, | ||
eventType: string | ||
) => Relations; | ||
andybalaam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
export default class EndPollDialog extends React.Component<IProps> { | ||
private onFinished = (endPoll: boolean) => { | ||
const topAnswer = findTopAnswer( | ||
this.props.event, | ||
this.props.matrixClient, | ||
this.props.getRelationsForEvent, | ||
); | ||
|
||
const message = ( | ||
(topAnswer === "") | ||
? _t("The poll has ended. No votes were cast.") | ||
: _t( | ||
"The poll has ended. Top answer: %(topAnswer)s", | ||
{ topAnswer }, | ||
) | ||
); | ||
|
||
if (endPoll) { | ||
const endContent: IPollEndContent = { | ||
[POLL_END_EVENT_TYPE.name]: {}, | ||
"m.relates_to": { | ||
"event_id": this.props.event.getId(), | ||
"rel_type": "m.reference", | ||
}, | ||
[TEXT_NODE_TYPE.name]: message, | ||
}; | ||
|
||
this.props.matrixClient.sendEvent( | ||
this.props.event.getRoomId(), POLL_END_EVENT_TYPE.name, endContent, | ||
).catch((e: any) => { | ||
console.error("Failed to submit poll response event:", e); | ||
Modal.createTrackedDialog( | ||
'Failed to end poll', | ||
'', | ||
ErrorDialog, | ||
{ | ||
title: _t("Failed to end poll"), | ||
description: _t( | ||
"Sorry, the poll did not end. Please try again."), | ||
}, | ||
); | ||
}); | ||
} | ||
this.props.onFinished(endPoll); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<QuestionDialog | ||
title={_t("End Poll")} | ||
description={ | ||
_t( | ||
"Are you sure you want to end this poll? " + | ||
"This will show the final results of the poll and " + | ||
"stop people from being able to vote.", | ||
) | ||
} | ||
button={_t("End Poll")} | ||
onFinished={(endPoll: boolean) => this.onFinished(endPoll)} | ||
/> | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.