diff --git a/src/server/handlers/catch-all-handler.tsx b/src/server/handlers/catch-all-handler.tsx index 6b214944..c599e465 100644 --- a/src/server/handlers/catch-all-handler.tsx +++ b/src/server/handlers/catch-all-handler.tsx @@ -90,7 +90,7 @@ export default async (req: Request, res: Response) => { } const error = Object.values(routeData).find( - res => res.state === "failed" && res.msg !== "couldnt_find_object" // TODO: find a better way of handling errors + res => res.state === "failed" ) as FailedRequestState | undefined; // Redirect to the 404 if there's an API error diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index e9aaaa1b..dca621eb 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -38,8 +38,6 @@ import { ListingType, PersonView, PostView, - ResolveObject, - ResolveObjectResponse, Search as SearchForm, SearchResponse, SearchType, @@ -75,14 +73,12 @@ type SearchData = RouteDataResponse<{ listCommunitiesResponse: ListCommunitiesResponse; creatorDetailsResponse: GetPersonDetailsResponse; searchResponse: SearchResponse; - resolveObjectResponse: ResolveObjectResponse; }>; type FilterType = "creator" | "community"; interface SearchState { searchRes: RequestState; - resolveObjectRes: RequestState; creatorDetailsRes: RequestState; communitiesRes: RequestState; communityRes: RequestState; @@ -239,7 +235,6 @@ export class Search extends Component { private isoData = setIsoData(this.context); state: SearchState = { - resolveObjectRes: { state: "empty" }, creatorDetailsRes: { state: "empty" }, communitiesRes: { state: "empty" }, communityRes: { state: "empty" }, @@ -275,7 +270,6 @@ export class Search extends Component { communityResponse: communityRes, creatorDetailsResponse: creatorDetailsRes, listCommunitiesResponse: communitiesRes, - resolveObjectResponse: resolveObjectRes, searchResponse: searchRes, } = this.isoData.routeData; @@ -320,13 +314,6 @@ export class Search extends Component { searchRes, }; } - - if (resolveObjectRes?.state === "success") { - this.state = { - ...this.state, - resolveObjectRes, - }; - } } } } @@ -406,9 +393,6 @@ export class Search extends Component { const query = getSearchQueryFromQuery(q); let searchResponse: RequestState = { state: "empty" }; - let resolveObjectResponse: RequestState = { - state: "empty", - }; if (query) { const form: SearchForm = { @@ -425,21 +409,6 @@ export class Search extends Component { if (query !== "") { searchResponse = await client.search(form); - if (auth) { - const resolveObjectForm: ResolveObject = { - q: query, - auth, - }; - resolveObjectResponse = await HttpService.silent_client.resolveObject( - resolveObjectForm - ); - - // If we return this object with a state of failed, the catch-all-handler will redirect - // to an error page, so we ignore it by covering up the error with the empty state. - if (resolveObjectResponse.state === "failed") { - resolveObjectResponse = { state: "empty" }; - } - } } } @@ -447,7 +416,6 @@ export class Search extends Component { communityResponse, creatorDetailsResponse, listCommunitiesResponse, - resolveObjectResponse, searchResponse, }; } @@ -609,28 +577,7 @@ export class Search extends Component { buildCombined(): Combined[] { const combined: Combined[] = []; - const { - resolveObjectRes: resolveObjectResponse, - searchRes: searchResponse, - } = this.state; - - // Push the possible resolve / federated objects first - if (resolveObjectResponse.state == "success") { - const { comment, post, community, person } = resolveObjectResponse.data; - - if (comment) { - combined.push(commentViewToCombined(comment)); - } - if (post) { - combined.push(postViewToCombined(post)); - } - if (community) { - combined.push(communityViewToCombined(community)); - } - if (person) { - combined.push(personViewSafeToCombined(person)); - } - } + const { searchRes: searchResponse } = this.state; // Push the search results if (searchResponse.state === "success") { @@ -757,21 +704,10 @@ export class Search extends Component { } get comments() { - const { - searchRes: searchResponse, - resolveObjectRes: resolveObjectResponse, - siteRes, - } = this.state; + const { searchRes: searchResponse, siteRes } = this.state; const comments = searchResponse.state === "success" ? searchResponse.data.comments : []; - if ( - resolveObjectResponse.state === "success" && - resolveObjectResponse.data.comment - ) { - comments.unshift(resolveObjectResponse.data.comment); - } - return ( { } get posts() { - const { - searchRes: searchResponse, - resolveObjectRes: resolveObjectResponse, - siteRes, - } = this.state; + const { searchRes: searchResponse, siteRes } = this.state; const posts = searchResponse.state === "success" ? searchResponse.data.posts : []; - if ( - resolveObjectResponse.state === "success" && - resolveObjectResponse.data.post - ) { - posts.unshift(resolveObjectResponse.data.post); - } - return ( <> {posts.map(pv => ( @@ -861,20 +786,10 @@ export class Search extends Component { } get communities() { - const { - searchRes: searchResponse, - resolveObjectRes: resolveObjectResponse, - } = this.state; + const { searchRes: searchResponse } = this.state; const communities = searchResponse.state === "success" ? searchResponse.data.communities : []; - if ( - resolveObjectResponse.state === "success" && - resolveObjectResponse.data.community - ) { - communities.unshift(resolveObjectResponse.data.community); - } - return ( <> {communities.map(cv => ( @@ -887,20 +802,10 @@ export class Search extends Component { } get users() { - const { - searchRes: searchResponse, - resolveObjectRes: resolveObjectResponse, - } = this.state; + const { searchRes: searchResponse } = this.state; const users = searchResponse.state === "success" ? searchResponse.data.users : []; - if ( - resolveObjectResponse.state === "success" && - resolveObjectResponse.data.person - ) { - users.unshift(resolveObjectResponse.data.person); - } - return ( <> {users.map(pvs => ( @@ -913,27 +818,14 @@ export class Search extends Component { } get resultsCount(): number { - const { searchRes: r, resolveObjectRes: resolveRes } = this.state; + const { searchRes: r } = this.state; - const searchCount = - r.state === "success" - ? r.data.posts.length + + return r.state === "success" + ? r.data.posts.length + r.data.comments.length + r.data.communities.length + r.data.users.length - : 0; - - const resObjCount = - resolveRes.state === "success" - ? resolveRes.data.post || - resolveRes.data.person || - resolveRes.data.community || - resolveRes.data.comment - ? 1 - : 0 - : 0; - - return resObjCount + searchCount; + : 0; } async search() { @@ -959,16 +851,6 @@ export class Search extends Component { }); window.scrollTo(0, 0); restoreScrollPosition(this.context); - - if (auth) { - this.setState({ resolveObjectRes: { state: "loading" } }); - this.setState({ - resolveObjectRes: await HttpService.silent_client.resolveObject({ - q, - auth, - }), - }); - } } }