-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functional proposal details #2449
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ba0fa00
Start moving proposalDetails to functional component
vctt94 e9ff5c4
Finish changing politeia proposal details
vctt94 545c1c6
clean up
vctt94 221182b
Use state machine to update vote choice
vctt94 8806afe
lint
vctt94 c737bf4
Make modal functional component
vctt94 f8beffb
Add proposal details header
vctt94 1c35c99
review fixes
vctt94 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 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 |
---|---|---|
@@ -1,57 +1,47 @@ | ||
import { showCheck, eventOutsideElement } from "helpers"; | ||
import ReactDOM from "react-dom"; | ||
import { modal } from "connectors"; | ||
import EventListener from "react-event-listener"; | ||
import "style/Modals.less"; | ||
import Draggable from "react-draggable"; | ||
import cx from "classnames"; | ||
|
||
@autobind | ||
class Modal extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.modalRef = React.createRef(); | ||
} | ||
|
||
componentDidMount() { | ||
this.props.modalShown(); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.props.modalHidden(); | ||
} | ||
|
||
mouseUp(event) { | ||
const el = this.modalRef.current; | ||
import { useRef } from "react"; | ||
import { useSelector } from "react-redux"; | ||
import * as sel from "selectors"; | ||
|
||
function Modal({ | ||
children, className, draggable, onCancelModal | ||
}) { | ||
const expandSideBar = useSelector(sel.expandSideBar); | ||
const showingSidebarMenu = useSelector(sel.showingSidebarMenu); | ||
const domNode = document.getElementById("modal-portal"); | ||
const modalRef = useRef(null); | ||
|
||
const mouseUp = (event) => { | ||
const el = modalRef.current; | ||
if (eventOutsideElement(el, event.target)) { | ||
this.props.onCancelModal && this.props.onCancelModal(); | ||
onCancelModal && onCancelModal(); | ||
} | ||
} | ||
}; | ||
|
||
onKeyDown(event) { | ||
const onKeyDown = (event) => { | ||
// 27: ESC key | ||
if (event.keyCode === 27) { | ||
this.props.onCancelModal && this.props.onCancelModal(); | ||
onCancelModal && onCancelModal(); | ||
} | ||
} | ||
}; | ||
|
||
render() { | ||
const { children, className, expandSideBar, showingSidebarMenu, draggable } = this.props; | ||
const domNode = document.getElementById("modal-portal"); | ||
|
||
const innerView = <div ref={this.modalRef} className={cx((showingSidebarMenu ? expandSideBar ? "app-modal " : "app-modal-reduced-bar " : "app-modal-standalone "), className && className, draggable && " draggable-modal ")}> | ||
{children} | ||
</div>; | ||
const innerView = <div ref={modalRef} className={cx((showingSidebarMenu ? expandSideBar ? "app-modal " : "app-modal-reduced-bar " : "app-modal-standalone "), className && className, draggable && " draggable-modal ")}> | ||
{children} | ||
</div>; | ||
|
||
return ReactDOM.createPortal( | ||
<EventListener target="document" onMouseUp={this.mouseUp} onKeyDown={this.onKeyDown}> | ||
<div className={showingSidebarMenu ? expandSideBar ? "app-modal-overlay" : "app-modal-overlay-reduced-bar" : "app-modal-overlay-standalone"}> | ||
{draggable ? <Draggable bounds="parent" cancel=".cancel-dragging">{innerView}</Draggable> : innerView } | ||
</div> | ||
</EventListener> | ||
, domNode); | ||
} | ||
return ReactDOM.createPortal( | ||
<EventListener target="document" onMouseUp={mouseUp} onKeyDown={onKeyDown}> | ||
<div className={showingSidebarMenu ? expandSideBar ? "app-modal-overlay" : "app-modal-overlay-reduced-bar" : "app-modal-overlay-standalone"}> | ||
{draggable ? <Draggable bounds="parent" cancel=".cancel-dragging">{innerView}</Draggable> : innerView } | ||
</div> | ||
</EventListener> | ||
, domNode); | ||
} | ||
|
||
export default showCheck(modal(Modal)); | ||
export default showCheck(Modal); |
5 changes: 2 additions & 3 deletions
5
app/components/views/GovernancePage/Proposals/PoliteiaDisabled.js
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 |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import { FormattedMessage as T } from "react-intl"; | ||
import { EnableExternalRequestButton } from "buttons"; | ||
import { EXTERNALREQUEST_POLITEIA } from "main_dev/externalRequests"; | ||
import { proposals } from "connectors"; | ||
|
||
export default proposals(({ getTokenAndInitialBatch }) => ( | ||
export default ({ getTokenAndInitialBatch }) => ( | ||
<div className="politeia-disabled-wrapper"> | ||
<p><T id="proposals.enablePoliteia.description" m="Politeia integration is currently disabled in your privacy settings. Please enable it if you want to be able to access the proposal system." /></p> | ||
<EnableExternalRequestButton requestType={EXTERNALREQUEST_POLITEIA} onClick={getTokenAndInitialBatch}> | ||
<T id="proposals.enablePoliteia.button" m="Enable Politeia Integration" /> | ||
</EnableExternalRequestButton> | ||
</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
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
125 changes: 125 additions & 0 deletions
125
app/components/views/ProposalDetails/ChooseVoteOption.js
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,125 @@ | ||
import { FormattedMessage as T } from "react-intl"; | ||
import { PassphraseModalButton } from "buttons"; | ||
import { fetchMachine } from "stateMachines/FetchStateMachine"; | ||
import { useMachine } from "@xstate/react"; | ||
import { StakeyBounceXs } from "indicators"; | ||
import { useDispatch } from "react-redux"; | ||
import { useState } from "react"; | ||
import { ProposalError } from "./helpers"; | ||
import * as gov from "actions/GovernanceActions"; | ||
|
||
const VoteOption = ({ value, description, onClick, checked }) => ( | ||
<div className="proposal-vote-option"> | ||
<input className={value} type="radio" id={value} name="proposalVoteChoice" | ||
readOnly={!onClick} onChange={onClick} | ||
value={value} | ||
checked ={checked} | ||
/> | ||
<label className={"radio-label " + value} htmlFor={value}/>{description} | ||
</div> | ||
); | ||
|
||
function UpdateVoteChoiceModalButton({ onSubmit, newVoteChoice, eligibleTicketCount }) { | ||
return ( | ||
<PassphraseModalButton | ||
modalTitle={ | ||
<> | ||
<T id="proposals.updateVoteChoiceModal.title" m="Confirm Your Vote" /> | ||
<div className="proposal-vote-confirmation"> | ||
<div className={newVoteChoice+"-proposal"}/> | ||
{newVoteChoice} | ||
</div> | ||
</> | ||
} | ||
modalDescription={ | ||
<T | ||
id="proposalDetails.votingInfo.eligibleCount" | ||
m="You have {count, plural, one {one ticket} other {# tickets}} eligible for voting" | ||
values={{ count: eligibleTicketCount }} | ||
/> | ||
} | ||
disabled={!newVoteChoice} | ||
onSubmit={onSubmit} | ||
buttonLabel={<T id="proposals.updateVoteChoiceModal.btnLabel" m="Cast Vote" />} | ||
/> | ||
);} | ||
|
||
const getError = (error) => { | ||
if (!error) return; | ||
if (typeof error === "string") return error; | ||
if (typeof error === "object") { | ||
if (error.message) return error.message; | ||
return JSON.stringify(error); | ||
} | ||
}; | ||
|
||
function ChooseVoteOption({ | ||
viewedProposalDetails, voteOptions, currentVoteChoice, votingComplete, eligibleTicketCount | ||
}) { | ||
const [ newVoteChoice, setVoteOption ] = useState(null); | ||
|
||
const dispatch = useDispatch(); | ||
const onUpdateVoteChoice = (privatePassphrase) => dispatch( | ||
gov.updateVoteChoice(viewedProposalDetails, newVoteChoice, privatePassphrase) | ||
); | ||
const [ state, send ] = useMachine(fetchMachine, { | ||
actions: { | ||
initial: () => ({}), | ||
load: (context, event) => { | ||
const { privatePassphrase } = event; | ||
if(!newVoteChoice) return; | ||
onUpdateVoteChoice(privatePassphrase) | ||
.then(() => send("RESOLVE")) | ||
.catch(error => send({ type: "REJECT", error })); | ||
} | ||
} | ||
}); | ||
|
||
const error = state && state.context && getError(state.context.error); | ||
const ChooseOptions = () => ( | ||
<> | ||
<div className="proposal-details-voting-preference"> | ||
<div className="proposal-details-voting-preference-title"><T id="proposalDetails.votingInfo.votingPreferenceTitle" m="My Voting Preference" /></div> | ||
<div className="proposal-details-current-choice-box"> | ||
{ voteOptions.map(o => { | ||
return <VoteOption | ||
value={o.id} key={o.id} | ||
description={o.id.charAt(0).toUpperCase()+o.id.slice(1)} | ||
onClick={ () => currentVoteChoice === "abstain" && setVoteOption(o.id) } | ||
checked={ newVoteChoice ? newVoteChoice === o.id : currentVoteChoice !== "abstain" ? currentVoteChoice.id === o.id : null } | ||
/>; | ||
})} | ||
</div> | ||
</div> | ||
{ !votingComplete && | ||
<UpdateVoteChoiceModalButton {...{ | ||
newVoteChoice, onSubmit: (privatePassphrase) => send({ type: "FETCH", privatePassphrase }), eligibleTicketCount | ||
}} /> | ||
} | ||
</> | ||
); | ||
|
||
switch (state.value) { | ||
case "idle": | ||
return <ChooseOptions {...{ | ||
setVoteOption, newVoteChoice, eligibleTicketCount, currentVoteChoice, | ||
voteOptions, votingComplete | ||
}} />; | ||
case "loading": | ||
return ( | ||
<div className="proposal-details-updating-vote-choice"> | ||
<StakeyBounceXs /> | ||
<T id="proposalDetails.votingInfo.updatingVoteChoice" m="Updating vote choice" />... | ||
</div> | ||
); | ||
case "success": | ||
return <ChooseOptions {...{ | ||
setVoteOption, newVoteChoice, eligibleTicketCount, currentVoteChoice, | ||
voteOptions, votingComplete | ||
}} />; | ||
case "failure": | ||
return <ProposalError {...{ error }} />; | ||
} | ||
} | ||
|
||
export default ChooseVoteOption; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, as it is a component, I'd rather let it as function. Otherwise, as an arrow function it does not show at the stack trace, when erroring, which makes debug harder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, makes sense