Skip to content

Commit b1b8169

Browse files
committed
refactor(data): ♻️ add contact tabbing between (un)/paired
1 parent e340065 commit b1b8169

File tree

8 files changed

+108
-89
lines changed

8 files changed

+108
-89
lines changed

src/components/contacts-list.js

Lines changed: 64 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
envoy,
44
restate,
55
sortContactsByAlias,
6+
filterPairedContacts,
7+
filterUnpairedContacts,
68
timeago,
79
getAvatar,
810
} from '../helpers/utils.js'
@@ -15,6 +17,7 @@ const initialState = {
1517
placement: 'contacts',
1618
rendered: null,
1719
responsive: true,
20+
showUnpaired: false,
1821
delay: 500,
1922
wallet: {},
2023
contacts: [],
@@ -25,7 +28,23 @@ const initialState = {
2528
) {},
2629
header: state => html`
2730
<header>
28-
<h6>Contacts (${state.contacts.length})</h6>
31+
<div class="inline row gap-2">
32+
<h5 class="lh-2">Contacts</h5>
33+
<button
34+
id="paired_contacts"
35+
class="pill rounded${!state.showUnpaired ? ' active' : ''}"
36+
title="Paired Contacts"
37+
>
38+
Paired <span class="indicator">${state.contacts.filter(filterPairedContacts).length}</span>
39+
</button>
40+
<button
41+
id="unpaired_contacts"
42+
class="pill rounded${state.showUnpaired ? ' active' : ''}"
43+
title="Unpaired Contacts"
44+
>
45+
Unpaired <span class="indicator">${state.contacts.filter(filterUnpairedContacts).length}</span>
46+
</button>
47+
</div>
2948
<button
3049
id="add_contact"
3150
class="pill rounded"
@@ -43,10 +62,17 @@ const initialState = {
4362
4463
<div>
4564
${
46-
state.contacts.length > 0
65+
state.contacts?.length > 0
4766
? (
4867
await Promise.all(
49-
state.contacts.map(async c => await state.item(c))
68+
state.contacts
69+
.filter(
70+
state.showUnpaired
71+
? filterUnpairedContacts
72+
: filterPairedContacts
73+
)
74+
.sort(sortContactsByAlias)
75+
.map(async c => await state.item(c)),
5076
)
5177
).join('')
5278
: ''
@@ -60,7 +86,6 @@ const initialState = {
6086
${await state.footer(state)}
6187
`,
6288
item: async c => {
63-
// console.warn('contact list item', c)
6489
if ('string' === typeof c) {
6590
return html`
6691
<article>
@@ -118,6 +143,18 @@ const initialState = {
118143
<h4>${itemAlias}</h4>
119144
<h5>${itemName}</h5>
120145
</address>
146+
<!-- <aside class="inline row">
147+
<button class="pill rounded">
148+
<svg width="24" height="24" viewBox="0 0 24 24">
149+
<use xlink:href="#icon-arrow-circle-up"></use>
150+
</svg>
151+
</button>
152+
<button class="pill rounded">
153+
<svg width="24" height="24" viewBox="0 0 24 24">
154+
<use xlink:href="#icon-arrow-circle-down"></use>
155+
</svg>
156+
</button>
157+
</aside> -->
121158
</a>
122159
`
123160
},
@@ -170,30 +207,19 @@ const initialState = {
170207
elements: {
171208
},
172209
events: {
173-
// handleChange: state => event => {
174-
// event.preventDefault()
175-
// // console.log(
176-
// // 'handle balance change',
177-
// // [event.target],
178-
// // )
179-
// },
180210
handleClick: state => event => {
181211
event.preventDefault()
182-
// console.log(
183-
// 'handle contacts click',
184-
// event,
185-
// state,
186-
// )
212+
event.stopPropagation()
213+
console.log(
214+
'handle contacts click',
215+
event,
216+
state,
217+
)
187218
},
188219
handleContactsChange: (newState, oldState) => {
189220
if (newState.contacts !== oldState.contacts) {
190-
// console.log(
191-
// 'handle contacts update',
192-
// {newState, oldState}
193-
// )
194-
195221
newState.render?.({
196-
contacts: newState.contacts?.sort(sortContactsByAlias),
222+
contacts: newState.contacts
197223
})
198224
}
199225
}
@@ -208,28 +234,19 @@ let state = envoy(
208234
export async function setupContactsList(
209235
el, setupState = {}
210236
) {
211-
console.log(
212-
'setupContactsList state.contacts',
213-
state.contacts
214-
)
215237
restate(state, setupState)
216-
// if (setupState?.events?.handleContactsChange) {
217-
// state._listeners = [
218-
// setupState?.events?.handleContactsChange
219-
// ]
220-
// }
221238

222239
state.slugs.section = `${state.name}_${state.id}`
223240
.toLowerCase().replace(' ', '_')
224241

225242
const section = document.createElement('section')
226243

227-
state.elements.section = section
228-
229244
section.id = state.slugs.section
230245
section.classList.add(state.placement || '')
231246
section.innerHTML = await state.content(state)
232247

248+
state.elements.section = section
249+
233250
function addListener(
234251
node,
235252
event,
@@ -240,21 +257,8 @@ export async function setupContactsList(
240257
node.addEventListener(event, handler, capture)
241258
}
242259

243-
function addListeners() {
244-
// addListener(
245-
// section,
246-
// 'close',
247-
// state.events.handleChange(state)
248-
// )
249-
addListener(
250-
section,
251-
'click',
252-
state.events.handleClick(state),
253-
)
254-
}
255-
256260
function removeAllListeners(
257-
targets = [section],
261+
targets = [state.elements.section],
258262
) {
259263
_handlers = _handlers
260264
.filter(({ node, event, handler, capture }) => {
@@ -266,19 +270,28 @@ export async function setupContactsList(
266270
})
267271
}
268272

273+
function addListeners() {
274+
addListener(
275+
state.elements.section,
276+
'click',
277+
state.events.handleClick(state),
278+
)
279+
}
280+
269281
state.removeAllListeners = removeAllListeners
282+
state.addListeners = addListeners
270283

271284
async function render(
272285
renderState = {},
273286
position = 'afterbegin',
274287
) {
275288
await restate(state, renderState)
276289

277-
section.id = state.slugs.section
278-
section.innerHTML = await state.content(state)
290+
state.elements.section.id = state.slugs.section
291+
state.elements.section.innerHTML = await state.content(state)
279292

280-
removeAllListeners()
281-
addListeners()
293+
state.removeAllListeners()
294+
state.addListeners()
282295

283296
if (!state.rendered) {
284297
el.insertAdjacentElement(position, section)

src/helpers/wallet.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ export async function decryptData(
361361
}
362362

363363
export function storedData(
364-
encryptionPassword, keystore,
364+
encryptionPassword,
365+
keystore,
365366
) {
366367
const SD = {}
367368

src/rigs/add-contact.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export let addContactRig = (async function (globals) {
6969

7070
state.contact = newContact
7171

72-
console.log('debounceField', field, localName, newContact)
72+
// console.log('debounceField', field, localName, newContact)
7373

7474
getStoreData(
7575
store.contacts,
@@ -78,7 +78,7 @@ export let addContactRig = (async function (globals) {
7878
appState.contacts = res
7979

8080
return contactsList.restate({
81-
contacts: res?.sort(sortContactsByAlias),
81+
contacts: res,
8282
userInfo,
8383
})
8484
}
@@ -157,11 +157,11 @@ export let addContactRig = (async function (globals) {
157157
},
158158
}
159159

160-
console.log(
161-
'add contact handleInput parsedAddr',
162-
value,
163-
xkey,
164-
)
160+
// console.log(
161+
// 'add contact handleInput parsedAddr',
162+
// value,
163+
// xkey,
164+
// )
165165
}
166166

167167
if (existingContacts?.length > 0) {
@@ -202,7 +202,7 @@ export let addContactRig = (async function (globals) {
202202
appState.contacts = res
203203

204204
return contactsList.restate({
205-
contacts: res?.sort(sortContactsByAlias),
205+
contacts: res,
206206
userInfo,
207207
})
208208
}
@@ -566,7 +566,7 @@ export let addContactRig = (async function (globals) {
566566
)
567567

568568
pairedContact.then(pc => {
569-
console.log('pairedContact', pc)
569+
// console.log('pairedContact', pc)
570570

571571
getStoreData(
572572
store.contacts,
@@ -576,12 +576,12 @@ export let addContactRig = (async function (globals) {
576576

577577
updateAllFunds(state.wallet, walletFunds)
578578
.then(funds => {
579-
console.log('updateAllFunds then funds', funds)
579+
// console.log('updateAllFunds then funds', funds)
580580
})
581581
.catch(err => console.error('catch updateAllFunds', err, state.wallet))
582582

583583
return contactsList.restate({
584-
contacts: res?.sort(sortContactsByAlias),
584+
contacts: res,
585585
userInfo,
586586
})
587587
}

src/rigs/confirm-action.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export let confirmActionRig = (async function (globals) {
77
'use strict';
88

99
let {
10-
mainApp, setupDialog, appDialogs, appState, appTools,
11-
store, userInfo, contactsList,
10+
mainApp, setupDialog,
1211
} = globals
1312

1413
let confirmAction = await setupDialog(

src/rigs/confirm-delete.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export let confirmDeleteRig = (async function (globals) {
8787
appState.contacts = res
8888

8989
return contactsList.restate({
90-
contacts: res?.sort(sortContactsByAlias),
90+
contacts: res,
9191
userInfo,
9292
})
9393
}

0 commit comments

Comments
 (0)