From 7b685076c668631f0a13f534dff5e0673f634613 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 29 Mar 2018 10:49:53 +0200 Subject: [PATCH] Perfect history for the search --- scripts/Actions/Search.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/Actions/Search.ts b/scripts/Actions/Search.ts index 84f31b2b..531fc9df 100644 --- a/scripts/Actions/Search.ts +++ b/scripts/Actions/Search.ts @@ -24,6 +24,11 @@ var soundtrackSearchResults: HTMLElement var userSearchResults: HTMLElement var companySearchResults: HTMLElement +// Fetch options +const fetchOptions: RequestInit = { + credentials: "same-origin" +} + // Search export async function search(arn: AnimeNotifier, search: HTMLInputElement, e: KeyboardEvent) { if(e.ctrlKey || e.altKey) { @@ -48,11 +53,11 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, e: Ke correctResponseRendered.forum = false correctResponseRendered.soundtrack = false correctResponseRendered.user = false + correctResponseRendered.company = false // Set browser URL let url = "/search/" + term document.title = "Search: " + term - history.replaceState(url, document.title, url) arn.app.currentPath = url // Unmount mountables to improve visual responsiveness on key press @@ -76,6 +81,10 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, e: Ke arn.app.content.innerHTML = "" arn.app.content.appendChild(searchPage) + + history.pushState(url, document.title, url) + } else { + history.replaceState(url, document.title, url) } if(!animeSearchResults) { @@ -96,10 +105,6 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, e: Ke return } - const fetchOptions: RequestInit = { - credentials: "same-origin" - } - // Start searching fetch("/_/anime-search/" + term, fetchOptions) .then(showResponseInElement(arn, url, "anime", animeSearchResults))