mirror of
https://github.com/RetroShare/RSNewWebUI.git
synced 2026-09-14 11:05:47 +05:00
separate data from component
This commit is contained in:
parent
17f608d626
commit
653d977130
@ -1,6 +1,7 @@
|
||||
let m = require('mithril');
|
||||
let rs = require('rswebui');
|
||||
let widget = require('widgets');
|
||||
let data = require('network_data');
|
||||
|
||||
|
||||
const ConfirmRemove = () => {
|
||||
@ -103,36 +104,14 @@ const SearchBar = () => {
|
||||
const Friends = () => {
|
||||
return {
|
||||
oninit: () => {
|
||||
FriendNodes = {};
|
||||
rs.rsJsonApiRequest(
|
||||
'/rsPeers/getFriendList', {},
|
||||
(friendListIds) => {
|
||||
friendListIds.sslIds.map(
|
||||
(sslId) => rs.rsJsonApiRequest(
|
||||
'/rsPeers/getPeerDetails', {
|
||||
sslId
|
||||
},
|
||||
(details) => {
|
||||
// Store nodes obj with gpg id as key
|
||||
// single node can have multiple identities
|
||||
if(FriendNodes[details.det.gpg_id] === undefined)
|
||||
FriendNodes[details.det.gpg_id] = {
|
||||
locations: [details.det],
|
||||
isSearched: true
|
||||
}
|
||||
else
|
||||
FriendNodes[details.det.gpg_id].locations.push(
|
||||
details.det);
|
||||
})
|
||||
);
|
||||
});
|
||||
data.refreshGpgDetails();
|
||||
},
|
||||
view: () => m('.widget', [
|
||||
m('h3', 'Friend nodes'),
|
||||
m('hr'),
|
||||
Object.keys(FriendNodes).map((id) => m(Node, {
|
||||
data: FriendNodes[id].locations,
|
||||
isSearched: FriendNodes[id].isSearched,
|
||||
Object.keys(data.gpgDetails).map((id) => m(Node, {
|
||||
data: data.gpgDetails[id].locations,
|
||||
isSearched: data.gpgDetails[id].isSearched,
|
||||
})),
|
||||
]),
|
||||
};
|
||||
|
||||
45
webui-src/app/network/network_data.js
Normal file
45
webui-src/app/network/network_data.js
Normal file
@ -0,0 +1,45 @@
|
||||
let rs = require('rswebui');
|
||||
|
||||
module.exports = {
|
||||
sslIds: [],
|
||||
sslDetails: [],
|
||||
gpgDetails: {},
|
||||
|
||||
refreshIds() {
|
||||
return rs.rsJsonApiRequest(
|
||||
'/rsPeers/getFriendList',
|
||||
{},
|
||||
data => (this.sslIds = data.sslIds),
|
||||
);
|
||||
},
|
||||
|
||||
loadSslDetails() {
|
||||
this.sslDetails = [];
|
||||
|
||||
return Promise.all(
|
||||
this.sslIds.map(sslId =>
|
||||
rs.rsJsonApiRequest('/rsPeers/getPeerDetails', {sslId}, data =>
|
||||
this.sslDetails.push(data.det),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
refreshGpgDetails() {
|
||||
let details = {};
|
||||
|
||||
this.refreshIds()
|
||||
.then(() => this.loadSslDetails())
|
||||
.then(() => {
|
||||
this.sslDetails.map(data => {
|
||||
if (details[data.gpg_id] === undefined) {
|
||||
details[data.gpg_id] = {isSearched: true, locations: [data]};
|
||||
console.log(data);
|
||||
} else {
|
||||
details[data.gpg_id].locations.push(data);
|
||||
}
|
||||
});
|
||||
this.gpgDetails = details;
|
||||
});
|
||||
},
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user