diff --git a/src/components/Library.astro b/src/components/Library.astro index 930acaa..65d37c5 100644 --- a/src/components/Library.astro +++ b/src/components/Library.astro @@ -31,7 +31,7 @@ const {postDivSelector, skipSave = false} = Astro.props; const cachedRequests = (await cache.keys()) .filter(request => { const urlObj = new URL(request.url); - return urlObj.search !== ''; + return urlObj.search !== '' && urlObj.searchParams.get('url') !== ''; }); if(cachedRequests?.length) { @@ -64,7 +64,7 @@ const {postDivSelector, skipSave = false} = Astro.props; link.onclick = async (e) => { e.preventDefault(); localStorage.setItem('scrollPosition', window.scrollY.toString()); - scroll(0,0); + scrollTo(0,0); renderPost(responseText, url, postDivSelector?.value) } const item = document.createElement('li'); diff --git a/src/utils/library.ts b/src/utils/library.ts index 8903eb9..707028c 100644 --- a/src/utils/library.ts +++ b/src/utils/library.ts @@ -71,19 +71,24 @@ export function renderPost(responseText, url, postDivSelector: string, preventPu const newPost = html.querySelector('body')?.querySelector('#post'); if (postDiv && newPost?.innerHTML) { postDiv.innerHTML = newPost.innerHTML - const homeBtn = document.getElementById('app-home') as HTMLButtonElement; - homeBtn.removeAttribute('disabled'); const appUrl = document.getElementById('app-url') as HTMLInputElement; const cozyUrl = html.querySelector('meta[property="cozy:url"]')?.getAttribute('content'); + const homeBtn = document.getElementById('app-home') as HTMLButtonElement; + const submitBtn = document.getElementById('submit') as HTMLButtonElement; + + if(cozyUrl !== '/') { appUrl.value = cozyUrl || ''; + homeBtn.removeAttribute('disabled'); + submitBtn.removeAttribute('disabled'); } else { appUrl.value = ''; + homeBtn.setAttribute('disabled', 'true'); + submitBtn.setAttribute('disabled', 'true'); } + if(!preventPushState) { window.history.pushState({url}, '', url); } - const submitBtn = document.getElementById('submit') as HTMLButtonElement; - submitBtn.removeAttribute('disabled'); } } \ No newline at end of file