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

Feature/settings #27

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 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
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
},
"homepage": "https://github.com/blockades/patchbay-dark-crystal#readme",
"dependencies": {
"dataurl-": "^0.1.0",
"depnest": "^1.3.0",
"hypercrop": "^1.1.0",
"hyperfile": "^2.0.0",
"hyperlightbox": "^1.0.0",
"libnested": "^1.3.2",
"lodash.set": "^4.3.2",
"lodash.sortby": "^4.7.0",
Expand Down
211 changes: 147 additions & 64 deletions plugs/app/page/dark-crystal-index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
const nest = require('depnest')
const { h, Value, computed } = require('mutant')
const pull = require('pull-stream')
const Scuttle = require('scuttle-dark-crystal')

const {
h,
Value,
computed,
when,
onceTrue,
Array: MutantArray,
Struct,
} = require('mutant')

// Views
const CrystalsIndex = require('../../../views/crystals/index')
const CrystalsNew = require('../../../views/crystals/new')

const CrystalsShow = require('../../../views/crystals/show')
const FriendsCrystalsIndex = require('../../../views/friends/crystals/index')
const FriendsCrystalsShow = require('../../../views/friends/crystals/show')

const FriendsIndex = require('../../../views/friends/index')
const FriendsShow = require('../../../views/friends/show')

const ForwardNew = require('../../../views/forward/new')
// const ForwardIndex = require('../../../views/forward/index')
const SettingsShow = require('../../../views/settings/show')

// Components
const Tooltip = require('../../../views/component/tooltip')

// Modes / Tabs
const MINE = 'My Crystals'
const OTHERS = 'Others Shards'
const FORWARDS = 'Others Crystals'

exports.gives = nest({
'app.html.menuItem': true,
Expand All @@ -26,13 +43,13 @@ exports.needs = nest({
'app.html.modal': 'first',
'app.sync.goTo': 'first',
'keys.sync.id': 'first',
'sbot.obs.connection': 'first'
'sbot.obs.connection': 'first',
'blob.sync.url': 'first',
'message.async.publish': 'first',
'sbot.async.addBlob': 'first',
'sbot.obs.localPeers': 'first'
})

// modes
const MINE = 'My Crystals'
const OTHERS = 'Others Shards'
const FORWARDS = 'Others Crystals'

exports.create = function (api) {
return nest({
Expand All @@ -48,42 +65,136 @@ exports.create = function (api) {
}

function darkCrystalIndexPage (location) {
const scuttle = Scuttle(api.sbot.obs.connection)
const mode = Value(MINE)

// mix: TODO seperate this page and the routing out

const page = h('DarkCrystal -index', { title: '/dark-crystal' }, [
h('h1', { title: '' }, [ 'Dark Crystal', h('i.fa.fa-diamond') ]),
h('section.picker', { title: '' }, [MINE, OTHERS, FORWARDS].map(m => {
return h('div', {
'ev-click': () => mode.set(m),
className: computed(mode, mode => mode === m ? '-active' : '')
}, m)
})),
MySecrets({ mode, scuttle }),
OthersShards({ mode, scuttle }),
FriendsCrystals({ mode, scuttle })
// ForwardShards({ mode, scuttle })
const server = api.sbot.obs.connection
const scuttle = Scuttle(server)

const state = Struct({
ready: Value(false),
mode: Value(MINE),
abouts: MutantArray([])
})

// %%TODO%% extract into separate file
onceTrue(server, server => {
updateStore()
watchForUpdates()

function aboutsQuery () {
return {
query: [{
$filter: {
value: {
author: server.id,
timestamp: { $gt: 0 },
content: {
type: 'about',
about: server.id
}
}
},
// %%TODO%%: Work out why reduce isn't working?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mixmix any idea why reduce wouldn't be working here? Trying to just fo a count of the number of about messages. To be honest, what I really want is to grab the first about message, and terminate the stream if we find one. This is to be able to show a warning to the user to notify them that they haven't added any personal information yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KGibb8 I'm gonna skip to your question about what you'd like to query (because don't know about reduce easily)

  • you can say limit: 1 and it will quite out after first match is found
  • you might also want to do reverse: true because that will give you the most recent about message
  • not sure, you might also want to add some filters on the about fields that are present ... e.g. a name which is a string of length > 2 ? you might need to not use limit: 1 and instead use a drain and a http://pull-stream.github.io/#pull-abortable to cancel once you've confirmed some things a little more carefully in the drain

// $map: ['value', 'content', 'type'],
// $reduce: { $count: true }
}]
}
}

function updateStore () {
pull(
server.query.read(Object.assign({}, aboutsQuery(), { live: false })),
pull.collect(
(err, abouts) => {
if (err) throw err
else {
state.abouts.set(abouts)
state.ready.set(true)
}
}
)
)
}

function watchForUpdates () {
pull(
server.query.read(Object.assign({}, aboutsQuery(), { old: false, live: true })),
pull.filter(m => !m.sync),
pull.drain(m => updateStore())
)
}
})

return h('DarkCrystal -index', { title: '/dark-crystal' }, [
h('div.header', [
h('h1', 'Dark Crystal'),
h('i.fa.fa-diamond.fa-lg'),
when(state.ready, Settings({ abouts: state.abouts, scuttle }))
]),
when(state.ready,
[
h('section.picker', [MINE, OTHERS, FORWARDS].map(m => {
return h('div', {
'ev-click': () => state.mode.set(m),
className: computed(state.mode, mode => mode === m ? '-active' : '')
}, m)
})),
MySecrets({ mode: state.mode, scuttle }),
OthersShards({ mode: state.mode, scuttle }),
FriendsCrystals({ mode: state.mode, scuttle })
],
h('i.fa.fa-spinner.fa-pulse.fa-5x')
)
])
}

// page.scroll = () => {} // stops keyboard shortcuts from breaking
return page
function Settings ({ scuttle, abouts }) {
const isOpen = Value(false)

const view = SettingsShow({
onCancel: () => isOpen.set(false),
feedId: api.keys.sync.id(),
avatar: api.about.html.avatar,
name: api.about.obs.name,
publish: api.message.async.publish,
blobUrl: api.blob.sync.url,
addBlob: api.sbot.async.addBlob,
localPeers: api.sbot.obs.localPeers
})

const modal = api.app.html.modal(view, { isOpen })

return [
h('i.fa.fa-cog.fa-2x', { 'ev-click': () => isOpen.set(true), title: 'Settings' }),
// %%TODO%%: integrate a tooltip or flash alert system to begin to show warning messages to users...
computed([abouts], abouts => {
if (abouts.length === 0) return h('i.fa.fa-warning')
else return null
}),
modal
]
}

function MySecrets ({ mode, scuttle }) {
const view = Value('Rabbits!')
const isOpen = Value(false)
const modal = api.app.html.modal(view, { isOpen })

function showCrystal (opts) {
view.set(CrystalsShow(Object.assign({}, opts, {
scuttle,
avatar: api.about.html.avatar,
name: api.about.obs.name
})))
isOpen.set(true)
}

const { formModal, formOpen } = NewCrystalForm(scuttle)

return h('section.content', { className: computed(mode, m => m === MINE ? '-active' : '') }, [
formModal,
h('button -primary', { 'ev-click': () => formOpen.set(true) }, 'New'),
h('CrystalsIndex', [
CrystalsIndex({
scuttle,
routeTo: api.app.sync.goTo
})
])
])
h('CrystalsIndex', [ CrystalsIndex({ scuttle, showCrystal }) ]),
modal
])
}

function OthersShards ({ mode, scuttle }) {
Expand Down Expand Up @@ -151,34 +262,6 @@ exports.create = function (api) {
])
}

// function ForwardShards ({ mode, scuttle }) {
// const view = Value('Cats are cooler')
// const isOpen = Value(false)
// const forwardModal = api.app.html.modal(view, { isOpen })

// const newForward = (opts) => {
// view.set(ForwardNew(Object.assign({}, opts, {
// avatar: api.about.html.avatar,
// name: api.about.obs.name,
// suggest: { about: api.about.async.suggest },
// scuttle,
// onCancel: () => isOpen.set(false)
// })))
// isOpen.set(true)
// }

// return h('section.content', { className: computed(mode, m => m === FORWARD ? '-active' : '') }, [
// h('div.message', [ h('div.span', 'Select a friend whose shards you have been asked to forward...') ]),
// ForwardIndex({
// scuttle,
// avatar: api.about.html.avatar,
// name: api.about.obs.name,
// newForward
// }),
// forwardModal
// ])
// }

function NewCrystalForm (scuttle) {
const form = CrystalsNew({
scuttle,
Expand Down
7 changes: 7 additions & 0 deletions plugs/app/page/dark-crystal-index.mcss
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
DarkCrystal -index {
i.fa.fa-spinner {
position: absolute
top: 50%
left: 50%
transform: translate(-50%, -50%)
}

section.picker {
display: flex

Expand Down
21 changes: 11 additions & 10 deletions plugs/app/page/dark-crystal.mcss
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,32 @@ DarkCrystal {
align-content: start
justify-content: center
grid-template-columns: 40rem
grid-template-rows: 6rem 1rem 1fr auto
grid-template-rows: 4rem 3rem 1rem auto
grid-gap: 1rem

width: 100%
overflow-y: scroll

h1 {
text-transform: uppercase
letter-spacing: .5rem
font-size: 1.2rem

div.header {
display: grid
grid-template-columns: repeat(4, auto)
grid-gap: .9rem
grid-template-columns: auto 1fr auto;
grid-gap: 1rem
justify-content: start
align-items: baseline
margin-top: .5rem

h1 {
text-transform: uppercase
letter-spacing: .5rem
font-size: 1.2rem
}

i {
:hover {
color: rebeccapurple
cursor: pointer
}
}

margin-top: 2.5rem
}
}

3 changes: 2 additions & 1 deletion views/component/secret.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ module.exports = function Secret (opts) {
error = Value(),
modalOpen = Value(),
secretLabel = Value(),
secret = Value()
secret = ''
} = opts

console.log(secret)
return h('DarkCrystalSecret', when(error, renderError(), renderSecret()))

function renderSecret () {
Expand Down
Loading