Skip to content

Instantly share code, notes, and snippets.

@tianhaoz95
Last active May 10, 2021 01:04
Show Gist options
  • Select an option

  • Save tianhaoz95/b978ef584df0d66515f05f00595c16be to your computer and use it in GitHub Desktop.

Select an option

Save tianhaoz95/b978ef584df0d66515f05f00595c16be to your computer and use it in GitHub Desktop.
const useQuery = (): URLSearchParams => {
return new URLSearchParams(useLocation().search);
};
const Home = (): JSX.Element => {
const query = useQuery();
const wowUrl = query.get("wow");
const githubUser: string = query.get("gh_user") ? query.get("gh_user") : "wowlink";
const githubRepository: string = query.get("gh_repo") ? query.get("gh_repo") : "default-profile";
const [progress, setProgress] = useState({ msg: "init" });
useEffect(() => {
const convertAndRedirect = async () => {
const fetcher: LookupFetcher = GitHubLookupFetcher({ githubUser, githubRepository });
const fetcherResponse: LookupFetchResponse = await fetcher.fetch({});
const translator: UrlTranslator = BasicUrlTranslator({ fetcherResponse });
window.location.href = translator.convert({ wowUrl }).fullUrl;
};
convertAndRedirect();
}, [wowUrl, githubUser, githubRepository]);
return (<div className="App"><p>WOW Link: a goto link service</p></div>);
};
export default (): JSX.Element => { return (<Router><Home/></Router>); };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment