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

remove ramda from settings #980

Open
wants to merge 2 commits into
base: supporter_level_goal
Choose a base branch
from
Open
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
5 changes: 2 additions & 3 deletions client/js/settings/index/branding/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// License: LGPL-3.0-or-later
// npm
const flyd = require('flyd')
const R = require('ramda')
flyd.flatMap = require('flyd/module/flatmap')
flyd.filter = require('flyd/module/filter')
flyd.mergeAll = require('flyd/module/mergeall')
Expand All @@ -13,7 +12,7 @@ const colorPicker = require('../../../components/color-picker.es6')
const view = require('./view')

function init() {
const np = R.merge(app.nonprofit, {})
const np = { ...app.nonprofit }
const state = {
nonprofit: np
, font$: flyd.stream({
Expand All @@ -27,7 +26,7 @@ function init() {
}

const resp$ = flyd.flatMap(
state => flyd.map(R.prop('body'), request({
state => flyd.map(r => r.body, request({
method: 'put'
, path: `/nonprofits/${np.id}`
, send: {nonprofit: { brand_color: state.colorPicker.color$(), brand_font: state.font$().key }}
Expand Down
10 changes: 5 additions & 5 deletions client/js/settings/index/branding/view.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// License: LGPL-3.0-or-later
// npm
const h = require('snabbdom/h')
const R = require('ramda')
const notification = require('ff-core/notification')
const button = require('ff-core/button')
// local
Expand Down Expand Up @@ -41,14 +40,15 @@ const fontPicker = state =>
])

const fontListing = state =>
h('ul.inner', R.map(R.apply(fontRow(state)), R.toPairs(fonts)))
h('ul.inner', Object.entries(fonts).map(
([key, value]) => fontRow(state, key, value)
))

const fontRow = R.curry((state, key, font) =>
const fontRow = (state, key, font) =>
h('li', {
style: { fontFamily: font.family }
, on: {click: [state.font$, R.merge(font, {key: key})]}
, on: {click: [state.font$, {...font, key}]}
}, font.name)
)

const form = state => {
var btn = button({ buttonText: 'Save Branding' , loading$: state.loading$ })
Expand Down
14 changes: 5 additions & 9 deletions client/js/settings/index/email-settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// npm
const snabbdom = require('snabbdom')
const flyd = require('flyd')
const R = require('ramda')
const render = require('ff-core/render')
const notification = require('ff-core/notification')
const serializeForm = require('form-serialize')
Expand All @@ -16,23 +15,20 @@ const view = require('./view')
function init() {
var state = { submit$: flyd.stream() }

// formSerialize will set checked boxes to "on" and unchecked boxes to "". We want it to be true/false instead
const formObj$ = R.compose(
flyd.map(obj => R.map(val => val === 'on' ? true : false, obj))
, flyd.map(ev => serializeForm(ev.currentTarget, {hash: true, empty: true}))
)(state.submit$)
const intermediate = flyd.map(ev => serializeForm(ev.currentTarget, {hash: true, empty: true}, state.submit$));
const formObj$ = flyd.map(obj => obj.map(val => val === 'on' ? true : false), intermediate);

const path = `/nonprofits/${app.nonprofit_id}/users/${app.current_user_id}/email_settings`

const updateResp$ = flyd.flatMap(
obj => request({ path, method: 'post' , send: {email_settings: obj} }).load
, formObj$ )

state.email_settings$ = flyd.map(R.prop('body'), request({method: 'get', path}).load)
state.email_settings$ = flyd.map((r) => r.body, request({ method: 'get', path }).load);

state.loading$ = flyd.mergeAll([
flyd.map(R.always(true), state.submit$)
, flyd.map(R.always(false), updateResp$)
flyd.map(() => true, state.submit$)
, flyd.map(() => false, updateResp$)
])

const notify$ = flyd.map(()=> 'Email notification settings updated.', updateResp$)
Expand Down
3 changes: 1 addition & 2 deletions client/js/settings/index/integrations/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// License: LGPL-3.0-or-later
const h = require('snabbdom/h')
const R = require('ramda')
const flyd = require('flyd')
const request = require('../../../common/request')
const colors = require('../../../common/colors')
Expand All @@ -10,7 +9,7 @@ function init() {
clickSync$: flyd.stream()
, mailchimpKeyResp$: request({method: 'get', path: `/nonprofits/${app.nonprofit_id}/nonprofit_keys`, query: {select: 'mailchimp_token'}}).load
}
state.mailchimpKey$ = flyd.map(R.prop('response'), flyd.filter(resp => resp.status === 200, state.mailchimpKeyResp$))
state.mailchimpKey$ = flyd.map(r => r.response, flyd.filter(resp => resp.status === 200, state.mailchimpKeyResp$))
return state
}

Expand Down
1 change: 0 additions & 1 deletion client/js/settings/index/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require('../../common/restful_resource')

const render = require('ff-core/render')
const h = require('snabbdom/h')
const R = require('ramda')
const flyd = require('flyd')
const snabbdom = require('snabbdom')
const branding = require('./branding/index')
Expand Down
Loading