Skip to content
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

add option to autofill snapshot proposal from existing thread #1250

Merged
merged 3 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { formatSpace } from 'helpers/snapshot_utils/snapshot_utils';

import { notifyError } from 'controllers/app/notifications';
import QuillEditor from 'views/components/quill_editor';
import { idToProposal } from 'identifiers';
import { capitalize } from 'lodash';

interface IThreadForm {
name: string;
body: string;
Expand All @@ -25,7 +25,7 @@ interface IThreadForm {
end: number;
snapshot: number,
metadata: {},
type: string
type: string,
}

enum NewThreadErrors {
Expand Down Expand Up @@ -132,11 +132,15 @@ export const NewProposalForm: m.Component<{snapshotId: string}, {
space: any,
members: string[],
userScore: any,
isFromExistingProposal: boolean,
initialized: boolean,
snapshotScoresFetched: boolean,
}> = {
view: (vnode) => {
if (!app.community && !app.chain) return;

const pathVars = m.parsePathname(window.location.href);

if (!app.snapshot.spaces) return;
if (!vnode.state.initialized) {
vnode.state.initialized = true;
Expand All @@ -154,6 +158,19 @@ export const NewProposalForm: m.Component<{snapshotId: string}, {
type: 'single-choice'
};

if (pathVars.params.fromProposalType && pathVars.params.fromProposalId) {
const fromProposal = idToProposal(pathVars.params.fromProposalType, pathVars.params.fromProposalId);
vnode.state.form.name = fromProposal.title;
vnode.state.isFromExistingProposal = true;
if (fromProposal.body) {
try {
const parsedBody = JSON.parse(fromProposal.body);
vnode.state.form.body = parsedBody.ops[0].insert;
} catch (e) {
console.error(e);
}
}
}
const space = app.snapshot.spaces[vnode.attrs.snapshotId];

snapshotJs.utils.getScores(
Expand Down Expand Up @@ -205,6 +222,8 @@ export const NewProposalForm: m.Component<{snapshotId: string}, {
|| (vnode.state.space.filters?.minScore > 0 && vnode.state.userScore)
|| isMember);

const today = new Date();
const nextWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 7);
return m('.NewThreadForm', {
oncreate: (vvnode) => {
// $(vvnode.dom).find('.cui-input input').prop('autocomplete', 'off').focus();
Expand Down Expand Up @@ -272,6 +291,7 @@ export const NewProposalForm: m.Component<{snapshotId: string}, {
m(FormGroup, [
m(FormLabel, 'Start Date:'),
m(Input, {
defaultValue: vnode.state.isFromExistingProposal ? today.toDateString() : ' ',
name: 'targets',
placeholder: 'May 1, 1995',
oninput: (e) => {
Expand All @@ -284,6 +304,7 @@ export const NewProposalForm: m.Component<{snapshotId: string}, {
m(FormGroup, [
m(FormLabel, 'End Date:'),
m(Input, {
defaultValue: vnode.state.isFromExistingProposal ? nextWeek.toDateString() : ' ',
name: 'targets',
placeholder: 'May 22, 1995',
oninput: (e) => {
Expand All @@ -296,7 +317,7 @@ export const NewProposalForm: m.Component<{snapshotId: string}, {
]),
m(FormGroup, [
m(QuillEditor, {
contentsDoc: '', // Prevent the editor from being filled in with previous content
contentsDoc: vnode.state.form.body ? vnode.state.form.body : ' ', // Prevent the editor from being filled in with previous content
oncreateBind: (state) => {
vnode.state.quillEditorState = state;
},
Expand Down
10 changes: 9 additions & 1 deletion client/scripts/views/pages/view_proposal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'pages/view_proposal/tips.scss';
import $ from 'jquery';
import m from 'mithril';
import mixpanel from 'mixpanel-browser';
import { PopoverMenu, MenuDivider, Icon, Icons, Button, Input } from 'construct-ui';
import { PopoverMenu, MenuDivider, MenuItem, Icon, Icons, Button, Input } from 'construct-ui';

import app from 'state';
import Sublayout from 'views/sublayout';
Expand Down Expand Up @@ -163,6 +163,14 @@ const ProposalHeader: m.Component<{
&& m(ProposalBodyDeleteMenuItem, { item: proposal }),
(isAuthor || isAdmin)
&& m(ProposalHeaderPrivacyMenuItems, { proposal, getSetGlobalEditingStatus }),
(isAuthor || isAdmin) && (app.chain?.meta.chain.snapshot !== null)
&& m(MenuItem, {
onclick: (e) => {
m.route.set(`/${app.activeChainId()}/new/snapshot-proposal/${app.chain.meta.chain.snapshot}`
+ `?fromProposalType=${proposal.slug}&fromProposalId=${proposal.id}`);
},
label: 'Snapshot proposal from thread',
}),
(isAuthor || isAdmin)
&& m(MenuDivider),
m(ThreadSubscriptionMenuItem, { proposal: proposal as OffchainThread }),
Expand Down