From ef3ef3a42ad62c6e7b2eacbaccbc4a52d0a064a5 Mon Sep 17 00:00:00 2001 From: Ayush Bharat Jain <60114945+ayushbha@users.noreply.github.com> Date: Wed, 8 Jul 2020 17:27:43 -0700 Subject: [PATCH 1/3] Organization Page Done --- pages/organization/[pid].tsx | 116 ++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 3 deletions(-) diff --git a/pages/organization/[pid].tsx b/pages/organization/[pid].tsx index 58a9edb..1bf56c0 100644 --- a/pages/organization/[pid].tsx +++ b/pages/organization/[pid].tsx @@ -1,7 +1,117 @@ import React from "react"; +import useSWR, { mutate, trigger } from "swr"; +import axios from "axios"; +import styled from 'styled-components'; +import storage from "../../lib/utils/storage"; +import { SERVER_BASE_URL } from "../../lib/utils/constant"; +import OrganizationsAPI from "../../lib/api/organizations"; +import { Col, Row } from 'antd'; +import Header from "../../components/global/Header"; +import ArticleList from "../../components/global/ArticleList"; +import UserList from "../../components/global/UserList"; +import fetcher from "../../lib/utils/fetcher"; +import Tab_list from "../../components/profile/Tab_list"; -const replaceMe = () => { - return <> +const Organization = ({organization: InitialOrganization}) => { + const InitialOrganizationData = { + username: InitialOrganization.name, + image: InitialOrganization.image, + following: InitialOrganization.is_following, + is_moderator: InitialOrganization.is_moderator, + followers: InitialOrganization.followers, + moderators: InitialOrganization.moderators, + joined: InitialOrganization.createdAt, + bio: InitialOrganization.description + } + + const { + data: OrganizationArticles, + error: ArticleError, + } = useSWR( + `${SERVER_BASE_URL}/organizations/${InitialOrganization.slug}/articles`, + fetcher, + ); + + const { + data: OrganizationData, + error: OrganizationError, + } = useSWR( + `${SERVER_BASE_URL}/organizations/${InitialOrganization.slug}`, + fetcher, {refreshInterval:500}, + ); + + if(OrganizationData!=undefined && OrganizationData.organization!=InitialOrganization){ + InitialOrganization = OrganizationData.organization; + InitialOrganizationData.following = InitialOrganization.is_following; + } + + const Articles = OrganizationArticles || { + articles: [], + }; + + const [PostTab,setPostTab] = React.useState(true) + + const [FollowerTab,setFollowerTab] = React.useState(false) + + const handleFollow = async () => { + OrganizationsAPI.follow(InitialOrganization.slug); + }; + + const handleUnfollow = async () => { + OrganizationsAPI.unfollow(InitialOrganization.slug); + }; + + const TabClick = (key) => { + if(key=='Posts'){ + setPostTab(true) + setFollowerTab(false) + } + else if(key=='Followers'){ + setPostTab(false) + setFollowerTab(true) + } + } + + return( +
+ +
+ + + + + + + + + + + + {PostTab?:null} + {FollowerTab?:null} + + + + + + +
Moderators
+ +
+
Members
+ + + +
+
+ ); } -export default replaceMe; \ No newline at end of file +Organization.getInitialProps = async ({ query: { pid } }) => { + const { + data: { organization }, + } = await OrganizationsAPI.get(pid); + return { organization }; +}; + +export default Organization; \ No newline at end of file From f0bbe3e8f0a49a2e9a81316b7d17b5fda29c5da5 Mon Sep 17 00:00:00 2001 From: Ayush Bharat Jain <60114945+ayushbha@users.noreply.github.com> Date: Thu, 9 Jul 2020 14:55:14 -0700 Subject: [PATCH 2/3] Changed Header display --- components/global/Header.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/global/Header.tsx b/components/global/Header.tsx index 5bce70e..c951828 100644 --- a/components/global/Header.tsx +++ b/components/global/Header.tsx @@ -29,7 +29,8 @@ const SyledDetailContainer = styled.div` const StyledBio = styled.p` color: black; - padding-top: 3em; + padding-top: 1em; + margin-left: 94.4px; overflow-wrap: break-word; ` @@ -76,9 +77,9 @@ const Header = ({ user, follow, unfollow }) => { {user.bio} - {} + {user.location?:null} {} - {} + {user.occupation?:null} ) From 4f2703441910ba9dd8bba1f89d19a20559f8ccd0 Mon Sep 17 00:00:00 2001 From: Ayush Bharat Jain <60114945+ayushbha@users.noreply.github.com> Date: Thu, 9 Jul 2020 20:33:46 -0700 Subject: [PATCH 3/3] Modified UserList Component --- components/global/UserList.tsx | 80 +++++++++++++++++++++++----------- pages/organization/[pid].tsx | 5 +-- 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/components/global/UserList.tsx b/components/global/UserList.tsx index 8b55107..83994d5 100644 --- a/components/global/UserList.tsx +++ b/components/global/UserList.tsx @@ -1,7 +1,8 @@ import React from 'react'; import User from './User' -import styled from 'styled-components' -import {List, Skeleton} from 'antd'; +import styled from 'styled-components'; +import {List, Skeleton, Button} from 'antd'; +import UserAPI from '../../lib/api/user'; const StyledHeader = styled.div` font-family: Open Sans, sans-serif; @@ -13,29 +14,58 @@ const StyledHeader = styled.div` margin-bottom: 0.2em; ` -const UserList = (props) => ( - <> - {props.header} - ( +const UserList = (props) => { - - - - - - )} - /> - -) + const follow = user => { + if(user.profile.following == false){ + UserAPI.follow(user.profile.username,user.profile.email) + } + else{ + UserAPI.unfollow(user.profile.username) + } + } + + return( +
+ {props.header} + { + const handleClick = () => { + follow(user) + } + return( + + + + + + + )}} + /> +
+ ) +} export default UserList \ No newline at end of file diff --git a/pages/organization/[pid].tsx b/pages/organization/[pid].tsx index 1bf56c0..419dedc 100644 --- a/pages/organization/[pid].tsx +++ b/pages/organization/[pid].tsx @@ -1,8 +1,5 @@ import React from "react"; -import useSWR, { mutate, trigger } from "swr"; -import axios from "axios"; -import styled from 'styled-components'; -import storage from "../../lib/utils/storage"; +import useSWR from "swr"; import { SERVER_BASE_URL } from "../../lib/utils/constant"; import OrganizationsAPI from "../../lib/api/organizations"; import { Col, Row } from 'antd';