diff --git a/models/import.js b/models/import.js index 0b8dacf..5cbcb34 100644 --- a/models/import.js +++ b/models/import.js @@ -8,7 +8,7 @@ module.exports = (event, state) => { case '/legislation/:shortId/import': case '/nominations/:shortId/import': case '/:username/:shortId/import': - if (!state.user || !state.user.is_admin) return [{ ...state, loading: { page: true } }, redirect('/')] + if (!state.user) return [{ ...state, loading: { page: true } }, redirect('/join')] return [state] default: return [state] diff --git a/views/import-author-form-new.js b/views/import-author-form-new.js new file mode 100644 index 0000000..99d984f --- /dev/null +++ b/views/import-author-form-new.js @@ -0,0 +1,176 @@ +const { APP_NAME } = process.env +const { avatarURL, handleForm, html } = require('../helpers') +const { icon } = require('@fortawesome/fontawesome-svg-core') +const { faUser } = require('@fortawesome/free-solid-svg-icons/faUser') +const { faLink } = require('@fortawesome/free-solid-svg-icons/faLink') +const { faTwitter } = require('@fortawesome/free-brands-svg-icons/faTwitter') +const { faExclamationTriangle } = require('@fortawesome/free-solid-svg-icons/faExclamationTriangle') +const { faEdit } = require('@fortawesome/free-solid-svg-icons/faEdit') +const { faEnvelope } = require('@fortawesome/free-solid-svg-icons/faEnvelope') +const { faPlus } = require('@fortawesome/free-solid-svg-icons/faPlus') + +module.exports = (state, dispatch) => { + const { location } = state + const tab = location.query.tab || 'search' + const path = location.path + + return html` +
+
+ +
+ ${tab === 'email' ? addAuthorByEmailForm(state, dispatch) : []} + ${tab === 'twitter' ? addAuthorByTwitterForm() : []} + ${tab === 'search' ? addAuthorBySearchForm(state, dispatch) : []} +
+ ` +} + +const addAuthorByEmailForm = (state) => { + const { error } = state + + return html` +
+
+
+
+ + ${icon(faUser)} +
+
+
+
+ + ${icon(faLink)} +
+
+
+
+ + ${error && error.email + ? html`${icon(faExclamationTriangle)}` + : html`${icon(faEnvelope)}` + } + ${error && error.email ? html`

${error.message}

` : ''} +
+
+
+
+

They'll be sent a notification email.

+ ` +} + +const addAuthorByTwitterForm = () => { + return html` +
+
+ + ${icon(faTwitter)} +
+
+

They'll be sent an invitation tweet.

+ ` +} + +const addAuthorBySearchForm = (state, dispatch) => { + const { error, loading, cookies, authorSearchResults = [], authorSearchTerms } = state + + return html` + +
+ +
+
+ + ${error && error.message + ? html`${icon(faExclamationTriangle)}` + : html`${icon(faUser)}` + } + ${error && error.message ? html`

${error.message}

` : ''} +
+
+ +
+
+
+
+
+ ${authorSearchTerms && !authorSearchResults.length ? html`

No results for "${authorSearchTerms}"

` : ''} + ${authorSearchResults.map(result => searchResult(cookies, result, dispatch))} + ${authorSearchTerms ? html`

Can't find who you're looking for?
Add them by email or Twitter username.

` : ''} +
+ ` +} + +const searchResult = (cookies, result, dispatch) => { + const { first_name, id, last_name, username, twitter_username } = result + + return html` +
+
+
+ ${username || twitter_username + ? html` + + + + ` : html` + + `} +
+
+
+ + ${first_name} ${last_name} + @${username || twitter_username} + +
+
+ ${cookies.author_id && cookies.author_id === id + ? searchResultAdded({ id }, dispatch) : searchResultAdd(id, username, twitter_username, dispatch)} +
+
+ ` +} + +const searchResultAdd = (id, username, twitter_username, dispatch) => { + return html` +
+ + + +
+ ` +} + +const searchResultAdded = ({ id }) => { + return html` +
+ + +
+ ` +} diff --git a/views/import-vote-page.js b/views/import-vote-page.js index cc1a3ab..baa17ab 100644 --- a/views/import-vote-page.js +++ b/views/import-vote-page.js @@ -1,17 +1,23 @@ const { handleForm, html } = require('../helpers') -module.exports = ({ error, location, user }, dispatch) => { +module.exports = (state, dispatch) => { + const { error, location, user } = state return html`
-

Import Argument to ${location.params.shortId}

+

Import External Opinion Related to ${location.params.shortId}

- ${!user || !user.is_admin ? html`
You do not have permission to import votes.
` : ''} + ${!user ? html`
Login to import comments.
` : html`

Once imported & approved, it will be displayed alongside other comments.


`} -
+ ${error ? html`
${error.message}
` : ''} - +
+ +
+ +
+
@@ -29,12 +35,6 @@ module.exports = ({ error, location, user }, dispatch) => {
-
- -
- -
-
@@ -50,7 +50,7 @@ module.exports = ({ error, location, user }, dispatch) => {
- +
diff --git a/views/measure-comments.js b/views/measure-comments.js index 3e3c8e1..62168b2 100644 --- a/views/measure-comments.js +++ b/views/measure-comments.js @@ -12,7 +12,14 @@ module.exports = (state, dispatch) => { const comments = (measure.comments || []).map((id) => votes[id]) return html`
- ${displayFilters ? filtersView(state, dispatch) : html``} + ${displayFilters ? filtersView(state, dispatch) : html` + + `} ${loading.comments ? activityIndicator() : html``} ${!loading.comments && comments.length ? comments.map(voteOrSignatureView(state, dispatch)) : html``} ${!loading.comments && !comments.length ? noCommentsView() : html``} @@ -28,7 +35,7 @@ const voteOrSignatureView = (state, dispatch) => (vote) => { const noCommentsView = () => html`

No comments yet.

` const filtersView = (state, dispatch) => { - const { loading, location, measures, user } = state + const { loading, location, measures } = state const measure = measures[location.params.shortId] const pagination = measure.commentsPagination || { offset: 0, limit: 25 } const { path, query } = location @@ -107,16 +114,15 @@ const filtersView = (state, dispatch) => {
- ${user && user.is_admin ? html` -
diff --git a/views/vote.js b/views/vote.js index 0c216f5..7212b20 100644 --- a/views/vote.js +++ b/views/vote.js @@ -8,6 +8,8 @@ const { faStar: faStarOutline } = require('@fortawesome/free-regular-svg-icons/f const { faVoteYea } = require('@fortawesome/free-solid-svg-icons/faVoteYea') const { faVoteNay } = require('@fortawesome/pro-solid-svg-icons/faVoteNay') const { faBoxBallot } = require('@fortawesome/pro-solid-svg-icons/faBoxBallot') +const { faPlus } = require('@fortawesome/free-solid-svg-icons/faPlus') +const { faTimes } = require('@fortawesome/free-solid-svg-icons/faTimes') module.exports = (state, dispatch) => { const { key, vote, parent, padded = true, displayTitle = false, user, showIcon = false, measures = {} } = state @@ -45,21 +47,37 @@ module.exports = (state, dispatch) => { : html`avatar`}
`} -
-
-
- - ${!is_public && ownVote - ? 'You' - : vote.user - ? vote.user.public_profile - ? html`${vote.user.first_name} ${vote.user.last_name}` - : html`${vote.user.first_name} ${vote.user.last_name}` - : '[private]'} - - ${html`${delegate_name && delegate_rank !== -1 ? 'inherited' : 'voted'} ${position}${delegate_rank !== -1 && delegate_name ? ` vote from ${delegate_name}` : ''}${delegate_rank === -1 && vote_power > 1 && is_public ? html` on behalf of ${vote_power} people` : ''}${is_public ? '' : ' privately'}`} - ${source_url ? html` [source]` : ''} +
+
+
+ + ${!is_public && ownVote + ? 'You' + : vote.user + ? vote.user.public_profile + ? html`${vote.user.first_name} ${vote.user.last_name}` + : html`${vote.user.first_name} ${vote.user.last_name}` + : '[private]'} + + ${html`${delegate_name && delegate_rank !== -1 ? 'inherited' : 'voted'} ${position}${delegate_rank !== -1 && delegate_name ? ` vote from ${delegate_name}` : ''}${delegate_rank === -1 && vote_power > 1 && is_public ? html` on behalf of ${vote_power} people` : ''}${is_public ? '' : ' privately'}`} + ${source_url ? html` [source]` : ''} +
+
+ ${user && user.is_admin ? + html`
+
+ +
+
+ +
+
` + : ``} ${displayTitle ? html`
${measure_title}
` : ''} ${commentContent(key, vote, parent, dispatch)}