import { createAction, createSelector } from 'bouchon'; import { v4 as uuidv4 } from 'uuid'; import createCollectionMiddleware from '../collection-middleware'; import { actions as discussionActions } from '../discussions'; const actions = { get: createAction('Get messages'), post: createAction('Post message'), patch: createAction('Patch message'), delete: createAction('Delete message'), actions: createAction('Actions message'), patchTags: createAction('Patch message\'s tags'), }; const selectors = { all: () => state => state.messages, last: () => state => [...state.messages].pop(), byQuery: ({ offset = 0, limit = 20, discussion_id, is_draft, is_received }) => createSelector( [discussion_id ? selectors.byDiscussionId({ discussion_id }) : selectors.all()], messages => { const end = new Number(offset) + new Number(limit); return messages.filter(message => { if (is_draft !== undefined && message.is_draft.toString() !== is_draft) { return false; } if (is_received !== undefined && message.is_received.toString() !== is_received) { return false; } return true; }).slice(offset, end); }
import { createAction, createSelector } from 'bouchon'; import { v1 as uuidv1 } from 'uuid'; import createCollectionMiddleware from '../collection-middleware'; export const actions = { get: createAction('Get devices'), createOnSignin: createAction('Create device'), delete: createAction('Delete a device'), patch: createAction('Patch a device'), reqVerif: createAction('Req Verif of a device'), verify: createAction('Verify'), }; export const selectors = { all: () => state => state.devices, last: () => state => [...state.devices].pop(), byId: ({ device_id }) => createSelector( selectors.all(), devices => devices.find(device => device.device_id === device_id) ), location: () => createSelector( selectors.last(), device => ({ location: `/api/v2/devices/${device.device_id}` }) ), }; const devicesToIgnore = new Set(['00001']); const reducer = { [actions.createOnSignin]: (state, { body, req }) => { const { device_id } = body.device;
import { createAction, createSelector } from 'bouchon'; import { v1 as uuidv1 } from 'uuid'; import createCollectionMiddleware from '../collection-middleware'; const actions = { get: createAction('Get provider'), postRemote: createAction('post remote_identities'), }; const twitterPopupUrl = 'https://api.twitter.com/oauth/authorize?oauth_token=<token>'; const oauthUrlCallbackHost = ''; // should be hardcoded but it can be localhost:4000 or test-frontend:4000 according to current test env const selectors = { all: () => state => state.providers, byId: ({ providerName }) => createSelector( selectors.all(), providers => { const result = providers.find(provider => provider.name === providerName); if (!result) { throw new Error('provider not found'); } return { ...result, oauth_callback_uri: `/api/v2/providers/${providerName}/callback`, oauth_request_url: `${oauthUrlCallbackHost}/api/oauth-mock/${providerName}`, }; } ), none: () => state => {},