Skip to content

Commit

Permalink
Revert making ui translatable since it breaks stuff
Browse files Browse the repository at this point in the history
This reverts commit 0e61249.
  • Loading branch information
zadeviggers committed Oct 25, 2022
1 parent 0e61249 commit 799949e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
36 changes: 15 additions & 21 deletions src/components/OfflineButton.astro
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
---
import { useTranslations } from '../i18n/util';
const t = useTranslations(Astro);
---

<div id="offline-wrapper">
<span id="offline-status-text" aria-hidden="true">{t('offline.statusText.disabled')}</span>
<button id="offline-control-button" aria-hidden="true" tabindex="-1">
{t('offline.button.install')}
</button>
<span id="offline-status-text" aria-hidden="true">Offline not enabled.</span>
<button id="offline-control-button" aria-hidden="true" tabindex="-1">Install offline</button>
</div>
<style>
#offline-wrapper {
Expand Down Expand Up @@ -67,9 +60,6 @@ const t = useTranslations(Astro);
</style>

<script>
import { useTranslations } from '../i18n/util';
const t = useTranslations(Astro);

const offlineWrapper = document.getElementById('offline-wrapper') as HTMLDivElement;
const offlineStatusText = document.getElementById('offline-status-text') as HTMLSpanElement;
const offlineButton = document.getElementById('offline-control-button') as HTMLButtonElement;
Expand Down Expand Up @@ -123,6 +113,10 @@ const t = useTranslations(Astro);
offlineStatusText.classList.toggle('loading', isLoading);
}

function updateStatusMessage(message: string) {
offlineStatusText.innerText = message;
}

if (import.meta.env.DEV) removeOffline();
else if ('serviceWorker' in navigator) {
offlineWrapper.toggleAttribute('data-offline-supported', true);
Expand All @@ -132,8 +126,8 @@ const t = useTranslations(Astro);

if (await isWorkerInstalled()) {
// If the site is already set up to work offline, make the button remove offline support instead
offlineButton.innerText = t('offline.button.remove')!;
offlineStatusText.innerText = t('offline.statusText.enabled')!;
offlineButton.innerText = 'Remove offline';
updateStatusMessage('Offline enabled.');
}

navigator.serviceWorker.addEventListener('controllerchange', downloadStuffOnSwReady);
Expand All @@ -151,7 +145,7 @@ const t = useTranslations(Astro);
break;
case 'offline ready':
updateLoadingState(false);
offlineStatusText.innerText = t('offline.statusText.ready')!;
updateStatusMessage('Ready to work offline.');
break;
}
});
Expand All @@ -160,25 +154,25 @@ const t = useTranslations(Astro);

offlineButton.addEventListener('click', async () => {
if (await isWorkerInstalled()) {
offlineStatusText.innerText = t('offline.statusText.removing')!;
updateStatusMessage('Removing offline.');
updateLoadingState(true);
await removeOffline();
updateLoadingState(false);
offlineStatusText.innerText = t('offline.statusText.removed')!;
offlineButton.innerText = t('offline.button.install')!;
updateStatusMessage('Offline removed.');
offlineButton.innerText = 'Install offline';
} else {
offlineButton.toggleAttribute('disabled', true);
offlineStatusText.innerText = t('offline.statusText.installing')!;
updateStatusMessage('Installing worker.');
updateLoadingState(true);
navigator.serviceWorker
.register('/service-worker.js', {
scope: '/',
})
.then(() => {
offlineButton.innerText = t('offline.button.remove')!;
offlineButton.innerText = 'Remove offline';
offlineButton.toggleAttribute('disabled', false);
updateLoadingState(false);
offlineStatusText.innerText = t('offline.statusText.installed')!;
updateStatusMessage('Worker installed.');
});
}
});
Expand Down
11 changes: 0 additions & 11 deletions src/i18n/en/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ export default {
// Offline warning message at the top of documentation pages
'offline.warning.title': 'Page served from offline cache',
'offline.warning.body': 'The content here may be out of date, so be careful.',
// Offline control button
'offline.button.install': 'Install offline',
'offline.button.remove': 'Remove offline',
// Status text next to the offline control button
'offline.statusText.installing': 'Installing worker,',
'offline.statusText.removing': 'Removing offline.',
'offline.statusText.installed': 'Installed worker.',
'offline.statusText.removed': 'Offline removed.',
'offline.statusText.ready': 'Ready to work offline.',
'offline.statusText.enabled': 'Offline enabled.',
'offline.statusText.disabled': 'Offline not enabled.',
// Aside component default labels
'aside.note': 'Note',
'aside.tip': 'Tip',
Expand Down

0 comments on commit 799949e

Please sign in to comment.