refactor: migrate to nuxt
This commit is contained in:
17
utils/index.ts
Normal file
17
utils/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { meat, staple, vegetable } from '~/data/food'
|
||||
|
||||
const foodItems = [...vegetable, ...meat, ...staple]
|
||||
const foodEmojiMap = new Map()
|
||||
foodItems.forEach((item) => {
|
||||
foodEmojiMap.set(item.name, item.emoji)
|
||||
})
|
||||
|
||||
/**
|
||||
* get emojis from stuff name array
|
||||
* @param stuff
|
||||
* @returns
|
||||
*/
|
||||
export function getEmojisFromStuff(stuff: string[]) {
|
||||
const emojis: string[] = stuff.map(name => foodEmojiMap.get(name)).filter(item => !!item)
|
||||
return emojis
|
||||
}
|
||||
34
utils/pwa.ts
Normal file
34
utils/pwa.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { isClient } from '@vueuse/core'
|
||||
|
||||
/**
|
||||
* https://web.dev/customize-install/#detect-install
|
||||
* @returns
|
||||
*/
|
||||
export function installPrompt() {
|
||||
if (!isClient)
|
||||
return
|
||||
|
||||
const app = useAppStore()
|
||||
|
||||
window.addEventListener('beforeinstallprompt', (e) => {
|
||||
// Prevent the mini-infobar from appearing on mobile
|
||||
// e.preventDefault()
|
||||
// Stash the event so it can be triggered later.
|
||||
app.deferredPrompt = e
|
||||
// Update UI notify the user they can install the PWA
|
||||
// showInstallPromotion()
|
||||
// Optionally, send analytics event that PWA install promo was shown.
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('\'beforeinstallprompt\' event was fired.')
|
||||
})
|
||||
|
||||
window.addEventListener('appinstalled', () => {
|
||||
// Hide the app-provided install promotion
|
||||
// hideInstallPromotion()
|
||||
// Clear the deferredPrompt so it can be garbage collected
|
||||
app.deferredPrompt = null
|
||||
// Optionally, send analytics event to indicate successful install
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('PWA was installed')
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user