fix: disable the nav buttons on home
This commit is contained in:
parent
f913b1f3d2
commit
d3642a4902
2 changed files with 11 additions and 6 deletions
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue