From c8bd19aacf9059f740df4f6fa9890127c20c1f6d Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 13 Feb 2021 21:23:30 +0800 Subject: ... --- FrontEnd/src/app/App.tsx | 6 +- FrontEnd/src/app/http/timeline.ts | 33 +++++- FrontEnd/src/app/http/user.ts | 6 +- FrontEnd/src/app/utilities/url.ts | 3 +- FrontEnd/src/app/views/common/AppBar.tsx | 10 +- FrontEnd/src/app/views/common/user/UserAvatar.tsx | 13 ++- FrontEnd/src/app/views/home/TimelineBoard.tsx | 12 +- .../src/app/views/timeline-common/Timeline.tsx | 10 +- .../timeline-common/TimelinePageTemplateUI.tsx | 10 +- .../timeline-common/TimelinePostContentView.tsx | 114 ++++++++++++++++++ .../app/views/timeline-common/TimelinePostEdit.tsx | 129 +++++++++++---------- .../views/timeline-common/TimelinePostListView.tsx | 4 +- .../app/views/timeline-common/TimelinePostView.tsx | 26 ++++- 13 files changed, 274 insertions(+), 102 deletions(-) create mode 100644 FrontEnd/src/app/views/timeline-common/TimelinePostContentView.tsx (limited to 'FrontEnd/src') diff --git a/FrontEnd/src/app/App.tsx b/FrontEnd/src/app/App.tsx index 0a7513e4..fb57bd1e 100644 --- a/FrontEnd/src/app/App.tsx +++ b/FrontEnd/src/app/App.tsx @@ -12,7 +12,6 @@ import TimelinePage from "./views/timeline"; import Search from "./views/search"; import AlertHost from "./views/common/alert/AlertHost"; -import { dataStorage } from "./services/common"; import { userService, useRawUser } from "./services/user"; const NoMatch: React.FC = () => { @@ -24,16 +23,13 @@ const LazyAdmin = React.lazy( ); const App: React.FC = () => { - const [loading, setLoading] = React.useState(true); - const user = useRawUser(); React.useEffect(() => { void userService.checkLoginState(); - void dataStorage.ready().then(() => setLoading(false)); }, []); - if (user === undefined || loading) { + if (user === undefined) { return ; } else { return ( diff --git a/FrontEnd/src/app/http/timeline.ts b/FrontEnd/src/app/http/timeline.ts index 375a2325..50af259e 100644 --- a/FrontEnd/src/app/http/timeline.ts +++ b/FrontEnd/src/app/http/timeline.ts @@ -7,6 +7,7 @@ import { apiBaseUrl, extractResponseData, convertToIfErrorCodeIs, + getHttpToken, } from "./common"; import { HttpUser } from "./user"; @@ -50,20 +51,22 @@ export interface HttpTimelinePostInfo { id: number; time: string; author: HttpUser; - dataList: HttpTimelinePostDataDigest; + dataList: HttpTimelinePostDataDigest[]; color: string; lastUpdated: string; timelineName: string; editable: boolean; } +export interface HttpTimelinePostPostRequestData { + contentType: string; + data: string; +} + export interface HttpTimelinePostPostRequest { time?: string; color?: string; - dataList: { - contentType: string; - data: string; - }[]; + dataList: HttpTimelinePostPostRequestData[]; } export interface HttpTimelinePatchRequest { @@ -91,6 +94,8 @@ export interface IHttpTimelineClient { memberPut(timelineName: string, username: string): Promise; memberDelete(timelineName: string, username: string): Promise; listPost(timelineName: string): Promise; + generatePostDataUrl(timelineName: string, postId: number): string; + getPostDataAsString(timelineName: string, postId: number): Promise; postPost( timelineName: string, req: HttpTimelinePostPostRequest @@ -153,6 +158,24 @@ export class HttpTimelineClient implements IHttpTimelineClient { .then(extractResponseData); } + generatePostDataUrl(timelineName: string, postId: number): string { + return applyQueryParameters( + `${apiBaseUrl}/timelines/${timelineName}/posts/${postId}/data`, + { token: getHttpToken() } + ); + } + + getPostDataAsString(timelineName: string, postId: number): Promise { + return axios + .get( + `${apiBaseUrl}/timelines/${timelineName}/posts/${postId}/data`, + { + responseType: "text", + } + ) + .then(extractResponseData); + } + postPost( timelineName: string, req: HttpTimelinePostPostRequest diff --git a/FrontEnd/src/app/http/user.ts b/FrontEnd/src/app/http/user.ts index c6a567d3..dcb222bf 100644 --- a/FrontEnd/src/app/http/user.ts +++ b/FrontEnd/src/app/http/user.ts @@ -61,7 +61,7 @@ export interface IHttpUserClient { get(username: string): Promise; patch(username: string, req: HttpUserPatchRequest): Promise; delete(username: string): Promise; - // return etag + generateAvatarUrl(username: string): string; putAvatar(username: string, data: Blob): Promise; changePassword(req: HttpChangePasswordRequest): Promise; putUserPermission( @@ -100,6 +100,10 @@ export class HttpUserClient implements IHttpUserClient { return axios.delete(`${apiBaseUrl}/users/${username}`).then(); } + generateAvatarUrl(username: string): string { + return `${apiBaseUrl}/users/${username}/avatar`; + } + putAvatar(username: string, data: Blob): Promise { return axios .put(`${apiBaseUrl}/users/${username}/avatar`, data, { diff --git a/FrontEnd/src/app/utilities/url.ts b/FrontEnd/src/app/utilities/url.ts index 21ad6304..4f2a6ecd 100644 --- a/FrontEnd/src/app/utilities/url.ts +++ b/FrontEnd/src/app/utilities/url.ts @@ -4,7 +4,8 @@ export function applyQueryParameters(url: string, query: T): string { const params = new URLSearchParams(); for (const [key, value] of Object.entries(query)) { - if (typeof value === "string") params.set(key, value); + if (value == null) void 0; + else if (typeof value === "string") params.set(key, value); else if (typeof value === "number") params.set(key, String(value)); else if (typeof value === "boolean") params.set(key, String(value)); else if (value instanceof Date) params.set(key, value.toISOString()); diff --git a/FrontEnd/src/app/views/common/AppBar.tsx b/FrontEnd/src/app/views/common/AppBar.tsx index d0e39f98..e682a308 100644 --- a/FrontEnd/src/app/views/common/AppBar.tsx +++ b/FrontEnd/src/app/views/common/AppBar.tsx @@ -4,14 +4,13 @@ import { LinkContainer } from "react-router-bootstrap"; import { Navbar, Nav } from "react-bootstrap"; import { NavLink } from "react-router-dom"; -import { useUser, useAvatar } from "@/services/user"; +import { useUser } from "@/services/user"; import TimelineLogo from "./TimelineLogo"; -import BlobImage from "./BlobImage"; +import UserAvatar from "./user/UserAvatar"; const AppBar: React.FC = (_) => { const user = useUser(); - const avatar = useAvatar(user?.username); const { t } = useTranslation(); @@ -70,10 +69,9 @@ const AppBar: React.FC = (_) => {