adding and displaying of entries works"

;
This commit is contained in:
2024-03-06 12:40:44 +01:00
parent faadac6e35
commit 2ced264c55
36 changed files with 841 additions and 6 deletions

View File

@@ -0,0 +1,35 @@
import moment, { Moment } from "moment";
import { Ref, ref } from "vue";
const localStorageKey = 'entries'
export const entries: Ref<Entry[]> = ref(parseFromPossibleString(localStorage.getItem(localStorageKey)))
export interface Entry {
name: string
text: string | undefined
last_reset: Moment
}
export function parseFromPossibleString(input: string | null): Entry[] {
if (input === null) {
return []
}
const entries: Entry[] = []
const rawObjects: any[] = JSON.parse(input)
for (const rawObject of rawObjects) {
const { name, text, last_reset } = rawObject
if (name && text && last_reset) {
entries.push({ name, text, last_reset: moment(last_reset) })
}
}
return entries
}
export function save() {
localStorage.setItem(localStorageKey, JSON.stringify(entries.value))
}