From ae7142b501d5af09165883911e7f24c72e4ba4a6 Mon Sep 17 00:00:00 2001 From: Dipak Acharya Date: Sun, 24 Jan 2021 05:25:49 -0800 Subject: [PATCH] [Feat] Add follow users --- Makefile | 2 + frontend/package.json | 4 +- frontend/src/App.tsx | 6 +- frontend/src/Post.tsx | 4 +- frontend/src/Posts.tsx | 11 +- frontend/src/ProfilePage.tsx | 42 +- frontend/src/Signup.tsx | 1 - frontend/src/SinglePost.tsx | 4 +- go.sum | 2 + pkg/data/follow.go | 93 +++++ pkg/data/post.go | 34 ++ posts/api/handler.go | 45 ++- posts/api/post_api.proto | 11 +- posts/api/postspb/post_api.pb.go | 188 ++++++--- posts/api/postspb/post_api.pb.gw.go | 87 ++++- posts/api/postspb/post_api_grpc.pb.go | 48 ++- users/api/handler.go | 100 ++++- users/api/users_api.proto | 32 +- users/api/userspb/users_api.pb.go | 506 ++++++++++++++++++------- users/api/userspb/users_api.pb.gw.go | 299 ++++++++++++++- users/api/userspb/users_api_grpc.pb.go | 118 +++++- 21 files changed, 1410 insertions(+), 227 deletions(-) create mode 100644 pkg/data/follow.go diff --git a/Makefile b/Makefile index 49674e4..4a48cd9 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,8 @@ service: ## build the binary and docker image of $SERVICE service cd $(SERVICE) && \ make && make docker-build +restart: stop run + restart-service: ## Restart a service $SERVICE make -C $(SERVICE) api make -C $(SERVICE) diff --git a/frontend/package.json b/frontend/package.json index b90883f..1540b00 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -6,8 +6,8 @@ "scripts": { "start": "webpack-dev-server --open", "build": "webpack", - "lint": "eslint '*/**/*.{js,ts,tsx}' --quiet", - "lint-fix": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix" + "lint": "eslint 'src/**/*.{js,ts,tsx}' --quiet", + "lint-fix": "eslint 'src/**/*.{js,ts,tsx}' --quiet --fix" }, "keywords": [], "author": "", diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 1fc49c6..6f1c32e 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -86,7 +86,11 @@ export default function App() { - } /> + } + /> diff --git a/frontend/src/Post.tsx b/frontend/src/Post.tsx index 04ba9cb..3bc8172 100644 --- a/frontend/src/Post.tsx +++ b/frontend/src/Post.tsx @@ -120,7 +120,7 @@ function Post({ post: p, tokens, level, loggedIn, clickable }: PostProps) { return ( <> - {Object.keys(post.rezweet).length === 0 ? ( + {post.rezweet.id === '0' ? ( <> ) : ( <> @@ -141,7 +141,7 @@ function Post({ post: p, tokens, level, loggedIn, clickable }: PostProps) { > updatePage(updateKey + 1)} to={`/post/${post.id}`}>

{post.text}

- {!post.rezweet ? <> : getRezweet(post.rezweet)} + {post.rezweet.id === '0' ? <> : getRezweet(post.rezweet)} @{post.author.username} diff --git a/frontend/src/Posts.tsx b/frontend/src/Posts.tsx index a8bad44..2652a3e 100644 --- a/frontend/src/Posts.tsx +++ b/frontend/src/Posts.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import { useState, useEffect } from 'react'; +import { Redirect, useHistory } from 'react-router'; import { tokenToString } from 'typescript'; import { get, post, sendFileUploadRequest } from './helpers/request'; import Post from './Post'; @@ -8,15 +9,18 @@ import { CreatePostRequest, Tokens } from './types/types'; type PostsProps = { tokens: Tokens; loggedIn: boolean; + showInput: boolean; }; function Posts(props: PostsProps) { - const { loggedIn, tokens } = props; + const { loggedIn, tokens, showInput } = props; const [postText, setPostText]: [string, (prop: string) => void] = useState(''); const [posts, setPosts] = useState([]); const [message, setMessage]: [string, (prop: string) => void] = useState(''); + const history = useHistory(); useEffect(() => { - get('/posts', { headers: loggedIn ? { token: tokens.token } : {} }) + const url = loggedIn ? '/posts/feed/postfeed' : '/posts'; + get(url, { headers: loggedIn ? { token: tokens.token } : {} }) .then((res) => res.json()) .then( (json) => { @@ -60,6 +64,7 @@ function Posts(props: PostsProps) { setPosts([json.post, ...posts]); setPostText(''); setMessage('Successfully created a post'); + history.push(`/post/${json.post.id}`); }, (error) => { setMessage('Error: ' + error.message); @@ -71,7 +76,7 @@ function Posts(props: PostsProps) { <>

Posts

{!message ||

{message}

} - {!props.loggedIn || ( + {showInput && loggedIn && (