diff --git a/app.js b/app.js index 65a0c77..e311f47 100644 --- a/app.js +++ b/app.js @@ -151,12 +151,15 @@ module.exports = { return require('./models/activity')(event, state) case '/legislation/create': case '/petitions/create': + case '/legislation/import': + case '/petitions/import': case '/petitions/yours': case '/legislation/yours': case '/legislation/:shortId': case '/nominations/:shortId': case '/:username/:shortId': case '/:username/:shortId/edit': + case '/:user.id/:shortId': return require('./models/measure')(event, state) case '/legislation/:shortId/import': case '/nominations/:shortId/import': diff --git a/routes.js b/routes.js index 5ecc552..0cfc3f0 100644 --- a/routes.js +++ b/routes.js @@ -14,8 +14,10 @@ module.exports = { '/settings': () => import('./views/settings-page'), '/settings/unsubscribe': () => import('./views/settings-unsubscribe-page'), '/legislation/create': () => import('./views/edit-legislation-page'), + '/legislation/import': () => import('./views/import-legislation-page'), '/legislation/yours': () => import('./views/user-legislation-page'), '/petitions/create': () => import('./views/edit-petition-page'), + '/petitions/import': () => import('./views/import-petition-page'), '/legislation/:shortId': () => import('./views/measure-details-page'), '/nominations/:shortId': () => import('./views/measure-details-page'), '/legislation/:shortId/import': () => import('./views/import-vote-page'), @@ -32,7 +34,9 @@ module.exports = { '/metrics': () => import('./views/metrics-page'), '/:username': () => import('./views/profile-page'), '/:username/:shortId': () => import('./views/measure-details-page'), + '/:author_id/:shortId': () => import('./views/measure-details-page'), '/:username/:shortId/import': () => import('./views/import-vote-page'), + '/:user.id/:shortId/import': () => import('./views/import-vote-page'), '/:username/:shortId/edit': () => import('./views/edit-legislation-page'), '/:username/:shortId/votes/:voteId': () => import('./views/measure-details-page'), } diff --git a/views/activity-page.js b/views/activity-page.js index 7fe22cc..8b87143 100644 --- a/views/activity-page.js +++ b/views/activity-page.js @@ -37,7 +37,9 @@ module.exports = (state, dispatch) => {
diff --git a/views/import-legislation-page.js b/views/import-legislation-page.js new file mode 100644 index 0000000..97e138d --- /dev/null +++ b/views/import-legislation-page.js @@ -0,0 +1,109 @@ +const { WWW_URL } = process.env +const { handleForm, html } = require('../helpers') +const activityIndicator = require('./activity-indicator') + +module.exports = (state, dispatch) => { + const { location, measures = {}, user } = state + const measure = location.params.shortId && measures[location.params.shortId] + return html` ++ You must create a public profile to import a petition. + ${verified + ? html`Choose a username and make a public profile.` + : html`Verify your phone number to choose a username and make a public profile.` + } +
+ ` +} + +const form = (state, dispatch) => { + const { error, forms, legislatures = [], loading, location, user, measures = {} } = state + const measure = measures[location.params.shortId] || {} + const form = forms.editMeasure || {} + const { legislature_id, summary, title } = measure + const auto_short_id = (form.title || title || '').toLowerCase().replace(/ /g, '-').replace(/[^A-z0-9-_]/g, '').slice(0, 32) + const short_id = !forms.editMeasureShortId && !measure.short_id ? auto_short_id : (form.short_id || measure.short_id) + + return html` + + ` +} + +const editedShortId = (dispatch) => (event) => { + dispatch({ type: 'measure:editFormShortIdChanged', shortId: event.currentTarget.value, event }) +} diff --git a/views/import-petition-page.js b/views/import-petition-page.js new file mode 100644 index 0000000..13227cf --- /dev/null +++ b/views/import-petition-page.js @@ -0,0 +1,110 @@ +const { WWW_URL } = process.env +const { handleForm, html } = require('../helpers') +const activityIndicator = require('./activity-indicator') + +module.exports = (state, dispatch) => { + const { location, measures = {}, user } = state + const measure = location.params.shortId && measures[location.params.shortId] + return html` ++ You must create a public profile to import a petition. + ${verified + ? html`Choose a username and make a public profile.` + : html`Verify your phone number to choose a username and make a public profile.` + } +
+ ` +} + +const form = (state, dispatch) => { + const { error, forms, legislatures = [], loading, location, measures = {}, user } = state + const measure = measures[location.params.shortId] || {} + const form = forms.editMeasure || {} + const { legislature_id, summary, title } = measure + const auto_short_id = (form.title || title || '').toLowerCase().replace(/ /g, '-').replace(/[^A-z0-9-_]/g, '').slice(0, 32) + const short_id = !forms.editMeasureShortId && !measure.short_id ? auto_short_id : (form.short_id || measure.short_id) + + return html` + + ` +} + +const editedShortId = (dispatch) => (event) => { + dispatch({ type: 'measure:editFormShortIdChanged', shortId: event.currentTarget.value, event }) +} diff --git a/views/navbar.js b/views/navbar.js index 207e2c4..d803887 100644 --- a/views/navbar.js +++ b/views/navbar.js @@ -114,7 +114,9 @@ const navbarAuthed = ({ location, user }) => { Settings