diff --git a/packages/frontend/src/components/SearchInput.tsx b/packages/frontend/src/components/SearchInput.tsx index c9887c89..5644f169 100644 --- a/packages/frontend/src/components/SearchInput.tsx +++ b/packages/frontend/src/components/SearchInput.tsx @@ -3,7 +3,7 @@ */ import React from "react"; -import { Redirect } from "react-router-dom"; +import { useHistory } from "react-router-dom"; import { useDebounce } from "use-debounce"; import Autocomplete from "@material-ui/lab/Autocomplete"; import Paper from "@material-ui/core/Paper"; @@ -36,6 +36,7 @@ const SearchInput = (): JSX.Element => { } `; + const history = useHistory(); const [open, setOpen] = React.useState(false); const [host, setHost] = React.useState(""); const [selectedCommunity, setSelectedCommunity] = React.useState(null); @@ -99,46 +100,42 @@ const SearchInput = (): JSX.Element => { const loadingText = showSpinner ? "Searching..." : "No communities found"; if (selectedCommunity) { - return ( - - ); - } else { - return ( - - setOpen(true)} - onClose={onOpen} - getOptionLabel={getOptionLabel} - filterOptions={optionsFilter} - options={options} - loading={openLoader} - loadingText={loadingText} - onChange={onSelectChange} - onInputChange={onInputChange} - renderInput={(params) => ( - - {showSpinner ? : null} - {params.InputProps.endAdornment} - - } - /> - )} - /> - - ); + history.push(`/instances/${selectedCommunity.host}/communities/${selectedCommunity.id}/posts`); } + + return ( + + setOpen(true)} + onClose={onOpen} + getOptionLabel={getOptionLabel} + filterOptions={optionsFilter} + options={options} + loading={openLoader} + loadingText={loadingText} + onChange={onSelectChange} + onInputChange={onInputChange} + renderInput={(params) => ( + + {showSpinner ? : null} + {params.InputProps.endAdornment} + + } + /> + )} + /> + + ); }; export default SearchInput; diff --git a/packages/frontend/src/pages/PublicUserProfile.tsx b/packages/frontend/src/pages/PublicUserProfile.tsx index 8c753fc6..94848b93 100644 --- a/packages/frontend/src/pages/PublicUserProfile.tsx +++ b/packages/frontend/src/pages/PublicUserProfile.tsx @@ -3,20 +3,107 @@ import { Container, Grid } from "@material-ui/core"; import UserInfoCard from "./../components/UserInfoCard"; import { useParams } from "react-router-dom"; import PostPreview from "../components/PostPreview"; +import { gql, useQuery } from "@apollo/client"; +import LoadingPage from "../components/LoadingPage"; interface PublicUserProfileParams { username: string; } const PublicUserProfile = (): JSX.Element => { + const GET_POSTS = gql` + query($community: String!, $host: String!) { + getPosts(community: { id: $community, host: $host }) { + id + title + host + author { + id + } + } + } + `; + + const general = useQuery(GET_POSTS, { + variables: { + community: "general", + host: window.location.host, + }, + }); + + const all = useQuery(GET_POSTS, { + variables: { + community: "all", + host: window.location.host, + }, + }); + + const elections = useQuery(GET_POSTS, { + variables: { + community: "elections", + host: window.location.host, + }, + }); + const { username } = useParams(); - // hardcoded js123 as the only valid user for now - needs changing - const name = username === "js123" ? "John Smith" : username; + const name = username; + + if (elections.error || all.error || general.error) + return

Error!

; + if (elections.loading || all.loading || general.loading) return ; + return ( - + {elections.data.getPosts.map((post: any) => { + if (post.title && post.author.id === username) { + return ( + + ); + } else { + return null; + } + })} + {general.data.getPosts.map((post: any) => { + if (post.title && post.author.id === username) { + return ( + + ); + } else { + return null; + } + })} + {all.data.getPosts.map((post: any) => { + if (post.title && post.author.id === username) { + return ( + + ); + } else { + return null; + } + })}