wip
This commit is contained in:
@@ -3,6 +3,10 @@ import { Ref, ref } from "vue";
|
|||||||
|
|
||||||
const localStorageKey = 'entries'
|
const localStorageKey = 'entries'
|
||||||
|
|
||||||
|
export function getDifferenceToToday(date: Moment) {
|
||||||
|
return Math.abs(date.diff(moment(), 'days'))
|
||||||
|
}
|
||||||
|
|
||||||
export const entries: Ref<Entry[]> = ref(parseFromPossibleString(localStorage.getItem(localStorageKey)))
|
export const entries: Ref<Entry[]> = ref(parseFromPossibleString(localStorage.getItem(localStorageKey)))
|
||||||
|
|
||||||
export interface Entry {
|
export interface Entry {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const router = createRouter({
|
|||||||
history: createWebHistory(),
|
history: createWebHistory(),
|
||||||
routes: [
|
routes: [
|
||||||
{ path: '/', component: Home},
|
{ path: '/', component: Home},
|
||||||
{ path: '/:name', component: Detail}
|
{ path: '/:name', component: Detail, props: true}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,30 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { Card, CardTitle, CardDescription } from '@/components/ui/card';
|
||||||
|
import { entries, getDifferenceToToday } from '@/data/entries';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
const probs = defineProps<{ name: string }>()
|
||||||
|
const entry = ref(entries.value.find(entry => entry.name === probs.name))
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div id="container" class="flex w-full justify-center p-10">
|
||||||
|
<main class="">
|
||||||
|
<header>
|
||||||
|
<Card v-if="entry" class="p-10">
|
||||||
|
<CardTitle>{{ getDifferenceToToday(entry.last_reset) }} days</CardTitle>
|
||||||
|
<CardDescription v-if="entry.text">
|
||||||
|
text is defined
|
||||||
|
{{ entry.text }}
|
||||||
|
</CardDescription>
|
||||||
|
<CardDescription v-else>
|
||||||
|
text is not defined
|
||||||
|
</CardDescription>
|
||||||
|
</Card>
|
||||||
|
</header>
|
||||||
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped></style>
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ import { Badge } from '@/components/ui/badge';
|
|||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
import { getDifferenceToToday } from '@/data/entries';
|
||||||
import { toTypedSchema } from '@vee-validate/zod';
|
import { toTypedSchema } from '@vee-validate/zod';
|
||||||
import * as z from 'zod'
|
import * as z from 'zod'
|
||||||
import moment, { Moment } from 'moment';
|
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { toast } from 'vue-sonner';
|
import { toast } from 'vue-sonner';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const createEntryZodSchema = z.object({
|
const createEntryZodSchema = z.object({
|
||||||
@@ -24,9 +25,6 @@ type CreateEntrySchema = z.infer<typeof createEntryZodSchema>
|
|||||||
|
|
||||||
const createEntrySchema = toTypedSchema(createEntryZodSchema)
|
const createEntrySchema = toTypedSchema(createEntryZodSchema)
|
||||||
|
|
||||||
function getDifferenceToToday(date: Moment) {
|
|
||||||
return Math.abs(date.diff(moment(), 'days'))
|
|
||||||
}
|
|
||||||
|
|
||||||
function createEntry(value: CreateEntrySchema) {
|
function createEntry(value: CreateEntrySchema) {
|
||||||
if (entries.value.map(entry => entry.name).includes(value.name)) {
|
if (entries.value.map(entry => entry.name).includes(value.name)) {
|
||||||
@@ -41,7 +39,8 @@ function createEntry(value: CreateEntrySchema) {
|
|||||||
entries.value.push({
|
entries.value.push({
|
||||||
last_reset: moment(),
|
last_reset: moment(),
|
||||||
name: value.name,
|
name: value.name,
|
||||||
text: value.text
|
text: value.text && value.text.trim() !== ''
|
||||||
|
? value.text : undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
save()
|
save()
|
||||||
|
|||||||
Reference in New Issue
Block a user