feat: add admin components for input, metrics, tables, and user forms
- Introduced AdminInput component for standardized input fields. - Created AdminMetricCard for displaying metrics with customizable tones. - Added AdminPlaceholderTable for loading states in tables. - Developed AdminSectionCard for consistent section layouts. - Implemented AdminSectionShell for organizing admin sections. - Added AdminSelect for dropdown selections with v-model support. - Created AdminTable for displaying tabular data with loading and empty states. - Introduced AdminTextarea for multi-line text input. - Developed AdminUserFormFields for user creation and editing forms. - Added useAdminPageHeader composable for managing admin page header state.
This commit is contained in:
47
src/composables/useNetworkStatus.ts
Normal file
47
src/composables/useNetworkStatus.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
const isOffline = ref(false)
|
||||
|
||||
let listenersCount = 0
|
||||
|
||||
function syncNetworkStatus() {
|
||||
if (typeof navigator === 'undefined') return
|
||||
|
||||
isOffline.value = !navigator.onLine
|
||||
}
|
||||
|
||||
function handleNetworkStatusChange() {
|
||||
syncNetworkStatus()
|
||||
}
|
||||
|
||||
function startListening() {
|
||||
if (typeof window === 'undefined') return
|
||||
|
||||
if (listenersCount === 0) {
|
||||
syncNetworkStatus()
|
||||
window.addEventListener('online', handleNetworkStatusChange)
|
||||
window.addEventListener('offline', handleNetworkStatusChange)
|
||||
}
|
||||
|
||||
listenersCount += 1
|
||||
}
|
||||
|
||||
function stopListening() {
|
||||
if (typeof window === 'undefined' || listenersCount === 0) return
|
||||
|
||||
listenersCount -= 1
|
||||
|
||||
if (listenersCount === 0) {
|
||||
window.removeEventListener('online', handleNetworkStatusChange)
|
||||
window.removeEventListener('offline', handleNetworkStatusChange)
|
||||
}
|
||||
}
|
||||
|
||||
export function useNetworkStatus() {
|
||||
return {
|
||||
isOffline,
|
||||
syncNetworkStatus,
|
||||
startListening,
|
||||
stopListening,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user