-
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.
- Loading branch information
Showing
10 changed files
with
126 additions
and
43 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
<script setup lang="ts"> | ||
const needRefresh = ref(false) | ||
const newMsgId = ref<number>() | ||
function handlePublished() { | ||
needRefresh.value = true | ||
function handlePublished(id: number | undefined) { | ||
newMsgId.value = id | ||
} | ||
function handleRefreshed() { | ||
needRefresh.value = false | ||
newMsgId.value = undefined | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="w-full"> | ||
<ThoughtsMessages :need-refresh="needRefresh" @refreshed="handleRefreshed" /> | ||
<div class="relative size-full overflow-auto"> | ||
<ThoughtsMessages :new-msg-id="newMsgId" @refreshed="handleRefreshed" /> | ||
<ThoughtsInput @published="handlePublished" /> | ||
</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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import dayjs from 'dayjs' | ||
import prisma from '~/lib/prisma' | ||
|
||
async function selectSingleMessage(id: number) { | ||
const message = await prisma.message.findUnique({ | ||
where: { id }, | ||
select: { | ||
id: true, | ||
parent: { | ||
select: { | ||
id: true, | ||
content: true, | ||
}, | ||
}, | ||
author: { | ||
select: { | ||
id: true, | ||
username: true, | ||
site: true, | ||
avatar: true, | ||
}, | ||
}, | ||
content: true, | ||
publishedAt: true, | ||
editedAt: true, | ||
}, | ||
}) | ||
|
||
return message | ||
} | ||
|
||
export default formattedEventHandler(async (event) => { | ||
const query = getQuery(event) as { id: string } | ||
const id = Number.parseInt(query.id) | ||
const message = await selectSingleMessage(id) | ||
if (!message) { | ||
return { | ||
statusCode: 404, | ||
statusMessage: 'Message not found', | ||
success: false, | ||
} | ||
} | ||
const result = { | ||
...message, | ||
publishedAt: dayjs(message.publishedAt).format('YYYY-MM-DD HH:mm:ss'), | ||
editedAt: dayjs(message.editedAt).format('YYYY-MM-DD HH:mm:ss'), | ||
} | ||
return { payload: result } | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ export interface MessageItem { | |
site: string | null | ||
avatar: string | null | ||
} | null | ||
isNew?: boolean | ||
} |