From 545de7bcc3ac5e22da9761d7fbd0f85ce940415e Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 21 Jan 2021 20:00:29 +0800 Subject: chore: Fix crlf. --- FrontEnd/src/app/http/search.ts | 96 ++++++------- FrontEnd/src/app/views/search/index.tsx | 234 ++++++++++++++++---------------- 2 files changed, 165 insertions(+), 165 deletions(-) diff --git a/FrontEnd/src/app/http/search.ts b/FrontEnd/src/app/http/search.ts index 8ff1c499..2da9295e 100644 --- a/FrontEnd/src/app/http/search.ts +++ b/FrontEnd/src/app/http/search.ts @@ -1,48 +1,48 @@ -import { - apiBaseUrl, - axios, - convertToNetworkError, - extractResponseData, -} from "./common"; -import { - HttpTimelineInfo, - processRawTimelineInfo, - RawHttpTimelineInfo, -} from "./timeline"; -import { HttpUser } from "./user"; - -export interface IHttpSearchClient { - searchTimelines(query: string): Promise; - searchUsers(query: string): Promise; -} - -export class HttpSearchClient implements IHttpSearchClient { - searchTimelines(query: string): Promise { - return axios - .get(`${apiBaseUrl}/search/timelines?q=${query}`) - .then(extractResponseData) - .then((ts) => ts.map(processRawTimelineInfo)) - .catch(convertToNetworkError); - } - - searchUsers(query: string): Promise { - return axios - .get(`${apiBaseUrl}/search/users?q=${query}`) - .then(extractResponseData) - .catch(convertToNetworkError); - } -} - -let client: IHttpSearchClient = new HttpSearchClient(); - -export function getHttpSearchClient(): IHttpSearchClient { - return client; -} - -export function setHttpSearchClient( - newClient: IHttpSearchClient -): IHttpSearchClient { - const old = client; - client = newClient; - return old; -} +import { + apiBaseUrl, + axios, + convertToNetworkError, + extractResponseData, +} from "./common"; +import { + HttpTimelineInfo, + processRawTimelineInfo, + RawHttpTimelineInfo, +} from "./timeline"; +import { HttpUser } from "./user"; + +export interface IHttpSearchClient { + searchTimelines(query: string): Promise; + searchUsers(query: string): Promise; +} + +export class HttpSearchClient implements IHttpSearchClient { + searchTimelines(query: string): Promise { + return axios + .get(`${apiBaseUrl}/search/timelines?q=${query}`) + .then(extractResponseData) + .then((ts) => ts.map(processRawTimelineInfo)) + .catch(convertToNetworkError); + } + + searchUsers(query: string): Promise { + return axios + .get(`${apiBaseUrl}/search/users?q=${query}`) + .then(extractResponseData) + .catch(convertToNetworkError); + } +} + +let client: IHttpSearchClient = new HttpSearchClient(); + +export function getHttpSearchClient(): IHttpSearchClient { + return client; +} + +export function setHttpSearchClient( + newClient: IHttpSearchClient +): IHttpSearchClient { + const old = client; + client = newClient; + return old; +} diff --git a/FrontEnd/src/app/views/search/index.tsx b/FrontEnd/src/app/views/search/index.tsx index d7b1ac53..3cd3da58 100644 --- a/FrontEnd/src/app/views/search/index.tsx +++ b/FrontEnd/src/app/views/search/index.tsx @@ -1,117 +1,117 @@ -import { TimelineInfo } from "@/services/timeline"; -import React from "react"; -import { Container, Row } from "react-bootstrap"; -import { useHistory, useLocation } from "react-router"; -import { Link } from "react-router-dom"; - -import { getHttpSearchClient } from "@/http/search"; - -import SearchInput from "../common/SearchInput"; -import { HttpNetworkError } from "@/http/common"; -import { useAvatar } from "@/services/user"; -import BlobImage from "../common/BlobImage"; - -const TimelineSearchResultItemView: React.FC<{ timeline: TimelineInfo }> = ({ - timeline, -}) => { - const link = timeline.name.startsWith("@") - ? `users/${timeline.owner.username}` - : `timelines/${timeline.name}`; - - const avatar = useAvatar(timeline.owner.username); - - return ( -
-

- - {timeline.title} - {timeline.name} - -

-
- - {timeline.owner.nickname} - - @{timeline.owner.username} - -
-
- ); -}; - -const SearchPage: React.FC = () => { - const history = useHistory(); - const location = useLocation(); - const searchParams = new URLSearchParams(location.search); - const queryParam = searchParams.get("q"); - - const [searchText, setSearchText] = React.useState(""); - const [state, setState] = React.useState< - TimelineInfo[] | "init" | "loading" | "network-error" | "error" - >("init"); - - React.useEffect(() => { - if (queryParam != null && queryParam.length > 0) { - setSearchText(queryParam); - setState("loading"); - void getHttpSearchClient() - .searchTimelines(queryParam) - .then( - (ts) => { - setState(ts); - }, - (e) => { - if (e instanceof HttpNetworkError) { - setState("network-error"); - } else { - setState("error"); - } - } - ); - } - }, [queryParam]); - - return ( - - - { - if (searchText.length > 0) { - history.push(`/search?q=${searchText}`); - } - }} - /> - - {(() => { - switch (state) { - case "init": { - return "Input something and search!"; - } - case "loading": { - return "Loading!"; - } - case "network-error": { - return "Network error!"; - } - case "error": { - return "Unknown error!"; - } - default: { - return state.map((t) => ( - - )); - } - } - })()} - - ); -}; - -export default SearchPage; +import { TimelineInfo } from "@/services/timeline"; +import React from "react"; +import { Container, Row } from "react-bootstrap"; +import { useHistory, useLocation } from "react-router"; +import { Link } from "react-router-dom"; + +import { getHttpSearchClient } from "@/http/search"; + +import SearchInput from "../common/SearchInput"; +import { HttpNetworkError } from "@/http/common"; +import { useAvatar } from "@/services/user"; +import BlobImage from "../common/BlobImage"; + +const TimelineSearchResultItemView: React.FC<{ timeline: TimelineInfo }> = ({ + timeline, +}) => { + const link = timeline.name.startsWith("@") + ? `users/${timeline.owner.username}` + : `timelines/${timeline.name}`; + + const avatar = useAvatar(timeline.owner.username); + + return ( +
+

+ + {timeline.title} + {timeline.name} + +

+
+ + {timeline.owner.nickname} + + @{timeline.owner.username} + +
+
+ ); +}; + +const SearchPage: React.FC = () => { + const history = useHistory(); + const location = useLocation(); + const searchParams = new URLSearchParams(location.search); + const queryParam = searchParams.get("q"); + + const [searchText, setSearchText] = React.useState(""); + const [state, setState] = React.useState< + TimelineInfo[] | "init" | "loading" | "network-error" | "error" + >("init"); + + React.useEffect(() => { + if (queryParam != null && queryParam.length > 0) { + setSearchText(queryParam); + setState("loading"); + void getHttpSearchClient() + .searchTimelines(queryParam) + .then( + (ts) => { + setState(ts); + }, + (e) => { + if (e instanceof HttpNetworkError) { + setState("network-error"); + } else { + setState("error"); + } + } + ); + } + }, [queryParam]); + + return ( + + + { + if (searchText.length > 0) { + history.push(`/search?q=${searchText}`); + } + }} + /> + + {(() => { + switch (state) { + case "init": { + return "Input something and search!"; + } + case "loading": { + return "Loading!"; + } + case "network-error": { + return "Network error!"; + } + case "error": { + return "Unknown error!"; + } + default: { + return state.map((t) => ( + + )); + } + } + })()} + + ); +}; + +export default SearchPage; -- cgit v1.2.3