docs/.vitepress/theme/components/ReloadPrompt.vue

9c71c0b98c33380d391db04906088be28b13ac57
wotaku/docs/.vitepress/theme/components/ReloadPrompt.vue
taskylizard hello world, again319b2575cd 1 year ago

104 lines · 2902 bytes

  1<!--
  2  Copyright (c) 2024 taskylizard
  3
  4  Licensed under the Apache License, Version 2.0 (the "License");
  5  you may not use this file except in compliance with the License.
  6  You may obtain a copy of the License at
  7
  8  http://www.apache.org/licenses/LICENSE-2.0
  9
 10  Unless required by applicable law or agreed to in writing, software
 11  distributed under the License is distributed on an "AS IS" BASIS,
 12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  See the License for the specific language governing permissions and
 14  limitations under the License.
 15-->
 16<script setup lang="ts">
 17import { onBeforeMount, ref } from 'vue'
 18
 19const needRefresh = ref(false)
 20
 21let updateServiceWorker: (() => Promise<void>) | undefined
 22
 23function onNeedRefresh() {
 24  needRefresh.value = true
 25}
 26async function close() {
 27  needRefresh.value = false
 28}
 29
 30onBeforeMount(async () => {
 31  const { registerSW } = await import('virtual:pwa-register')
 32  updateServiceWorker = registerSW({
 33    immediate: true,
 34    onNeedRefresh
 35  })
 36})
 37</script>
 38
 39<template>
 40  <template v-if="needRefresh">
 41    <div
 42      class="pwa-toast z-100 bg-$vp-c-bg b b-solid b-1px b-color-$pwa-border rounded-2 fixed bottom-0 right-0 m-6 px-6 py-4 shadow-xl"
 43      role="alertdialog"
 44      aria-labelledby="pwa-message"
 45    >
 46      <div id="pwa-message" class="mb-3">
 47        New content available, click the reload button to update.
 48      </div>
 49      <button
 50        type="button"
 51        class="pwa-refresh mr-2 rounded px-3 py-1"
 52        @click="updateServiceWorker?.()"
 53      >
 54        Reload
 55      </button>
 56      <button
 57        type="button"
 58        class="pwa-cancel b b-solid b-1px !b-color-$pwa-border mr-2 rounded px-3 py-1"
 59        @click="close"
 60      >
 61        Close
 62      </button>
 63    </div>
 64  </template>
 65</template>
 66
 67<style scoped>
 68/* PWA: Prompt for Update */
 69.pwa-toast .pwa-refresh {
 70  border-color: var(--vp-button-brand-border);
 71  color: var(--vp-button-brand-text);
 72  background-color: var(--vp-button-brand-bg);
 73}
 74
 75.pwa-toast .pwa-refresh:hover {
 76  border-color: var(--vp-button-brand-hover-border);
 77  color: var(--vp-button-brand-hover-text);
 78  background-color: var(--vp-button-brand-hover-bg);
 79}
 80
 81.pwa-toast .pwa-refresh:active {
 82  border-color: var(--vp-button-brand-active-border);
 83  color: var(--vp-button-brand-active-text);
 84  background-color: var(--vp-button-brand-active-bg);
 85}
 86
 87.pwa-toast .pwa-cancel {
 88  border-color: var(--vp-button-alt-border);
 89  color: var(--vp-button-alt-text);
 90  background-color: var(--vp-button-alt-bg);
 91}
 92
 93.pwa-toast .pwa-cancel:hover {
 94  border-color: var(--vp-button-alt-hover-border);
 95  color: var(--vp-button-alt-hover-text);
 96  background-color: var(--vp-button-alt-hover-bg);
 97}
 98
 99.pwa-toast .pwa-cancel:active {
100  border-color: var(--vp-button-alt-active-border);
101  color: var(--vp-button-alt-active-text);
102  background-color: var(--vp-button-alt-active-bg);
103}
104</style>
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form