mirror of https://github.com/nkoehring/starsy.git
loading and saving to localstorage and filesystem
parent
033688dde4
commit
408b3d156d
@ -0,0 +1,28 @@
|
|||||||
|
<template>
|
||||||
|
<div class="info">
|
||||||
|
<header>
|
||||||
|
<button v-for="(_, slot) in slots"
|
||||||
|
:key="slot"
|
||||||
|
@click="shownSlot = slot"
|
||||||
|
class="app-menu-button"
|
||||||
|
:class="{ highlighted: shownSlot === slot }"
|
||||||
|
>
|
||||||
|
{{ slot }}
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
<slot :name="shownSlot"></slot>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, useSlots } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
defaultSlot: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const slots = useSlots()
|
||||||
|
const shownSlot = ref(props.defaultSlot || Object.keys(slots)[0] || 'default')
|
||||||
|
</script>
|
@ -0,0 +1,45 @@
|
|||||||
|
import { ref, computed } from 'vue'
|
||||||
|
import { useStorage } from '@vueuse/core'
|
||||||
|
|
||||||
|
export default function useStarsyStorage(star, objects) {
|
||||||
|
const store = useStorage('starsy', {
|
||||||
|
example: { star, objects }
|
||||||
|
})
|
||||||
|
|
||||||
|
const storageInfo = computed(() => {
|
||||||
|
return Object.keys(store.value).map(name => {
|
||||||
|
const { star, objects } = store.value[name]
|
||||||
|
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
star: star.designation,
|
||||||
|
objects: objects.length,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const currentName = ref('example')
|
||||||
|
|
||||||
|
function loadPreset(name) {
|
||||||
|
return store.value[name]
|
||||||
|
}
|
||||||
|
|
||||||
|
function savePreset(star, objects) {
|
||||||
|
const name = currentName.value
|
||||||
|
store.value[name] = { star, objects }
|
||||||
|
console.log('saved preset', name, store.value[name])
|
||||||
|
}
|
||||||
|
|
||||||
|
function deletePreset(name) {
|
||||||
|
delete store.value[name]
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
store,
|
||||||
|
storageInfo,
|
||||||
|
loadPreset,
|
||||||
|
savePreset,
|
||||||
|
deletePreset,
|
||||||
|
currentName,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue