Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #214 from hyperspacedev/develop-1.1.3-fix-search
Browse files Browse the repository at this point in the history
v1.1.3 - Fix search page results
  • Loading branch information
alicerunsonfedora authored Jun 23, 2020
2 parents a98a8f0 + a34ab59 commit f51e00f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 54 deletions.
74 changes: 51 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hyperspace",
"productName": "Hyperspace Desktop",
"version": "1.1.2",
"version": "1.1.3",
"description": "A beautiful, fluffy client for the fediverse",
"author": "Marquis Kurt <hyperspacedev@marquiskurt.net>",
"repository": "https://github.com/hyperspacedev/hyperspace.git",
Expand All @@ -19,14 +19,14 @@
"@types/react-router-dom": "^4.3.5",
"@types/react-swipeable-views": "latest",
"axios": "^0.19.2",
"electron": "^9.0.4",
"electron": "^9.0.5",
"electron-builder": "^22.7.0",
"emoji-mart": "^2.11.2",
"file-dialog": "^0.0.7",
"material-ui-pickers": "^2.2.4",
"mdi-material-ui": "^5.27.0",
"megalodon": "^0.6.4",
"moment": "^2.26.0",
"moment": "^2.27.0",
"notistack": "^0.5.1",
"prettier": "^1.19.1",
"query-string": "^6.13.1",
Expand Down
2 changes: 1 addition & 1 deletion public/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1.2",
"version": "1.1.3",
"location": "https://hyperspaceapp.herokuapp.com",
"branding": {
"name": "Hyperspace",
Expand Down
10 changes: 6 additions & 4 deletions src/components/AppLayout/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ import { getConfig, getUserDefaultBool } from "../../utilities/settings";
import {
isDesktopApp,
isDarwinApp,
getElectronApp
getElectronApp,
linkablePath
} from "../../utilities/desktop";
import { Config } from "../../types/Config";
import {
Expand Down Expand Up @@ -326,9 +327,10 @@ export class AppLayout extends Component<any, IAppLayoutState> {
searchForQuery(what: string) {
what = what.replace(/^#/g, "tag:");
// console.log(what);
window.location.href = isDesktopApp()
? "hyperspace://hyperspace/app/index.html#/search?query=" + what
: "/#/search?query=" + what;
window.location.href = linkablePath("/#/search?query=" + what);
// window.location.href = isDesktopApp()
// ? "hyperspace://hyperspace/app/index.html#/search?query=" + what
// : "/#/search?query=" + what;
}

/**
Expand Down
34 changes: 11 additions & 23 deletions src/pages/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import PersonAddIcon from "@material-ui/icons/PersonAdd";
import { styles } from "./PageLayout.styles";
import { LinkableIconButton, LinkableAvatar } from "../interfaces/overrides";
import Mastodon from "megalodon";
import { parse as parseParams, ParsedQuery } from "query-string";
import { parse as parseParams } from "query-string";
import { Results } from "../types/Search";
import { withSnackbar } from "notistack";
import Post from "../components/Post";
Expand Down Expand Up @@ -84,35 +84,23 @@ class SearchPage extends Component<any, ISearchPageState> {
}
}

runQueryCheck(newLocation?: string): ParsedQuery {
let searchParams = "";
if (newLocation !== undefined && typeof newLocation === "string") {
searchParams = newLocation.replace("#/search", "");
} else {
searchParams = this.props.location.hash.replace("#/search", "");
}
return parseParams(searchParams);
}

getQueryAndType(props: any) {
let newSearch = this.runQueryCheck(props.location);
let query: string | string[];
const { search }: { search: string } = props.location;
let newSearch = parseParams(search);
let query: string | string[] = "";
let type;

if (newSearch.query) {
if (newSearch.query.toString().startsWith("tag:")) {
if (search.includes("tag:")) {
type = "tag";
query = newSearch.query.toString().replace("tag:", "");
} else {
query = newSearch.query;
}
} else {
query = "";
query = newSearch.query.toString().replace("tag:", "");
}

if (newSearch.type && newSearch.type !== undefined) {
type = newSearch.type;
}

return {
query: query,
type: type
Expand Down Expand Up @@ -155,14 +143,11 @@ class SearchPage extends Component<any, ISearchPageState> {
let tagResults: [Status] = resp.data;
this.setState({
tagResults,
viewDidLoad: true,
viewIsLoading: false
viewDidLoad: true
});
// console.log(this.state.tagResults);
})
.catch((err: Error) => {
this.setState({
viewIsLoading: false,
viewDidError: true,
viewDidErrorCode: err.message
});
Expand All @@ -171,6 +156,9 @@ class SearchPage extends Component<any, ISearchPageState> {
`Couldn't search for posts with tag ${this.state.query}: ${err.name}`,
{ variant: "error" }
);
})
.finally(() => {
this.setState({ viewIsLoading: false });
});
}

Expand Down

0 comments on commit f51e00f

Please sign in to comment.