diff options
author | crupest <crupest@outlook.com> | 2021-01-03 19:38:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-03 19:38:05 +0800 |
commit | 418d631528fdb581a384068719e9af5dbaa66740 (patch) | |
tree | 42e2c0396a16cb5fbaaae665a238a8a031bef7f0 /FrontEnd/src/app/http/highlight.ts | |
parent | 4b3ae3edd9e8aceac5ff26ef137d2a8d686fe305 (diff) | |
parent | 8af803cb0da57af1355ad28cd056cb5dcf6d6915 (diff) | |
download | timeline-418d631528fdb581a384068719e9af5dbaa66740.tar.gz timeline-418d631528fdb581a384068719e9af5dbaa66740.tar.bz2 timeline-418d631528fdb581a384068719e9af5dbaa66740.zip |
Merge pull request #197 from crupest/front-dev
Front: Highlight and bookmark timeline and new home page.
Diffstat (limited to 'FrontEnd/src/app/http/highlight.ts')
-rw-r--r-- | FrontEnd/src/app/http/highlight.ts | 70 |
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; +} |