mirror of
https://github.com/urbit/shrub.git
synced 2024-12-02 21:34:04 +03:00
links: amend reducer to add new comments locally
This commit is contained in:
parent
2df06777e6
commit
fb9c775649
File diff suppressed because one or more lines are too long
@ -10,7 +10,7 @@ class UrbitApi {
|
|||||||
setAuthTokens(authTokens) {
|
setAuthTokens(authTokens) {
|
||||||
this.authTokens = authTokens;
|
this.authTokens = authTokens;
|
||||||
this.bindPaths = [];
|
this.bindPaths = [];
|
||||||
|
|
||||||
this.invite = {
|
this.invite = {
|
||||||
accept: this.inviteAccept.bind(this),
|
accept: this.inviteAccept.bind(this),
|
||||||
decline: this.inviteDecline.bind(this),
|
decline: this.inviteDecline.bind(this),
|
||||||
@ -21,7 +21,7 @@ class UrbitApi {
|
|||||||
bind(path, method, ship = this.authTokens.ship, app, success, fail, quit) {
|
bind(path, method, ship = this.authTokens.ship, app, success, fail, quit) {
|
||||||
this.bindPaths = _.uniq([...this.bindPaths, path]);
|
this.bindPaths = _.uniq([...this.bindPaths, path]);
|
||||||
|
|
||||||
window.subscriptionId = window.urb.subscribe(ship, app, path,
|
window.subscriptionId = window.urb.subscribe(ship, app, path,
|
||||||
(err) => {
|
(err) => {
|
||||||
fail(err);
|
fail(err);
|
||||||
},
|
},
|
||||||
@ -44,7 +44,7 @@ class UrbitApi {
|
|||||||
window.urb.poke(ship, appl, mark, data,
|
window.urb.poke(ship, appl, mark, data,
|
||||||
(json) => {
|
(json) => {
|
||||||
resolve(json);
|
resolve(json);
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
@ -54,9 +54,9 @@ class UrbitApi {
|
|||||||
inviteAction(data) {
|
inviteAction(data) {
|
||||||
this.action("invite-store", "json", data);
|
this.action("invite-store", "json", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
inviteInvite(path, ship) {
|
inviteInvite(path, ship) {
|
||||||
this.action("invite-hook", "json",
|
this.action("invite-hook", "json",
|
||||||
{
|
{
|
||||||
invite: {
|
invite: {
|
||||||
path: '/chat',
|
path: '/chat',
|
||||||
@ -81,7 +81,7 @@ class UrbitApi {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
inviteDecline(uid) {
|
inviteDecline(uid) {
|
||||||
this.inviteAction({
|
this.inviteAction({
|
||||||
decline: {
|
decline: {
|
||||||
@ -95,12 +95,15 @@ class UrbitApi {
|
|||||||
let endpoint = "/~link/discussions" + path + "/" + window.btoa(url) + ".json?p=0";
|
let endpoint = "/~link/discussions" + path + "/" + window.btoa(url) + ".json?p=0";
|
||||||
let promise = await fetch(endpoint);
|
let promise = await fetch(endpoint);
|
||||||
if (promise.ok) {
|
if (promise.ok) {
|
||||||
let comments = {};
|
let comments = {
|
||||||
comments["link-update"] = {};
|
"link-update": {
|
||||||
comments["link-update"].comments = {};
|
comments: {
|
||||||
comments["link-update"].comments.path = path;
|
path: path,
|
||||||
comments["link-update"].comments.page = page;
|
page: page,
|
||||||
comments["link-update"].comments.index = index;
|
index: index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
comments["link-update"].comments.data = await promise.json();
|
comments["link-update"].comments.data = await promise.json();
|
||||||
store.handleEvent(comments);
|
store.handleEvent(comments);
|
||||||
}
|
}
|
||||||
@ -110,16 +113,18 @@ class UrbitApi {
|
|||||||
let endpoint = "/~link/discussions" + path + "/" + window.btoa(url) + ".json?p=" + commentPage;
|
let endpoint = "/~link/discussions" + path + "/" + window.btoa(url) + ".json?p=" + commentPage;
|
||||||
let promise = await fetch(endpoint);
|
let promise = await fetch(endpoint);
|
||||||
if (promise.ok) {
|
if (promise.ok) {
|
||||||
let comPage = "page" + commentPage;
|
|
||||||
let responseData = await promise.json();
|
let responseData = await promise.json();
|
||||||
let update = {};
|
let update = {
|
||||||
update["link-update"] = {};
|
"link-update": {
|
||||||
update["link-update"].commentPage = {};
|
commentPage: {
|
||||||
update["link-update"].commentPage.path = path;
|
path: path,
|
||||||
update["link-update"].commentPage.linkPage = page;
|
linkPage: page,
|
||||||
update["link-update"].commentPage.index = index;
|
index: index,
|
||||||
update["link-update"].commentPage.comPageNo = commentPage;
|
comPageNo: commentPage,
|
||||||
update["link-update"].commentPage.data = responseData.page;
|
data: responseData.page
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
store.handleEvent(update);
|
store.handleEvent(update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,23 +134,26 @@ class UrbitApi {
|
|||||||
let promise = await fetch(endpoint);
|
let promise = await fetch(endpoint);
|
||||||
if (promise.ok) {
|
if (promise.ok) {
|
||||||
let resolvedPage = await promise.json();
|
let resolvedPage = await promise.json();
|
||||||
let update = {};
|
let update = {
|
||||||
update["link-update"] = {};
|
"link-update": {
|
||||||
update["link-update"].page = {};
|
page: {
|
||||||
update["link-update"].page[path] = {
|
[path]: {
|
||||||
"page": page
|
page: page,
|
||||||
|
links: resolvedPage.page
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
update["link-update"].page[path].links = resolvedPage.page;
|
|
||||||
store.handleEvent(update);
|
store.handleEvent(update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async postLink(path, url, title) {
|
async postLink(path, url, title) {
|
||||||
let json =
|
let json =
|
||||||
{ 'path': path,
|
{'path': path,
|
||||||
'title': title,
|
'title': title,
|
||||||
'url': url
|
'url': url
|
||||||
};
|
};
|
||||||
let endpoint = "/~link/save";
|
let endpoint = "/~link/save";
|
||||||
let post = await fetch(endpoint, {
|
let post = await fetch(endpoint, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -157,17 +165,19 @@ class UrbitApi {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (post.ok) {
|
if (post.ok) {
|
||||||
let update = {};
|
let update = {
|
||||||
update["link-update"] = {};
|
"link-update": {
|
||||||
update["link-update"].add = {};
|
add: {
|
||||||
update["link-update"].add[path] = {};
|
[path]: {
|
||||||
update["link-update"].add[path] = {
|
title: title,
|
||||||
"title": title,
|
url: url,
|
||||||
"url": url,
|
timestamp: moment.now(),
|
||||||
"timestamp": moment.now(),
|
ship: window.ship,
|
||||||
"ship": window.ship,
|
commentCount: 0
|
||||||
"commentCount": 0
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
store.handleEvent(update);
|
store.handleEvent(update);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -177,9 +187,9 @@ class UrbitApi {
|
|||||||
|
|
||||||
async postComment(path, url, comment, page, index) {
|
async postComment(path, url, comment, page, index) {
|
||||||
let json = {
|
let json = {
|
||||||
'path': path,
|
path: path,
|
||||||
'url': url,
|
url: url,
|
||||||
'udon': comment
|
udon: comment
|
||||||
}
|
}
|
||||||
|
|
||||||
let endpoint = "/~link/note";
|
let endpoint = "/~link/note";
|
||||||
@ -193,17 +203,18 @@ class UrbitApi {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (post.ok) {
|
if (post.ok) {
|
||||||
let update = {};
|
let update = {
|
||||||
update["link-update"] = {};
|
"link-update": {
|
||||||
update["link-update"].commentAdd = {};
|
commentAdd: {
|
||||||
update["link-update"].commentAdd = {
|
path: path,
|
||||||
"path": path,
|
url: url,
|
||||||
"url": url,
|
udon: comment,
|
||||||
"udon": comment,
|
page: page,
|
||||||
"page": page,
|
index: index,
|
||||||
"index": index,
|
time: moment.now()
|
||||||
"time": moment.now()
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
store.handleEvent(update);
|
store.handleEvent(update);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -55,9 +55,10 @@ export class LinkUpdateReducer {
|
|||||||
'time': time,
|
'time': time,
|
||||||
'udon': udon
|
'udon': udon
|
||||||
}
|
}
|
||||||
let tempArray = state.links[path][page][index].comments.page;
|
|
||||||
|
let tempArray = state.links[path][page][index].comments["page0"];
|
||||||
tempArray.unshift(tempObj);
|
tempArray.unshift(tempObj);
|
||||||
state.links[path][page][index].comments.page = tempArray;
|
state.links[path][page][index].comments["page0"] = tempArray;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user