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 common (incomplete) #977

Open
wants to merge 1 commit 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
3 changes: 1 addition & 2 deletions client/js/common/ajax/check_campaign_or_event_name.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// License: LGPL-3.0-or-later
const R = require('ramda')
const request = require('../client')

module.exports = function(name, event_or_campaign, callback) {
request.get(`/nonprofits/${app.nonprofit_id}/${event_or_campaign}s/name_and_id`)
.end(function(err, resp){
var names = resp.body.map(x => x.name)
if(R.contains(name, names)) {
if(names.includes(name)) {
appl.notify(`Oops. It looks like you already have ${event_or_campaign === 'campaign' ? 'a' : 'an'} ${event_or_campaign} named '${name}'. Please choose a different name and try again.`)
return
}
Expand Down
2 changes: 1 addition & 1 deletion client/js/common/direct-to-s3-upload.es6
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const uploadFile = R.curry(input => {
var url = `${presignedPost.s3_direct_url}`
var file = input.files[0]
var fileUrl = `${url}/tmp/${presignedPost.s3_uuid}/${file.name}`
var payload = R.merge(JSON.parse(presignedPost.s3_presigned_post), {file})
var payload = { ...JSON.parse(presignedPost.s3_presigned_post), file }

return flyd.map(resp => ({uri: fileUrl, file}), postFormData(url, payload))
}
Expand Down
6 changes: 3 additions & 3 deletions client/js/common/fundraiser_metrics.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// License: LGPL-3.0-or-later
const R = require('ramda')
const clamp = require('lodash/clamp');
const format = require('../common/format')
require('../common/restful_resource')

appl.def('ajax_metrics', {
index: function() {
appl.ajax.index('metrics').then(function(resp) {
appl.def('metrics.percentage_funded', R.clamp(1,100, format.percent(
appl.def('metrics.percentage_funded', clamp(format.percent(
resp.body.goal_amount
, resp.body.total_raised
))
), 1,100)
)
})
}
Expand Down
11 changes: 7 additions & 4 deletions client/js/common/on-change-sanitize-slug.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// License: LGPL-3.0-or-later
const R = require('ramda')
const sanitize = require('./sanitize-slug')

// Just a hacky way to automatically sanitize slug inputs when they are changed

var inputs = document.querySelectorAll('.js-sanitizeSlug')

R.map(
inp => inp.addEventListener('change', ev => ev.currentTarget.value = sanitize(ev.currentTarget.value || ev.currentTarget.getAttribute('data-slug-default')))
, inputs )
inputs.map((inp) =>
inp.addEventListener(
'change',
(ev) =>
(ev.currentTarget.value = sanitize(ev.currentTarget.value || ev.currentTarget.getAttribute('data-slug-default')))
)
);
10 changes: 5 additions & 5 deletions client/js/common/request.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// License: LGPL-3.0-or-later
const R = require('ramda')
const request = require('flyd-ajax')

module.exports = options => {
options.headers = R.merge({
'Content-Type': 'application/json'
, 'X-CSRF-Token': window._csrf
}, options.headers || {})
options.headers = {
'Content-Type': 'application/json',
'X-CSRF-Token': window._csrf,
...(options.headers || {}),
};
return request(options)
}
9 changes: 4 additions & 5 deletions client/js/common/search-data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// License: LGPL-3.0-or-later
const R = require('ramda')
const flyd = require('flimflam/flyd')
const getValidData = require('../common/get-valid-data')

Expand All @@ -20,16 +19,16 @@ module.exports = (path, pageLength) => {
const hasMoreResults$ = flyd.map(x => x && x.length >= pageLength, allResults$)

const data$ = flyd.scanMerge([
[searchLessResults$, (data, results) => R.concat(data, results)]
[searchLessResults$, (data, results) => [...data, ...results]]
, [searchResults$, (data, results) => results]
], [])

searchLessQuery$({page: 1, page_length: pageLength, search: ''})

const loading$ = flyd.mergeAll([
flyd.map(R.always(true), submitSearch$)
, flyd.map(R.always(true), searchLessQuery$)
, flyd.map(R.always(false), allResults$)
flyd.map(() => true, submitSearch$)
, flyd.map(() => true, searchLessQuery$)
, flyd.map(() => false, allResults$)
, flyd.stream(true)
])

Expand Down
Loading