[Glitch] Port polls creation UI from upstream
This commit is contained in:
parent
3e5a0bc825
commit
8fe86cebaa
9 changed files with 403 additions and 20 deletions
|
@ -31,6 +31,12 @@ import {
|
|||
COMPOSE_UPLOAD_CHANGE_FAIL,
|
||||
COMPOSE_DOODLE_SET,
|
||||
COMPOSE_RESET,
|
||||
COMPOSE_POLL_ADD,
|
||||
COMPOSE_POLL_REMOVE,
|
||||
COMPOSE_POLL_OPTION_ADD,
|
||||
COMPOSE_POLL_OPTION_CHANGE,
|
||||
COMPOSE_POLL_OPTION_REMOVE,
|
||||
COMPOSE_POLL_SETTINGS_CHANGE,
|
||||
} from 'flavours/glitch/actions/compose';
|
||||
import { TIMELINE_DELETE } from 'flavours/glitch/actions/timelines';
|
||||
import { STORE_HYDRATE } from 'flavours/glitch/actions/store';
|
||||
|
@ -70,6 +76,7 @@ const initialState = ImmutableMap({
|
|||
is_changing_upload: false,
|
||||
progress: 0,
|
||||
media_attachments: ImmutableList(),
|
||||
poll: null,
|
||||
suggestion_token: null,
|
||||
suggestions: ImmutableList(),
|
||||
default_advanced_options: ImmutableMap({
|
||||
|
@ -94,6 +101,12 @@ const initialState = ImmutableMap({
|
|||
}),
|
||||
});
|
||||
|
||||
const initialPoll = ImmutableMap({
|
||||
options: ImmutableList(['', '']),
|
||||
expires_in: 24 * 3600,
|
||||
multiple: false,
|
||||
});
|
||||
|
||||
function statusToTextMentions(state, status) {
|
||||
let set = ImmutableOrderedSet([]);
|
||||
|
||||
|
@ -140,6 +153,7 @@ function clearAll(state) {
|
|||
map.set('privacy', state.get('default_privacy'));
|
||||
map.set('sensitive', false);
|
||||
map.update('media_attachments', list => list.clear());
|
||||
map.set('poll', null);
|
||||
map.set('idempotencyKey', uuid());
|
||||
});
|
||||
};
|
||||
|
@ -336,6 +350,7 @@ export default function compose(state = initialState, action) {
|
|||
map.set('spoiler', false);
|
||||
map.set('spoiler_text', '');
|
||||
map.set('privacy', state.get('default_privacy'));
|
||||
map.set('poll', null);
|
||||
map.update(
|
||||
'advanced_options',
|
||||
map => map.mergeWith(overwrite, state.get('default_advanced_options'))
|
||||
|
@ -424,7 +439,27 @@ export default function compose(state = initialState, action) {
|
|||
map.set('spoiler', false);
|
||||
map.set('spoiler_text', '');
|
||||
}
|
||||
|
||||
if (action.status.get('poll')) {
|
||||
map.set('poll', ImmutableMap({
|
||||
options: action.status.getIn(['poll', 'options']).map(x => x.get('title')),
|
||||
multiple: action.status.getIn(['poll', 'multiple']),
|
||||
expires_in: 24 * 3600,
|
||||
}));
|
||||
}
|
||||
});
|
||||
case COMPOSE_POLL_ADD:
|
||||
return state.set('poll', initialPoll);
|
||||
case COMPOSE_POLL_REMOVE:
|
||||
return state.set('poll', null);
|
||||
case COMPOSE_POLL_OPTION_ADD:
|
||||
return state.updateIn(['poll', 'options'], options => options.push(action.title));
|
||||
case COMPOSE_POLL_OPTION_CHANGE:
|
||||
return state.setIn(['poll', 'options', action.index], action.title);
|
||||
case COMPOSE_POLL_OPTION_REMOVE:
|
||||
return state.updateIn(['poll', 'options'], options => options.delete(action.index));
|
||||
case COMPOSE_POLL_SETTINGS_CHANGE:
|
||||
return state.update('poll', poll => poll.set('expires_in', action.expiresIn).set('multiple', action.isMultiple));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue