diff --git a/src/helpers/ComunicUsersHelper.ts b/src/helpers/ComunicUsersHelper.ts index e5e3650..8b20339 100644 --- a/src/helpers/ComunicUsersHelper.ts +++ b/src/helpers/ComunicUsersHelper.ts @@ -14,6 +14,27 @@ export interface SearchResult { account_image: string; } +export interface ComunicUser { + id: number; + first_name: string; + last_name: string; + email: string; + account_creation_time: number; + last_activity: number; + page_visibilty: "private" | "public" | "open"; + directory?: string; + account_image: string; + friend_list_public: string; + is_email_public: boolean; + personal_website?: string; + public_note?: string; + location?: string; + block_commments: boolean; + allow_posts_from_friends: boolean; + allow_mails: boolean; + lang: string; +} + export class ComunicUsersHelper { /** * Search for Comunic users @@ -30,4 +51,13 @@ export class ComunicUsersHelper { email: email, }); } + + /** + * Get information about a single user + */ + static async GetSingle(id: number): Promise { + return await serverRequest("users/info", { + user_id: id, + }); + } } diff --git a/src/ui/routes/ComunicUserRoute.tsx b/src/ui/routes/ComunicUserRoute.tsx new file mode 100644 index 0000000..d35b80c --- /dev/null +++ b/src/ui/routes/ComunicUserRoute.tsx @@ -0,0 +1,44 @@ +import React from "react"; +import { + ComunicUser, + ComunicUsersHelper, +} from "../../helpers/ComunicUsersHelper"; +import { AsyncWidget } from "../widgets/AsyncWidget"; + +/** + * Comunic user management route + * + * @author Pierre Hubert + */ +export class ComunicUserRoute extends React.Component< + { userID: number }, + { user: ComunicUser } +> { + constructor(p: any) { + super(p); + + this.load = this.load.bind(this); + this.build = this.build.bind(this); + } + + async load() { + const user = await ComunicUsersHelper.GetSingle(this.props.userID); + + this.setState({ user: user }); + } + + build() { + return

Go for {this.state.user.first_name}

; + } + + render() { + return ( + + ); + } +} diff --git a/src/ui/routes/MainRoute.tsx b/src/ui/routes/MainRoute.tsx index 83e2682..43922aa 100644 --- a/src/ui/routes/MainRoute.tsx +++ b/src/ui/routes/MainRoute.tsx @@ -27,12 +27,14 @@ import { Route, Switch, useHistory, + useParams, useRouteMatch, } from "react-router-dom"; import { AccountHelper, AdminAccountRole } from "../../helpers/AccountHelper"; import { AccountLogsRoute } from "./AccountLogsRoute"; import { AccountSettingsRoute } from "./AccountSettingsRoute"; import { AccountsListRoute } from "./AccountsListRoute"; +import { ComunicUserRoute } from "./ComunicUserRoute"; import { HomeRoute } from "./HomeRoute"; import { NotFoundRoute } from "./NotFoundRoute"; import { SearchComunicUsersRoute } from "./SearchComunicUsersRoute"; @@ -221,6 +223,10 @@ export function MainRoute() { + + + + @@ -244,3 +250,9 @@ export function MainRoute() { ); } + +function ComunicUserRouteProxy() { + let { id } = useParams<{ id: string }>(); + + return ; +} diff --git a/src/ui/routes/SearchComunicUsersRoute.tsx b/src/ui/routes/SearchComunicUsersRoute.tsx index 2bd3420..8825c6e 100644 --- a/src/ui/routes/SearchComunicUsersRoute.tsx +++ b/src/ui/routes/SearchComunicUsersRoute.tsx @@ -4,10 +4,19 @@ * @author Pierre Hubert */ -import { Avatar, Grid, Paper, TextField, Typography } from "@material-ui/core"; +import { + Avatar, + Grid, + ListItem, + Paper, + TextField, + Typography, +} from "@material-ui/core"; import React from "react"; +import { useHistory } from "react-router-dom"; import { ComunicUsersHelper, + SearchResult, SearchResult as UserSearchResult, } from "../../helpers/ComunicUsersHelper"; import { AsyncWidget } from "../widgets/AsyncWidget"; @@ -117,25 +126,36 @@ export class SearchComunicUsersRoute extends React.Component< return ( {this.state.results.map((result) => { - return ( - - - - {result.first_name.substring(0, 1)} - - - - - {result.first_name} {result.last_name} - - - {result.email} - - - - ); + return ; })} ); } } + +function ResultItem(p: { user: SearchResult }) { + const history = useHistory(); + const openButton = () => { + history.push("/user/" + p.user.id); + }; + + return ( + + + + + {p.user.first_name.substring(0, 1)} + + + + + {p.user.first_name} {p.user.last_name} + + + {p.user.email} + + + + + ); +}