Skip to content

Commit

Permalink
Merge pull request #12 from Reeywhaar/edit-article
Browse files Browse the repository at this point in the history
Edit article + CSP
  • Loading branch information
umputun authored Nov 19, 2018
2 parents b99c060 + c1b8e09 commit 0ff0ea3
Show file tree
Hide file tree
Showing 10 changed files with 673 additions and 129 deletions.
128 changes: 107 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
"type": "git",
"url": "git+https://github.com/igoradamenko/rtnews-ui.git"
},
"sideEffects": ["*.scss", "./src/main.jsx"],
"sideEffects": [
"*.scss",
"./src/main.jsx"
],
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
Expand All @@ -25,9 +29,11 @@
"node-sass": "^4.10.0",
"preact": "^8.3.1",
"preact-compat": "^3.18.4",
"quill": "^1.3.6",
"react-redux": "^5.0.7",
"react-router-dom": "^4.3.1",
"react-router-hash-link": "^1.2.1",
"react-router-scroll-4": "^1.0.0-beta.2",
"react-svg-inline": "^2.1.1",
"redux": "^4.0.0",
"sass-loader": "^7.1.0",
Expand Down
35 changes: 32 additions & 3 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,52 @@ export async function pollActiveArticle(ms = 295) {
}
}

export function addArticle(link, title = "", snippet = "") {
/**
* Adds article or updates it if title already exists
*/
export function addArticle(link, title = "", snippet = "", content = "") {
const body = { link };
if (title.length > 0) body.title = title;
if (snippet.length > 0) body.snippet = snippet;
if (!title || title.length > 0) body.title = title;
if (!snippet || snippet.length > 0) body.snippet = snippet;
if (!content || content.length > 0) body.content = content;

const headers = new Headers();
headers.append("Content-Type", "application/json");

const url = title.length > 0 ? "/news/manual" : "/news";

for (let [slug, article] of articlesCache.entries()) {
if (article.title === title) {
articlesCache.delete(slug);
articlesIdSlugMap.delete(article.id);
}
}

return request(url, {
method: "POST",
body: JSON.stringify(body),
headers,
});
}

export function updateArticle(updated) {
for (let [slug, article] of articlesCache.entries()) {
if (article.id === updated.id) {
articlesCache.delete(slug);
articlesIdSlugMap.delete(article.id);
}
}

const headers = new Headers();
headers.append("Content-Type", "application/json");

return request("/news/manual", {
method: "POST",
body: JSON.stringify(updated),
headers,
});
}

export function moveArticle(id, offset) {
return request(`/news/moveid/${id}/${offset}`, { method: "PUT" });
}
Expand Down
Loading

0 comments on commit 0ff0ea3

Please sign in to comment.