From bed336cfb15ccc9b45bb4ca771e7d7cbebe19667 Mon Sep 17 00:00:00 2001 From: Vyrtsev Mikhail Date: Mon, 8 Apr 2019 01:10:42 +0300 Subject: [PATCH 1/4] update readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4055096b..9d9c83c9 100644 --- a/README.md +++ b/README.md @@ -507,7 +507,7 @@ type Comment struct { User User `json:"user"` // user info, read only Locator Locator `json:"locator"` // post locator Score int `json:"score"` // comment score, read only - Votes map[string]bool `json:"votes"` // comment votes, read only + Vote int `json:"vote"` // vote for the current user, -1/1/0. Controversy float64 `json:"controversy,omitempty"` // comment controversy, read only Timestamp time.Time `json:"time"` // time stamp, read only Edit *Edit `json:"edit,omitempty" bson:"edit,omitempty"` // pointer to have empty default in json response @@ -609,11 +609,11 @@ Sort can be `time`, `active` or `score`. Supported sort order with prefix -/+, i ### Images management -* `GET /api/v1/picture/{user}/{id}` - load stored image +* `GET /api/v1/picture/{user}/{id}` - load stored image * `POST /api/v1/picture` - upload and store image, uses post form with `FormFile("file")`. returns `{"id": user/imgid}` _auth required_ _returned id should be appended to load image url on caller side_ - + ### Admin * `DELETE /api/v1/admin/comment/{id}?site=site-id&url=post-url` - delete comment by `id`. From eca230b87f90fef7ce5bb0b6586f398d23025573 Mon Sep 17 00:00:00 2001 From: Vyrtsev Mikhail Date: Wed, 10 Apr 2019 02:39:35 +0300 Subject: [PATCH 2/4] fix tabs --- web/.babelrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/.babelrc b/web/.babelrc index 7b541de0..d99459f5 100644 --- a/web/.babelrc +++ b/web/.babelrc @@ -7,7 +7,7 @@ "browsers": ["> 1%", "android >= 4.4.4", "ios >= 9", "IE >= 11"] }, "useBuiltIns": "usage", - "corejs": 3 + "corejs": 3 } ], [ From 6f67cbc30d2362d3c1768f61cc11995e4b2ac5c6 Mon Sep 17 00:00:00 2001 From: Vyrtsev Mikhail Date: Wed, 10 Apr 2019 02:49:08 +0300 Subject: [PATCH 3/4] remove webpack log spam --- web/webpack.config.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/webpack.config.js b/web/webpack.config.js index 92ba409e..47aef48c 100644 --- a/web/webpack.config.js +++ b/web/webpack.config.js @@ -139,6 +139,7 @@ module.exports = () => ({ }, stats: { children: false, + entrypoints: false, }, devServer: { host: 'localhost', @@ -157,5 +158,9 @@ module.exports = () => ({ changeOrigin: true, }, }, + stats: { + children: false, + entrypoints: false, + }, }, }); From 3246b662140fca74bb1fcf4befd25b1648220861 Mon Sep 17 00:00:00 2001 From: Vyrtsev Mikhail Date: Wed, 10 Apr 2019 02:24:19 +0300 Subject: [PATCH 4/4] support new voting api in ui --- web/app/common/api.ts | 14 +++++++++++--- web/app/common/types.ts | 8 ++++++-- web/app/components/comment/comment.test.tsx | 6 +++--- web/app/components/comment/comment.tsx | 12 +----------- web/app/components/root/root.tsx | 15 +++++++++++++-- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/web/app/common/api.ts b/web/app/common/api.ts index ed6b9c6f..b5948148 100644 --- a/web/app/common/api.ts +++ b/web/app/common/api.ts @@ -52,7 +52,10 @@ export const logOut = (): Promise => export const getConfig = (): Promise => fetcher.get(`/config`); export const getPostComments = (sort: Sorting): Promise => - fetcher.get(`/find?site=${siteId}&url=${url}&sort=${sort}&format=tree`); + fetcher.get({ + url: `/find?site=${siteId}&url=${url}&sort=${sort}&format=tree`, + withCredentials: true, + }); export const getLastComments = (siteId: string, max: number): Promise => fetcher.get(`/last/${max}?site=${siteId}`); @@ -63,7 +66,8 @@ export const getCommentsCount = (siteId: string, urls: string[]): Promise<{ url: body: urls, }); -export const getComment = (id: Comment['id']): Promise => fetcher.get(`/id/${id}?url=${url}`); +export const getComment = (id: Comment['id']): Promise => + fetcher.get({ url: `/id/${id}?url=${url}`, withCredentials: true }); export const getUserComments = ( userId: User['id'], @@ -71,7 +75,11 @@ export const getUserComments = ( ): Promise<{ comments: Comment[]; count: number; -}> => fetcher.get(`/comments?user=${userId}&limit=${limit}`); +}> => + fetcher.get({ + url: `/comments?user=${userId}&limit=${limit}`, + withCredentials: true, + }); export const putCommentVote = ({ id, value }: { id: Comment['id']; value: number }): Promise => fetcher.put({ diff --git a/web/app/common/types.ts b/web/app/common/types.ts index c14d8146..d1843789 100644 --- a/web/app/common/types.ts +++ b/web/app/common/types.ts @@ -44,8 +44,12 @@ export interface Comment { locator: Locator; /** comment score, read only */ score: number; - /** comment votes, read only */ - votes: { [key: string]: boolean }; + /** + * vote delta, + * if user hasn't voted delta will be 0, + * -1/+1 for downvote/upvote + */ + vote: number; /** comment controversy, read only */ controversy?: number; /** pointer to have empty default in json response */ diff --git a/web/app/components/comment/comment.test.tsx b/web/app/components/comment/comment.test.tsx index 254bb4ef..cc8a947e 100644 --- a/web/app/components/comment/comment.test.tsx +++ b/web/app/components/comment/comment.test.tsx @@ -12,7 +12,7 @@ const DefaultProps: Partial = { view: 'main', data: { text: 'test comment', - votes: {}, + vote: 0, user: { id: 'someone', picture: 'somepicture-url', @@ -121,7 +121,7 @@ describe('', () => { const element = ( ); @@ -146,7 +146,7 @@ describe('', () => { const element = ( ); diff --git a/web/app/components/comment/comment.tsx b/web/app/components/comment/comment.tsx index 5fd98b97..3062f922 100644 --- a/web/app/components/comment/comment.tsx +++ b/web/app/components/comment/comment.tsx @@ -104,18 +104,8 @@ export class Comment extends Component { } updateState(props: Props) { - let scoreDelta = 0; - if (props.user) { - if (props.data.votes[props.user.id] === true) { - ++scoreDelta; - } - if (props.data.votes[props.user.id] === false) { - --scoreDelta; - } - } - this.setState({ - scoreDelta, + scoreDelta: props.data.vote, cachedScore: props.data.score, }); diff --git a/web/app/components/root/root.tsx b/web/app/components/root/root.tsx index 345f708a..c638be64 100644 --- a/web/app/components/root/root.tsx +++ b/web/app/components/root/root.tsx @@ -113,6 +113,17 @@ export class Root extends Component { window.addEventListener('message', this.onMessage.bind(this)); } + logIn = async (p: AuthProvider): Promise => { + const user = await this.props.logIn(p); + await this.props.fetchComments(this.props.sort); + return user; + }; + + logOut = async (): Promise => { + await this.props.logOut(); + await this.props.fetchComments(this.props.sort); + }; + checkUrlHash( e: Event & { newURL?: string; @@ -202,8 +213,8 @@ export class Root extends Component { providers={StaticStore.config.auth_providers} isCommentsDisabled={isCommentsDisabled} postInfo={this.props.info} - onSignIn={this.props.logIn} - onSignOut={this.props.logOut} + onSignIn={this.logIn} + onSignOut={this.logOut} onBlockedUsersShow={this.onBlockedUsersShow} onBlockedUsersHide={this.onBlockedUsersHide} onCommentsEnable={this.props.enableComments}