|
| 1 | +<template> |
| 2 | + <div v-if="status" :class="[$style.statusBar, classes]"> |
| 3 | + <h1 :class="$style.title">{{ status.title }}</h1> |
| 4 | + <button v-if="status.button && status.action" type="button" :class="$style.button" @click="status.action"> |
| 5 | + {{ status.button }} |
| 6 | + </button> |
| 7 | + </div> |
| 8 | +</template> |
| 9 | + |
| 10 | +<script lang="ts" setup> |
| 11 | +import { useStorage } from '@storage/index.ts'; |
| 12 | +import { ClassNames } from '@utils'; |
| 13 | +import { computed } from 'vue'; |
| 14 | +import { useI18n } from 'vue-i18n'; |
| 15 | +
|
| 16 | +type Status = { |
| 17 | + title: string; |
| 18 | + button?: string; |
| 19 | + action?: () => unknown; |
| 20 | +}; |
| 21 | +
|
| 22 | +const props = defineProps<{ |
| 23 | + class?: ClassNames; |
| 24 | +}>(); |
| 25 | +
|
| 26 | +const { t } = useI18n(); |
| 27 | +const { status: storageStatus, retry: retrySync } = useStorage(); |
| 28 | +
|
| 29 | +const classes = computed(() => props.class); |
| 30 | +
|
| 31 | +const status = computed((): Status | undefined => { |
| 32 | + switch (storageStatus.value) { |
| 33 | + case 'error': |
| 34 | + return { |
| 35 | + title: t('navigation.status.synchronizationFailedDueToNetworkError'), |
| 36 | + button: t('navigation.status.retrySynchronization'), |
| 37 | + action: retrySync |
| 38 | + }; |
| 39 | + case 'retrying': { |
| 40 | + return { |
| 41 | + title: t('navigation.status.retryingPleaseWait') |
| 42 | + }; |
| 43 | + } |
| 44 | + } |
| 45 | +
|
| 46 | + return undefined; |
| 47 | +}); |
| 48 | +</script> |
| 49 | + |
| 50 | +<style lang="scss" module> |
| 51 | +.statusBar { |
| 52 | + display: flex; |
| 53 | + align-items: center; |
| 54 | + justify-content: center; |
| 55 | + height: 24px; |
| 56 | + background: var(--c-danger); |
| 57 | + color: var(--c-danger-text); |
| 58 | + gap: 4px; |
| 59 | +} |
| 60 | +
|
| 61 | +.button { |
| 62 | + all: unset; |
| 63 | + text-decoration: underline; |
| 64 | + cursor: pointer; |
| 65 | +} |
| 66 | +
|
| 67 | +.title, |
| 68 | +.button { |
| 69 | + font-size: var(--font-size-xs); |
| 70 | + font-weight: var(--font-weight-l); |
| 71 | +} |
| 72 | +</style> |
0 commit comments