forked from mixmix/infinite-game
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from blockades/search-and-show
Search and show
- Loading branch information
Showing
11 changed files
with
342 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { h, Array: MutantArray, resolve } = require('mutant') | ||
|
||
const { isFeedId } = require('ssb-ref') | ||
const AddPeer = require('./AddPeer') | ||
|
||
module.exports = function Search (props = {}, children = []) { | ||
const { suggest, secrets, routeTo, myId } = props | ||
const state = { | ||
selected: MutantArray([]) | ||
} | ||
|
||
return h('div.search', [ | ||
h('i.fa.fa-search.fa-lg'), | ||
AddPeer({ | ||
suggest, | ||
secrets, | ||
selected: state.selected, | ||
max: 1, | ||
canClear: false, | ||
onSubmit: () => { | ||
const record = resolve(state.selected)[0] | ||
if (record.id === myId) routeTo({ path: `/settings/account` }) | ||
else if (isFeedId(record.id)) routeTo({ path: `/peers/${record.id}`, peer: { id: record.id } }) | ||
else routeTo({ path: `/secrets/${record.id}`, secret: record }) | ||
} | ||
}, [ h('div') ]) | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
div.search { | ||
display: grid | ||
grid-template-columns: auto 1fr auto | ||
justify-content: center | ||
align-items: center | ||
grid-gap: 0.5rem | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const nest = require('depnest') | ||
const { h, computed, Value } = require('mutant') | ||
|
||
const Avatar = require('../../components/Avatar') | ||
const Backward = require('../../components/Backward') | ||
|
||
exports.gives = nest('views.peers.show') | ||
|
||
exports.needs = nest({ | ||
'app.actions.shards.fetch': 'first', | ||
'router.sync.goTo': 'first', | ||
'router.sync.goBack': 'first', | ||
'about.obs.imageUrl': 'first', | ||
'about.obs.name': 'first' | ||
}) | ||
|
||
exports.create = (api) => { | ||
return nest('views.peers.show', peersShow) | ||
|
||
// This design isn't right. I've put together something to show for the moment. | ||
// %%TODO%%: Redesign the peersShow interface and the shardsShow interface | ||
|
||
function peersShow (request, children = []) { | ||
const state = { | ||
id: request.peer.id | ||
} | ||
|
||
return h('Peers -show', [ | ||
Backward({ routeTo: api.router.sync.goBack }), | ||
h('div.container', [ | ||
h('section.profile', [ | ||
h('div.left', [ | ||
Avatar({ | ||
id: state.id, | ||
imageUrl: api.about.obs.imageUrl, | ||
size: 6 | ||
}) | ||
]), | ||
h('div.right', [ | ||
h('p', 'Shards you hold belonging to: '), | ||
h('div.name', [ h('strong', api.about.obs.name(state.id)) ]) | ||
]) | ||
]), | ||
computed(api.app.actions.shards.fetch(), (shards) => { | ||
if (!shards.length) return h('i.fa.fa-spinner.fa-pulse.fa-2x') | ||
|
||
const peer = shards.find(s => s.id === state.id) | ||
|
||
if (!peer) return h('section', [ h('p', `You don't hold any shards for this person`) ]) | ||
else return peer.shards.map((shard) => { | ||
return h('section.shard', { title: shard.root, 'ev-click': () => api.router.sync.goTo({ path: `/shards/${shard.id}`, shard: { ...shard, peerId: peer.id } }) }, [ | ||
h('div.left', [ | ||
h('div.sentAt', shard.sentAt) | ||
]), | ||
h('div.right', [ | ||
h('div.state', shard.state) | ||
]) | ||
]) | ||
}) | ||
}) | ||
]) | ||
]) | ||
} | ||
} |
Oops, something went wrong.