-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.js
155 lines (118 loc) · 3.79 KB
/
profile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import account from '/src/account.js';
const select = q => document.querySelector(q);
const selectAll = qs => Array.prototype.slice.call(
document.querySelectorAll(qs)
);
document.body.addEventListener('ready', function(){
var p = document.location.pathname.replace(/^\/|\/$/g, '').split('/');
var name = p[1];//location.hash.substr(1) || location.host.split('.')[0];
var user_el = document.createElement('pineal-user'),
rate_el = document.createElement('fractal-rate'),
title_el = document.createElement('h1'),
subscribe_el = document.createElement('fractal-subscribe'),
seeds_el = document.createElement('div');
seeds_el.id = 'owner_seeds';
rate_el.slot='left';
rate_el.style = '--icon-size: 32px';
title_el.id = 'owner-title';
user_el.addEventListener('loaded', async ev => {
let user = ev.detail.user;
var cover = select('#cover');
var title = user.item?(user.item.title):(user.name || ('#'+user.id));
title_el.textContent = title;
user.axon.link.children(links => {
links.map(link => {
link.load(item => {
if(item.name == 'cover_images')
cover.setAttribute('src', link.url);
});
});
});
rate_el.setAttribute('src', user.axon.link.url);
select('#profile-article').setAttribute('src', user.axon.link.url);
subscribe_el.setAttribute('path', user.email);
var stories = document.querySelector('#catalogem-stories');
stories.setAttribute('owner', user.email);
user_el.link.checkOwnership(async own => {
if(!own) return seeds_el.remove();
seeds_el.innerText = await user.getValue();
seeds_el.addEventListener('click', async ev => {
if(!account.user || !account.user.super) return;
var num = parseInt(prompt(`Number of seeds ${user.email} has?`, user.value));
if(!num && num !== 0) return;
var acc_link = Link(`mongo://${Cfg.server}/acc?email=`+user.email);
acc_link.set('value', num).then(r => {
});
user.value = num;
delete user.value_promise;
seeds_el.innerText = await user.getValue();
});
});
const home = select('#home');
// create an observer instance
var observer = new MutationObserver(muts => {
console.log(muts);
let cl = document.body.classList;
muts.forEach(mut => {
if(
mut.type == 'attributes' &&
mut.attributeName == 'class'
){
document.body.classList[
home.classList.contains('selected')?
'add':
'remove'
]('home');
}
});
});
observer.observe(home, {
attributes: true
});
account.authenticated.then(account => {
if(account.user.email == user.email)
customElements.whenDefined(cover.localName).then(() => {
cover.includeAdd();
});
cover.addEventListener('upload', ev => {
let link = ev.detail.link;
if(!ev.target.link){
var newItem = {
type: 'gallery',
name: 'cover_images',
title: 'Cover images',
owner: user.email
};
let collection = 'tree';
user_el.W({
cmd: 'save',
item: newItem,
collection
}).then(r => {
if(!r || !r.item) return console.error(`
unable to init_profile_photos
`);
let link = Link(`mongo://${location.host}/${collection}#${r.item.id}`);
link.item = r.item;
account.axon.link.add(link).then(link => {
ev.target.setAttribute('src', link.url);
});
});
}
});
});
});
user_el.setAttribute('path', name);
let append = el => document.querySelector('#owner').appendChild(el);
append(user_el);
append(title_el);
append(rate_el);
append(subscribe_el);
append(seeds_el);
let click = ev => {
select('#head').goHome();
};
user_el.addEventListener('click', click);
title_el.addEventListener('click', click);
//Lib.item.children.push('mongo://'+document.location.host+'/tree'+'?domain='+domain);
});