-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
253 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
export default defineAppConfig({ | ||
ui: { | ||
primary: 'lime', | ||
gray: 'neutral' | ||
primary: 'emerald', | ||
container: { | ||
constrained: 'max-w-2xl' | ||
}, | ||
card: { | ||
header: { | ||
base: 'flex flex-wrap items-center justify-between' | ||
}, | ||
body: { | ||
base: 'space-y-4' | ||
} | ||
}, | ||
dropdown: { | ||
width: 'w-full', | ||
popper: { | ||
strategy: 'absolute' | ||
} | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,70 @@ | ||
<script setup lang="ts"> | ||
<script setup> | ||
const { loggedIn } = useUserSession() | ||
const colorMode = useColorMode() | ||
const color = computed(() => colorMode.value === 'dark' ? '#111827' : 'white') | ||
watch(loggedIn, () => { | ||
if (!loggedIn.value) { | ||
navigateTo('/') | ||
} | ||
}) | ||
function toggleColorMode() { | ||
colorMode.preference = colorMode.preference === 'dark' ? 'light' : 'dark' | ||
} | ||
useHead({ | ||
meta: [ | ||
{ charset: 'utf-8' }, | ||
{ name: 'viewport', content: 'width=device-width, initial-scale=1' }, | ||
{ key: 'theme-color', name: 'theme-color', content: color } | ||
], | ||
link: [ | ||
{ rel: 'icon', href: '/favicon.ico' } | ||
], | ||
htmlAttrs: { | ||
lang: 'en' | ||
} | ||
htmlAttrs: { lang: 'en' }, | ||
link: [{ rel: 'icon', href: '/icon.png' }], | ||
}) | ||
useSeoMeta({ | ||
viewport: 'width=device-width, initial-scale=1, maximum-scale=1', | ||
title: 'Nuxt Todos Edge', | ||
description: | ||
'A Nuxt demo hosted with Edge-side rendering, authentication and queyring a SQLite database', | ||
ogImage: '/social-image.png', | ||
twitterImage: '/social-image.png', | ||
twitterCard: 'summary_large_image', | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<NuxtLoadingIndicator /> | ||
<UContainer class="min-h-screen flex flex-col justify-center"> | ||
<div class="mb-2 text-right"> | ||
<UButton | ||
square | ||
variant="ghost" | ||
color="black" | ||
:icon="$colorMode.preference === 'dark' ? 'i-heroicons-moon' : 'i-heroicons-sun'" | ||
@click="toggleColorMode" | ||
/> | ||
</div> | ||
|
||
<NuxtPage /> | ||
|
||
<NuxtLayout> | ||
<NuxtPage /> | ||
</NuxtLayout> | ||
<footer class="text-center mt-2"> | ||
<NuxtLink | ||
href="https://github.com/atinux/nuxt-todos-edge" | ||
target="_blank" | ||
class="text-sm text-gray-500 hover:text-gray-700" | ||
> | ||
GitHub | ||
</NuxtLink> | ||
· | ||
<NuxtLink | ||
href="https://twitter.com/Atinux" | ||
target="_blank" | ||
class="text-sm text-gray-500 hover:text-gray-700" | ||
> | ||
</NuxtLink> | ||
</footer> | ||
</UContainer> | ||
<UNotifications /> | ||
</template> | ||
|
||
<UNotifications /> | ||
</div> | ||
</template> | ||
<style lang="postcss"> | ||
body { | ||
@apply font-sans text-gray-950 bg-gray-50 dark:bg-gray-950 dark:text-gray-50; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<script setup> | ||
definePageMeta({ | ||
middleware: 'auth' | ||
}) | ||
const loading = ref(false) | ||
const newTodo = ref('') | ||
const newTodoInput = ref(null) | ||
const toast = useToast() | ||
const { user, clear } = useUserSession() | ||
const { data: todos } = await useFetch('/api/todos') | ||
async function addTodo () { | ||
if (!newTodo.value.trim()) { return } | ||
loading.value = true | ||
try { | ||
const todo = await $fetch('/api/todos', { | ||
method: 'POST', | ||
body: { | ||
title: newTodo.value, | ||
completed: 0 | ||
} | ||
}) | ||
todos.value.push(todo) | ||
toast.add({ title: `Todo "${todo.title}" created.` }) | ||
newTodo.value = '' | ||
nextTick(() => { | ||
newTodoInput.value?.input?.focus() | ||
}) | ||
} catch (err) { | ||
if (err.data?.data?.issues) { | ||
const title = err.data.data.issues.map(issue => issue.message).join('\n') | ||
toast.add({ title, color: 'red' }) | ||
} | ||
} | ||
loading.value = false | ||
} | ||
async function toggleTodo (todo) { | ||
todo.completed = Number(!todo.completed) | ||
await useFetch(`/api/todos/${todo.id}`, { | ||
method: 'PATCH', | ||
body: { | ||
completed: todo.completed | ||
} | ||
}) | ||
} | ||
async function deleteTodo (todo) { | ||
await useFetch(`/api/todos/${todo.id}`, { method: 'DELETE' }) | ||
todos.value = todos.value.filter(t => t.id !== todo.id) | ||
toast.add({ title: `Todo "${todo.title}" deleted.` }) | ||
} | ||
const items = [[{ | ||
label: 'Logout', | ||
icon: 'i-heroicons-arrow-left-on-rectangle', | ||
click: clear | ||
}]] | ||
</script> | ||
<template> | ||
<UCard @submit.prevent="addTodo"> | ||
<template #header> | ||
<h3 class="text-lg font-semibold leading-6"> | ||
<NuxtLink to="/"> | ||
Todo List | ||
</NuxtLink> | ||
</h3> | ||
<UDropdown v-if="user" :items="items"> | ||
<UButton color="white" trailing-icon="i-heroicons-chevron-down-20-solid"> | ||
<UAvatar :src="`https://github.com/${user.login}.png`" :alt="user.login" size="3xs" /> | ||
{{ user.login }} | ||
</UButton> | ||
</UDropdown> | ||
</template> | ||
<div class="flex items-center gap-2"> | ||
<UInput | ||
ref="newTodoInput" | ||
v-model="newTodo" | ||
name="todo" | ||
:disabled="loading" | ||
class="flex-1" | ||
placeholder="Make a Nuxt demo" | ||
autocomplete="off" | ||
autofocus | ||
:ui="{ wrapper: 'flex-1' }" | ||
/> | ||
<UButton type="submit" icon="i-heroicons-plus-20-solid" :loading="loading" :disabled="newTodo.trim().length === 0" /> | ||
</div> | ||
<ul class="divide-y divide-gray-200 dark:divide-gray-800"> | ||
<li | ||
v-for="todo of todos" | ||
:key="todo.id" | ||
class="flex items-center gap-4 py-2" | ||
> | ||
<span class="flex-1 font-medium" :class="[todo.completed ? 'line-through text-gray-500' : '']">{{ todo.title }}</span> | ||
<UToggle :model-value="Boolean(todo.completed)" @update:model-value="toggleTodo(todo)" /> | ||
<UButton | ||
color="red" | ||
variant="soft" | ||
size="2xs" | ||
icon="i-heroicons-x-mark-20-solid" | ||
@click="deleteTodo(todo)" | ||
/> | ||
</li> | ||
</ul> | ||
</UCard> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE `todos` ( | ||
`id` integer PRIMARY KEY NOT NULL, | ||
`user_id` integer NOT NULL, | ||
`title` text NOT NULL, | ||
`completed` integer DEFAULT 0 NOT NULL, | ||
`created_at` integer NOT NULL | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.