-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from botmaster/refactor/no-ref/refactor-stores
refactor: Refactor stores
- Loading branch information
Showing
19 changed files
with
271 additions
and
87 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,64 @@ | ||
<script setup lang="ts"> | ||
import type { IArticle } from '~/types/types'; | ||
defineProps<{ | ||
item: IArticle | ||
}>(); | ||
const { locale: currentLocale } = useI18n(); | ||
// Computed - Map status color to tailwind color | ||
const statusColor = computed<Record<string, string>>(() => { | ||
return { | ||
red: 'badge--is-danger', | ||
green: 'badge--is-success', | ||
blue: 'badge--is-info', | ||
}; | ||
}); | ||
</script> | ||
|
||
<template> | ||
<AppCard | ||
:data-pageid="item.id" | ||
class="h-full" | ||
> | ||
<template #image> | ||
<img v-if="item.image" loading="lazy" :src="item.image" alt=""> | ||
<div v-if="item.status" class="absolute right-2 top-1.5"> | ||
<span | ||
class="badge shadow-md" | ||
:class="item.status.color ? statusColor[item.status.color] : 'badge--is-neutral'" | ||
>{{ | ||
item.status.name | ||
}}</span> | ||
</div> | ||
</template> | ||
|
||
<h3 class="font-body text-base font-bold capitalize leading-tight"> | ||
<span class="mr-[0.3em]">{{ item.title }}</span> | ||
</h3> | ||
<p v-if="item.tags.length" class="mt-2 flex flex-wrap gap-2"> | ||
<span | ||
v-for="tag in item.tags" | ||
:key="tag.id" | ||
class="badge badge--is-neutral badge--is-small" | ||
>{{ tag.name }}</span> | ||
</p> | ||
<p v-if="item.score" class="mt-2 text-xs"> | ||
{{ item.score.name }} | ||
</p> | ||
|
||
<template #footer> | ||
<p v-if="item.createdTime" class="mt-2 text-xs font-normal text-muted-text"> | ||
{{ new Date(item.createdTime).toLocaleDateString(currentLocale) }} | ||
</p> | ||
<p class="truncate"> | ||
<Icon name="material-symbols:link" class="text-lg" /> <a :href="item.url" target="_blank">{{ item.url }}</a> | ||
</p> | ||
</template> | ||
</AppCard> | ||
</template> | ||
|
||
<style scoped lang="scss"> | ||
</style> |
File renamed without changes.
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,23 @@ | ||
<script setup lang="ts"> | ||
import type { NuxtError } from '#app'; | ||
const props = defineProps({ | ||
error: Object as () => NuxtError, | ||
}); | ||
const localePath = useLocalePath(); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<NuxtLayout> | ||
<div class="container mx-auto mb-12 mt-8 md:mb-24 md:mt-20"> | ||
<h1>{{ error?.statusCode }}</h1> | ||
<pre v-if="error">{{ error }}</pre> | ||
<NuxtLink :to="localePath({ name: 'index' })"> | ||
Go back home | ||
</NuxtLink> | ||
</div> | ||
</NuxtLayout> | ||
</div> | ||
</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 |
---|---|---|
@@ -1,9 +1,27 @@ | ||
<script setup lang="ts"></script> | ||
<script setup lang="ts"> | ||
// const { data, error } = await useAsyncData('test', () => $fetch('/api/test')); | ||
import { useTestStore } from '~/stores/test.store'; | ||
const testStore = useTestStore(); | ||
const { data, error } = await useAsyncData('test', () => testStore.fetchTest()); | ||
</script> | ||
|
||
<template> | ||
<h1>test</h1> | ||
<div v-if="data"> | ||
<p>Data:</p> | ||
-> {{ data }} | ||
</div> | ||
<div v-if="error"> | ||
<p>Error:</p> | ||
-> {{ error }} | ||
</div> | ||
</template> | ||
|
||
<style scoped lang="scss"> | ||
h1 { | ||
color: red; | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default defineEventHandler(async (event) => { | ||
throw createError({ | ||
statusCode: 502, | ||
statusMessage: 'Something bad happened on the server', | ||
}); | ||
}); |
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,71 @@ | ||
/** | ||
* Pinia Article Database store | ||
*/ | ||
import type { GetDatabaseResponse } from '@notionhq/client/build/src/api-endpoints'; | ||
import { FetchError } from 'ofetch'; | ||
import type { IArticleTag } from '~/types/types'; | ||
|
||
export const useArticleDatabaseInfoStore = defineStore('articleDatabaseInfo', () => { | ||
const config = useRuntimeConfig(); | ||
|
||
// State | ||
const database = ref<GetDatabaseResponse>(); | ||
const loading = ref(false); | ||
const error = ref<null | Error>(null); | ||
|
||
// Actions | ||
const fetchDatabase = async () => { | ||
loading.value = true; | ||
|
||
try { | ||
const response = await $fetch('/api/notion-database-info', { | ||
params: { | ||
database_id: config.public.notionDatabaseId, | ||
}, | ||
method: 'GET', | ||
}); | ||
database.value = response; | ||
return response; | ||
} | ||
|
||
catch (e) { | ||
if (e instanceof FetchError) { | ||
error.value = e.data; | ||
throw e; | ||
} | ||
else { | ||
error.value = e as Error; | ||
return e; | ||
} | ||
} | ||
|
||
finally { | ||
loading.value = false; | ||
} | ||
}; | ||
|
||
// Getters | ||
// Get "tags" multi-select value from dbResponse | ||
const tagList = computed<IArticleTag[]>(() => { | ||
const selectProperty = database.value?.properties?.Tags as { | ||
type: 'multi_select' | ||
multi_select: { | ||
options: Array<IArticleTag> | ||
} | ||
id: string | ||
name: string | ||
}; | ||
return selectProperty?.multi_select?.options || []; | ||
}); | ||
|
||
return { | ||
loading, | ||
error, | ||
database, | ||
fetchDatabase, | ||
tagList, | ||
}; | ||
}); | ||
|
||
if (import.meta.hot) | ||
import.meta.hot.accept(acceptHMRUpdate(useArticleDatabaseInfoStore, import.meta.hot)); |
Oops, something went wrong.