links: amend reducer to add new comments locally

This commit is contained in:
Matilde Park 2020-02-03 17:52:39 -05:00
parent 2df06777e6
commit fb9c775649
3 changed files with 70 additions and 58 deletions

File diff suppressed because one or more lines are too long

View File

@ -95,12 +95,15 @@ class UrbitApi {
let endpoint = "/~link/discussions" + path + "/" + window.btoa(url) + ".json?p=0";
let promise = await fetch(endpoint);
if (promise.ok) {
let comments = {};
comments["link-update"] = {};
comments["link-update"].comments = {};
comments["link-update"].comments.path = path;
comments["link-update"].comments.page = page;
comments["link-update"].comments.index = index;
let comments = {
"link-update": {
comments: {
path: path,
page: page,
index: index
}
}
};
comments["link-update"].comments.data = await promise.json();
store.handleEvent(comments);
}
@ -110,16 +113,18 @@ class UrbitApi {
let endpoint = "/~link/discussions" + path + "/" + window.btoa(url) + ".json?p=" + commentPage;
let promise = await fetch(endpoint);
if (promise.ok) {
let comPage = "page" + commentPage;
let responseData = await promise.json();
let update = {};
update["link-update"] = {};
update["link-update"].commentPage = {};
update["link-update"].commentPage.path = path;
update["link-update"].commentPage.linkPage = page;
update["link-update"].commentPage.index = index;
update["link-update"].commentPage.comPageNo = commentPage;
update["link-update"].commentPage.data = responseData.page;
let update = {
"link-update": {
commentPage: {
path: path,
linkPage: page,
index: index,
comPageNo: commentPage,
data: responseData.page
}
}
};
store.handleEvent(update);
}
}
@ -129,23 +134,26 @@ class UrbitApi {
let promise = await fetch(endpoint);
if (promise.ok) {
let resolvedPage = await promise.json();
let update = {};
update["link-update"] = {};
update["link-update"].page = {};
update["link-update"].page[path] = {
"page": page
let update = {
"link-update": {
page: {
[path]: {
page: page,
links: resolvedPage.page
}
}
}
};
update["link-update"].page[path].links = resolvedPage.page;
store.handleEvent(update);
}
}
async postLink(path, url, title) {
let json =
{ 'path': path,
{'path': path,
'title': title,
'url': url
};
};
let endpoint = "/~link/save";
let post = await fetch(endpoint, {
method: "POST",
@ -157,17 +165,19 @@ class UrbitApi {
});
if (post.ok) {
let update = {};
update["link-update"] = {};
update["link-update"].add = {};
update["link-update"].add[path] = {};
update["link-update"].add[path] = {
"title": title,
"url": url,
"timestamp": moment.now(),
"ship": window.ship,
"commentCount": 0
}
let update = {
"link-update": {
add: {
[path]: {
title: title,
url: url,
timestamp: moment.now(),
ship: window.ship,
commentCount: 0
}
}
}
};
store.handleEvent(update);
return true;
} else {
@ -177,9 +187,9 @@ class UrbitApi {
async postComment(path, url, comment, page, index) {
let json = {
'path': path,
'url': url,
'udon': comment
path: path,
url: url,
udon: comment
}
let endpoint = "/~link/note";
@ -193,17 +203,18 @@ class UrbitApi {
});
if (post.ok) {
let update = {};
update["link-update"] = {};
update["link-update"].commentAdd = {};
update["link-update"].commentAdd = {
"path": path,
"url": url,
"udon": comment,
"page": page,
"index": index,
"time": moment.now()
}
let update = {
"link-update": {
commentAdd: {
path: path,
url: url,
udon: comment,
page: page,
index: index,
time: moment.now()
}
}
};
store.handleEvent(update);
return true;
} else {

View File

@ -55,9 +55,10 @@ export class LinkUpdateReducer {
'time': time,
'udon': udon
}
let tempArray = state.links[path][page][index].comments.page;
let tempArray = state.links[path][page][index].comments["page0"];
tempArray.unshift(tempObj);
state.links[path][page][index].comments.page = tempArray;
state.links[path][page][index].comments["page0"] = tempArray;
}
}