Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
project_ss23_gameunity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Yusuf Akgül
project_ss23_gameunity
Merge requests
!23
Tweet comments
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Tweet comments
tweetComments
into
main
Overview
0
Commits
3
Pipelines
1
Changes
10
Merged
David
requested to merge
tweetComments
into
main
1 year ago
Overview
0
Commits
3
Pipelines
1
Changes
10
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
9fc8a4b7
3 commits,
1 year ago
10 files
+
452
−
71
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
10
Search (e.g. *.vue) (Ctrl+P)
app/(content)/(home)/home/[postid]/page.tsx
0 → 100644
+
108
−
0
Options
import
CommentButton
from
"
@/components/comment-button
"
;
import
LikeButton
from
"
@/components/like-button
"
;
import
PostCommentForm
from
"
@/components/post-comment
"
;
import
PostItem
from
"
@/components/post-item
"
;
import
{
db
}
from
"
@/lib/db
"
;
import
{
Prisma
}
from
"
@prisma/client
"
;
export
const
revalidate
=
5
;
// revalidate this page every 5 seconds
type
messageType
=
any
// Prisma.PostUncheckedCreateInput
type
messageItemProps
=
{
msg
:
messageType
;
};
export
default
async
function
PostDetail
({
params
}:
{
params
:
{
postid
:
string
}
})
{
const
postid
=
params
.
postid
let
comments
=
null
let
message
=
null
try
{
comments
=
await
db
.
comment
.
findMany
({
where
:
{
postId
:
postid
},
orderBy
:
{
createdAt
:
"
desc
"
},
include
:
{
user
:
true
,
Like
:
true
},
})
message
=
await
db
.
post
.
findUnique
({
where
:
{
id
:
postid
},
include
:
{
user
:
true
,
Comment
:
true
,
Like
:
true
,
},
})
}
catch
(
error
)
{
console
.
log
(
"
the database is not running, try: 'npx prisma migrate dev --name init' if you want to use the database
"
)
}
return
(
<
div
>
<
h1
>
Post Section
</
h1
>
<
p
>
This will be where all comments show up.
</
p
>
<
p
>
Needs a reload after posting!!
</
p
>
<
PostItem
msg
=
{
message
}
/>
<
PostCommentForm
postid
=
{
postid
}
/>
{
comments
?
<>
{
comments
.
map
((
msg
)
=>
(
<
CommentItem
msg
=
{
msg
}
key
=
{
msg
.
id
}
/>
))
}
</>
:
<
p
>
no comments / no database
</
p
>
}
</
div
>
)
}
const
CommentItem
=
({
msg
}:
any
)
=>
{
if
(
!
msg
.
id
)
{
return
<
div
></
div
>;
}
return
(
<
div
className
=
"flex border-b border-gray-200 py-4"
>
<
div
className
=
"flex-shrink-0"
>
<
div
className
=
"h-10 w-10 rounded-full bg-gray-300"
></
div
>
</
div
>
<
div
className
=
"ml-4 flex flex-col flex-grow"
>
<
div
>
<
div
className
=
"flex items-center"
>
<
span
className
=
"font-bold mr-2"
>
{
msg
.
user
.
name
}
</
span
>
<
span
className
=
"text-gray-500 text-sm"
>
{
formatDate
(
new
Date
(
msg
.
createdAt
!
))
}
</
span
>
</
div
>
<
div
className
=
"text-gray-800"
>
{
msg
.
message
}
</
div
>
</
div
>
<
div
className
=
"mt-4 flex"
>
<
div
className
=
"bg-gray-200 rounded-lg py-10 px-20 mr-2"
>
</
div
>
</
div
>
<
div
className
=
"flex justify-end"
>
<
LikeButton
data
=
{
msg
}
/>
</
div
>
</
div
>
</
div
>
);
};
function
formatDate
(
date
:
Date
)
{
return
date
.
toLocaleDateString
(
"
en-US
"
,
{
day
:
"
numeric
"
,
month
:
"
short
"
,
year
:
"
numeric
"
});
}
\ No newline at end of file
Loading