import { axios, apiBaseUrl, convertToNetworkError, extractResponseData, } from "./common"; import { HttpTimelineInfo, processRawTimelineInfo, RawHttpTimelineInfo, } from "./timeline"; export interface HttpHighlightMoveRequest { timeline: string; newPosition: number; } export interface IHttpHighlightClient { list(): Promise; put(timeline: string): Promise; delete(timeline: string): Promise; move(req: HttpHighlightMoveRequest): Promise; } export class HttpHighlightClient implements IHttpHighlightClient { list(): Promise { return axios .get(`${apiBaseUrl}/highlights`) .then(extractResponseData) .then((list) => list.map(processRawTimelineInfo)) .catch(convertToNetworkError); } put(timeline: string): Promise { return axios .put(`${apiBaseUrl}/highlights/${timeline}`) .catch(convertToNetworkError) .then(); } delete(timeline: string): Promise { return axios .delete(`${apiBaseUrl}/highlights/${timeline}`) .catch(convertToNetworkError) .then(); } move(req: HttpHighlightMoveRequest): Promise { return axios .post(`${apiBaseUrl}/highlightop/move`, 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; }