-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d0b411
commit 0fea662
Showing
78 changed files
with
1,984 additions
and
208 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
env: { | ||
test: { | ||
plugins: [ | ||
"@babel/plugin-transform-runtime", | ||
[ | ||
"module-resolver", | ||
{ | ||
alias: { | ||
"@politeiagui/core": "../../packages/core/src", | ||
"@politeiagui/core/client": "../../packages/core/src/client", | ||
}, | ||
}, | ||
], | ||
], | ||
presets: ["@babel/preset-react", "@babel/preset-env"], | ||
}, | ||
}, | ||
}; |
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
15 changes: 15 additions & 0 deletions
15
plugins-structure/apps/politeia/src/components/Proposal/ModalProposalDiff.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,15 @@ | ||
import React from "react"; | ||
import { Card, Modal } from "pi-ui"; | ||
import { MarkdownDiffHTML } from "@politeiagui/common-ui"; | ||
|
||
function ModalProposalDiff({ oldBody, show, newBody, onClose }) { | ||
return ( | ||
<Modal show={show} onClose={onClose}> | ||
<Card paddingSize="small"> | ||
<MarkdownDiffHTML oldText={oldBody} newText={newBody} /> | ||
</Card> | ||
</Modal> | ||
); | ||
} | ||
|
||
export default ModalProposalDiff; |
49 changes: 16 additions & 33 deletions
49
plugins-structure/apps/politeia/src/components/Proposal/ProposalCard.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
95 changes: 95 additions & 0 deletions
95
plugins-structure/apps/politeia/src/components/Proposal/ProposalDetails.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,95 @@ | ||
import React from "react"; | ||
import { | ||
MarkdownRenderer, | ||
RecordCard, | ||
RecordToken, | ||
useModal, | ||
} from "@politeiagui/common-ui"; | ||
import { decodeProposalRecord } from "./utils"; | ||
import { | ||
ProposalDownloads, | ||
ProposalMetadata, | ||
ProposalStatusBar, | ||
ProposalStatusTag, | ||
ProposalSubtitle, | ||
} from "./common"; | ||
import { Button, ButtonIcon } from "pi-ui"; | ||
import { getShortToken } from "@politeiagui/core/records/utils"; | ||
import styles from "./styles.module.css"; | ||
import ModalProposalDiff from "./ModalProposalDiff"; | ||
|
||
const ProposalDetails = ({ | ||
record, | ||
voteSummary, | ||
piSummary, | ||
onFetchRecordTimestamps, | ||
onFetchVersion, | ||
}) => { | ||
const [open] = useModal(); | ||
|
||
const proposalDetails = decodeProposalRecord(record); | ||
function handleShowRawMarkdown() { | ||
window.location.pathname = `/record/${getShortToken( | ||
proposalDetails.token | ||
)}/raw`; | ||
} | ||
async function handleFetchVersion(version) { | ||
const proposalVersion = await onFetchVersion(version); | ||
const { body: oldBody } = decodeProposalRecord(proposalVersion); | ||
const { body: newBody } = proposalDetails; | ||
open(ModalProposalDiff, { oldBody, newBody }); | ||
} | ||
|
||
return ( | ||
<div> | ||
<RecordCard | ||
token={proposalDetails.token} | ||
title={proposalDetails.name} | ||
subtitle={ | ||
<ProposalSubtitle | ||
userid={proposalDetails.author.userid} | ||
username={proposalDetails.author.username} | ||
publishedat={proposalDetails.timestamps.publishedat} | ||
editedat={proposalDetails.timestamps.editedat} | ||
token={proposalDetails.token} | ||
version={proposalDetails.version} | ||
onChangeVersion={handleFetchVersion} | ||
/> | ||
} | ||
rightHeader={<ProposalStatusTag piSummary={piSummary} />} | ||
secondRow={ | ||
<div className={styles.secondRow}> | ||
<RecordToken token={proposalDetails.token} isCopyable={true} /> | ||
<ProposalStatusBar voteSummary={voteSummary} /> | ||
<ProposalMetadata metadata={proposalDetails.proposalMetadata} /> | ||
</div> | ||
} | ||
thirdRow={<MarkdownRenderer body={proposalDetails.body} />} | ||
fourthRow={ | ||
<> | ||
<Button>Click Me</Button> | ||
<Button kind="secondary"> Click Again</Button> | ||
</> | ||
} | ||
footer={ | ||
<> | ||
<ProposalDownloads | ||
record={record} | ||
onFetchRecordTimestamps={onFetchRecordTimestamps} | ||
/> | ||
<div className={styles.footerButtons}> | ||
<ButtonIcon | ||
type="markdown" | ||
onClick={handleShowRawMarkdown} | ||
viewBox="0 0 208 128" | ||
/> | ||
<ButtonIcon type="link" onClick={handleShowRawMarkdown} /> | ||
</div> | ||
</> | ||
} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProposalDetails; |
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
57 changes: 57 additions & 0 deletions
57
plugins-structure/apps/politeia/src/components/Proposal/common/ProposalDownloads.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,57 @@ | ||
import React from "react"; | ||
import { Dropdown, DropdownItem } from "pi-ui"; | ||
import { getShortToken } from "@politeiagui/core/records/utils"; | ||
import { | ||
DownloadCommentsBundle, | ||
DownloadCommentsTimestamps, | ||
} from "@politeiagui/comments/ui"; | ||
import fileDownload from "js-file-download"; | ||
|
||
const ProposalDownloads = ({ record, onFetchRecordTimestamps }) => { | ||
if (!record) return null; | ||
|
||
const { token } = record.censorshiprecord; | ||
const version = record.version; | ||
const shortToken = getShortToken(token); | ||
|
||
function handleDownload(data, filename) { | ||
return function onDownload() { | ||
const dataString = JSON.stringify(data, null, 2); | ||
fileDownload(dataString, `${filename}.json`); | ||
}; | ||
} | ||
|
||
async function handleFetchRecordTimestamps() { | ||
const timestamps = await onFetchRecordTimestamps({ token, version }); | ||
return handleDownload(timestamps, `${shortToken}-v${version}-timestamps`)(); | ||
} | ||
|
||
return ( | ||
<Dropdown title="Available Downloads" closeOnItemClick={false}> | ||
<DropdownItem | ||
onClick={handleDownload(record, `${shortToken}-v${version}`)} | ||
> | ||
Proposal Bundle | ||
</DropdownItem> | ||
<DropdownItem onClick={handleFetchRecordTimestamps}> | ||
Proposal Timestamps | ||
</DropdownItem> | ||
<DropdownItem> | ||
<DownloadCommentsBundle | ||
token={token} | ||
mode="text" | ||
label="Comments Bundle" | ||
/> | ||
</DropdownItem> | ||
<DropdownItem> | ||
<DownloadCommentsTimestamps | ||
token={token} | ||
mode="text" | ||
label="Comments Timestamps" | ||
/> | ||
</DropdownItem> | ||
</Dropdown> | ||
); | ||
}; | ||
|
||
export default ProposalDownloads; |
33 changes: 33 additions & 0 deletions
33
plugins-structure/apps/politeia/src/components/Proposal/common/ProposalMetadata.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,33 @@ | ||
import React from "react"; | ||
import { LabelValueList } from "@politeiagui/common-ui"; | ||
import { | ||
formatDateToInternationalString, | ||
formatUnixTimestampToObj, | ||
usdFormatter, | ||
} from "@politeiagui/common-ui/utils"; | ||
|
||
function getMetadataItems({ domain, amount, endDate, startDate }) { | ||
return [ | ||
{ label: "Domain", value: domain }, | ||
{ label: "Amount", value: usdFormatter.format(amount / 100) }, | ||
{ label: "Start Date", value: startDate }, | ||
{ label: "End Date", value: endDate }, | ||
]; | ||
} | ||
|
||
function ProposalMetadata({ metadata }) { | ||
const { amount, startdate, enddate, domain } = metadata; | ||
const metadataAvailable = !!amount || !!domain || !!startdate || !!enddate; | ||
if (!metadataAvailable) return; | ||
|
||
const startDate = formatDateToInternationalString( | ||
(startdate && formatUnixTimestampToObj(startdate)) || {} | ||
); | ||
const endDate = formatDateToInternationalString( | ||
(enddate && formatUnixTimestampToObj(enddate)) || {} | ||
); | ||
const items = getMetadataItems({ domain, amount, endDate, startDate }); | ||
return metadataAvailable && <LabelValueList items={items} />; | ||
} | ||
|
||
export default ProposalMetadata; |
13 changes: 13 additions & 0 deletions
13
plugins-structure/apps/politeia/src/components/Proposal/common/ProposalStatusBar.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,13 @@ | ||
import React from "react"; | ||
import { TicketvoteRecordVoteStatusBar } from "@politeiagui/ticketvote/ui"; | ||
import { showVoteStatusBar } from "../utils"; | ||
|
||
function ProposalStatusBar({ voteSummary }) { | ||
return ( | ||
showVoteStatusBar(voteSummary) && ( | ||
<TicketvoteRecordVoteStatusBar ticketvoteSummary={voteSummary} /> | ||
) | ||
); | ||
} | ||
|
||
export default ProposalStatusBar; |
10 changes: 10 additions & 0 deletions
10
plugins-structure/apps/politeia/src/components/Proposal/common/ProposalStatusTag.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,10 @@ | ||
import React from "react"; | ||
import { StatusTag } from "pi-ui"; | ||
import { getProposalStatusTagProps } from "../utils"; | ||
|
||
function ProposalStatusTag({ piSummary }) { | ||
const statusTagProps = getProposalStatusTagProps(piSummary); | ||
return <StatusTag {...statusTagProps} />; | ||
} | ||
|
||
export default ProposalStatusTag; |
Oops, something went wrong.