aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/app/http/highlight.ts
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-12-19 21:17:05 +0800
committercrupest <crupest@outlook.com>2020-12-19 21:17:05 +0800
commit0751d07c55dd26a8bc825e695bfa6c6442857b0b (patch)
treecfb2e847d6f3c95b0a297777b12d0214dc29ada1 /FrontEnd/src/app/http/highlight.ts
parent328ec15a1d4d927c53c4b9da4219d58ca12a2f20 (diff)
downloadtimeline-0751d07c55dd26a8bc825e695bfa6c6442857b0b.tar.gz
timeline-0751d07c55dd26a8bc825e695bfa6c6442857b0b.tar.bz2
timeline-0751d07c55dd26a8bc825e695bfa6c6442857b0b.zip
feat: Add highlight timeline http client.
Diffstat (limited to 'FrontEnd/src/app/http/highlight.ts')
-rw-r--r--FrontEnd/src/app/http/highlight.ts70
1 files changed, 70 insertions, 0 deletions
diff --git a/FrontEnd/src/app/http/highlight.ts b/FrontEnd/src/app/http/highlight.ts
new file mode 100644
index 00000000..1f226c19
--- /dev/null
+++ b/FrontEnd/src/app/http/highlight.ts
@@ -0,0 +1,70 @@
+import axios from "axios";
+
+import {
+ apiBaseUrl,
+ convertToNetworkError,
+ extractResponseData,
+} from "./common";
+
+import {
+ HttpTimelineInfo,
+ processRawTimelineInfo,
+ RawHttpTimelineInfo,
+} from "./timeline";
+
+export interface HttpHighlightMoveRequest {
+ timeline: string;
+ newPosition: number;
+}
+
+export interface IHttpHighlightClient {
+ list(): Promise<HttpTimelineInfo[]>;
+ put(timeline: string, token: string): Promise<void>;
+ delete(timeline: string, token: string): Promise<void>;
+ move(req: HttpHighlightMoveRequest, token: string): Promise<void>;
+}
+
+export class HttpHighlightClient implements IHttpHighlightClient {
+ list(): Promise<HttpTimelineInfo[]> {
+ return axios
+ .get<RawHttpTimelineInfo[]>(`${apiBaseUrl}/highlights`)
+ .then(extractResponseData)
+ .then((list) => list.map(processRawTimelineInfo))
+ .catch(convertToNetworkError);
+ }
+
+ put(timeline: string, token: string): Promise<void> {
+ return axios
+ .put(`${apiBaseUrl}/highlights/${timeline}?token=${token}`)
+ .catch(convertToNetworkError)
+ .then();
+ }
+
+ delete(timeline: string, token: string): Promise<void> {
+ return axios
+ .delete(`${apiBaseUrl}/highlights/${timeline}?token=${token}`)
+ .catch(convertToNetworkError)
+ .then();
+ }
+
+ move(req: HttpHighlightMoveRequest, token: string): Promise<void> {
+ return axios
+ .post(`${apiBaseUrl}/highlightop/move?token=${token}`, req)
+ .catch(convertToNetworkError)
+ .then();
+ }
+}
+
+let client: IHttpHighlightClient = new HttpHighlightClient();
+
+export function getHttpHighlightClient(): IHttpHighlightClient {
+ return client;
+}
+
+export function setHttpHighlightClient(
+ newClient: IHttpHighlightClient
+): IHttpHighlightClient {
+ const old = client;
+ client = newClient;
+ return old;
+}