Skip to content

Commit

Permalink
refactor(post): remove duplicate isDraft condition
Browse files Browse the repository at this point in the history
  • Loading branch information
fntsrlike committed Jul 31, 2023
1 parent 96e4737 commit 580f583
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion components/ListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class="text-xl font-bold leading-8 tracking-tight text-gray-900 dark:text-gray-100"
>
{{ item.title }}
<DraftBadge v-if="!item.published_at"></DraftBadge>
<DraftBadge v-if="isDraft(item)"></DraftBadge>
</h3>
<p class="text-gray-800 dark:text-gray-200">
{{ item.title_en }}
Expand All @@ -48,6 +48,9 @@
<script setup lang="ts">
import { DateTime } from 'luxon'
import { Post } from '@/types/index'
import { usePost } from '@/composables/usePost'
const { isDraft } = usePost()
defineProps<{
item: Post
Expand Down
5 changes: 3 additions & 2 deletions components/ListPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import { ref } from 'vue'
import { DateTime } from 'luxon'
import { Post } from '@/types/index'
import { usePost } from '@/composables/usePost'
const props = defineProps<{
page: Post
posts: Post[]
}>()
const { isDraft } = usePost()
const searchValue = ref('')
const list = props.posts.map((post) => {
Expand All @@ -45,9 +47,8 @@ const list = props.posts.map((post) => {
const filteredPosts = computed(() => {
return list.filter((post: Post) => {
const isDraft = !post.published_at
const isProduct = !process.dev
if (isProduct && isDraft) {
if (isProduct && isDraft(post)) {
return false
}
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Post extends ParsedContent {
published_at: string
updated_at: string
tags: string[]
draft: boolean
}

interface ToC {
Expand Down

0 comments on commit 580f583

Please sign in to comment.