houdini/client/js/nonprofits/supporters/index/sidepanel/supporter-activities.js
Bradley M. Kuhn fc77ee76d6 Relicense Javascript code in accordance with project's new license
The primary license of the project is changing to:
  AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later

The Additional Permission is designed to permit publicly distributed
Javascript code to be relicensed under LGPL-3.0-or-later, but not server-side
Javascript code.  As such, we've relicensed here static Javscript files under
LGPL-3.0-or-later, and those that run as part of build and/or server side
under AGPL-3.0-or-later.

Note that in future, Javascript files may be updated to be stronger copyleft
license with the Additional Permission, particularly if they adapted to run
on server side and/or turned into templates.  Of course, we'd seek public
discussion with the contributor community about such changes.

This commit is one of the many steps to relicense the entire codebase.

Documentation granting permission for this relicensing (from all past
contributors who hold copyrights) is on file with Software Freedom
Conservancy, Inc.
2018-03-25 15:10:40 -04:00

74 lines
2.2 KiB
JavaScript

// License: LGPL-3.0-or-later
const R = require('ramda')
const h = require('snabbdom/h')
const flyd = require('flyd')
const moment = require('moment')
const flatMap = require('flyd/module/flatmap')
const request = require('../../../../common/request')
const flyd_mergeAll = require('flyd/module/mergeall')
const generateContent = require('./generate-content')
function init(parentState) {
const activitiesWithJson$ = flyd.map(
R.map(parseActivityJson)
, parentState.activities$
)
const response$ = flyd.merge(
flyd.stream([]) // default to empty array on pageload
, activitiesWithJson$ )
const loading$ = flyd_mergeAll([
flyd.map(() => false, response$)
])
return {response$, loading$}
}
// Return js object if the string is json, otherwise return the string
const tryJSON = str => {
try { return JSON.parse(str) } catch(e) { return str }
}
// Parse the cached `json_data` column for activities
// Also, parse the nested `dedicaton` json if it is present
const parseActivityJson = data => {
var json_data = JSON.parse(data.json_data || '{}')
json_data.dedication = tryJSON(json_data.dedication)
return R.merge(data, {json_data})
}
const view = parentState => {
var state = parentState.activities
if(state.loading$()) {
return h('div', [
h('p.u-color--grey', [h('i.fa.fa-spin.fa-gear'), ' Loading timeline...'])
])
}
if(!state.loading$() && !state.response$().length) {
return h('div', [
h('p.u-color--grey', 'No activity yet...')
])
}
return h('ul.timeline-activities', R.map(activityContent(parentState), state.response$()))
}
// used to construct each activitiy list element
const activityContent = parentState => data => {
const contentFn = generateContent[data.kind]
if(!contentFn) return ''
const content = contentFn(data, parentState)
return h('li.timeline-activity', [
h('div.timeline-activity-icon', [h(`i.fa.${content.icon}`)])
, h('div.timeline-activity-card', [
h('div', [
h('small.u-color--grey', moment(data.date).format("ddd, MMMM Do YYYY"))
, h('div.u-fontSize--15', [
h('strong', content.title)
, h('div', content.body)
])
])
])
])
}
module.exports = {init, view}