-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(story): add table design #17
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<script setup lang="ts"> | ||
defineProps<{ | ||
goToPage: (page: number) => void; | ||
currentPage: number; | ||
hasPreviousPage: boolean; | ||
hasNextPage: boolean; | ||
numberOfPages: number; | ||
}>(); | ||
</script> | ||
|
||
<template> | ||
<div class="join"> | ||
<button | ||
class="btn btn-ghost btn-sm join-item" | ||
@click="goToPage(currentPage - 1)" | ||
:disabled="!hasPreviousPage" | ||
> | ||
<span class="sr-only">Previous Page</span> | ||
<LucideChevronLeft :size="16" /> | ||
</button> | ||
<div v-for="(_item, idx) in new Array(numberOfPages)"> | ||
<button | ||
class="font-normal btn btn-ghost btn-sm join-item" | ||
:class="{ | ||
'current-page': currentPage === idx + 1, | ||
}" | ||
:disabled="currentPage === idx + 1" | ||
@click="goToPage(idx + 1)" | ||
> | ||
{{ idx + 1 }} | ||
</button> | ||
</div> | ||
<button | ||
class="btn btn-ghost btn-sm join-item" | ||
@click="goToPage(currentPage + 1)" | ||
:disabled="!hasNextPage" | ||
> | ||
<span class="sr-only">Next Page</span> | ||
<LucideChevronRight :size="16" /> | ||
</button> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.current-page { | ||
@apply text-primary opacity-50; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<template></template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<template> | ||
<thead class="bg-gray-100"> | ||
<tr> | ||
<th class="flex items-center gap-3"> | ||
<label class="label"> | ||
<input | ||
class="checkbox checkbox-xs" | ||
type="checkbox" | ||
id="story-select-all" | ||
@change="" | ||
:checked="false" | ||
/> | ||
<label class="sr-only label-text" for="story-select-all" | ||
>Toggle All Stories</label | ||
> | ||
</label> | ||
<span>Name</span> | ||
</th> | ||
<th class="w-28">Content Type</th> | ||
<th class="w-28">Last Update</th> | ||
<th class="w-28">Author</th> | ||
</tr> | ||
</thead> | ||
</template> | ||
|
||
<style scoped> | ||
th { | ||
@apply font-normal text-sm text-gray-600 text-left p-2; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<script setup lang="ts"> | ||
import type { Story } from '~/types/story'; | ||
|
||
const props = defineProps<{ | ||
story: Story; | ||
checked: boolean; | ||
}>(); | ||
|
||
const emit = defineEmits<{ | ||
change: [ | ||
value: { | ||
id: number; | ||
checked: boolean; | ||
} | ||
]; | ||
}>(); | ||
|
||
const lastUpdate = computed(() => { | ||
const timestamp = props.story.updated_at || props.story.created_at; | ||
const [date, time] = timestamp.split('T'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to find out how nuxt handles the formatting of dates and https://nuxt.com/modules/date-fns there is this, but for now a new dependency might be too much so its fine to leave it as is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yeah, date-fns is definitely a great choice for date formatting as soon as we need to really format it :) |
||
return [date, time.slice(0, 5)]; | ||
}); | ||
|
||
const onChange = (event: Event) => { | ||
if (!event.target) { | ||
return; | ||
} | ||
emit('change', { | ||
id: props.story.id, | ||
checked: (event.target as HTMLInputElement).checked, | ||
}); | ||
}; | ||
</script> | ||
|
||
<template> | ||
<tr class="hover:bg-gray-100"> | ||
<td> | ||
<label class="justify-start gap-4 cursor-pointer label"> | ||
<input | ||
class="checkbox checkbox-xs" | ||
type="checkbox" | ||
:id="story.id.toString()" | ||
:name="story.id.toString()" | ||
@change="onChange" | ||
:checked="props.checked" | ||
/> | ||
<label class="label-text" :for="story.id.toString()" | ||
>{{ story.name }}<br /> | ||
<span class="text-xs font-light text-gray-400" | ||
>/{{ story.slug }}</span | ||
></label | ||
> | ||
</label> | ||
</td> | ||
<td class="text-sm font-light text-gray-500"> | ||
{{ story.content_type }} | ||
</td> | ||
<td class="text-xs font-light text-gray-500"> | ||
{{ lastUpdate[0] }}<br />{{ lastUpdate[1] }} | ||
</td> | ||
<td class="text-sm font-light text-gray-500"> | ||
{{ story.last_author.friendly_name }} | ||
</td> | ||
</tr> | ||
</template> | ||
|
||
<style scoped> | ||
td { | ||
@apply p-2; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import { type ISbStoryData } from 'storyblok-js-client'; | ||
|
||
export type Stories = { | ||
stories: ISbStoryData[]; | ||
export type StoriesResponse = { | ||
stories: Story[]; | ||
perPage: number; | ||
total: number; | ||
}; | ||
|
||
export type Story = ISbStoryData & { | ||
// these are missing from `ISbStoryData` | ||
content_type: string; | ||
updated_at?: string; | ||
last_author: { | ||
id: number; | ||
userid: string; | ||
friendly_name: string; | ||
avatar: string; | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the big diff. It was inevitable as I split stuff into smaller chunks. However, the majority of the code is the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love to see some code splitting <3