Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polish-community-beth
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Beth Davies
polish-community-beth
Commits
9f017d78
Commit
9f017d78
authored
8 months ago
by
Richard Githuba
Browse files
Options
Downloads
Patches
Plain Diff
changes to feed.js
parent
3a1940cf
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/resources/static/js/feed/feed.js
+10
-11
10 additions, 11 deletions
src/main/resources/static/js/feed/feed.js
with
10 additions
and
11 deletions
src/main/resources/static/js/feed/feed.js
+
10
−
11
View file @
9f017d78
...
...
@@ -41,7 +41,7 @@ function renderPost(post) {
postImage
.
style
.
display
=
'
none
'
;
}
//
R
ender tags
//
r
ender
the
tags
const
tagsContainer
=
postElement
.
querySelector
(
'
.post-tags
'
);
if
(
post
.
tags
&&
post
.
tags
.
length
>
0
)
{
post
.
tags
.
forEach
(
tag
=>
{
...
...
@@ -51,15 +51,15 @@ function renderPost(post) {
});
}
//
S
et
likes
count
//
s
et
the
count
of the likes
const
likeCount
=
postElement
.
querySelector
(
'
.like-count
'
);
likeCount
.
textContent
=
post
.
likesCount
||
0
;
//
Set
timestamp
// timestamp
const
timestamp
=
postElement
.
querySelector
(
'
.timestamp
'
);
timestamp
.
textContent
=
new
Date
(
post
.
postTime
).
toLocaleDateString
();
//
A
dd like
button functionality
//
a
dd
a
like
when presses
const
likeButton
=
postElement
.
querySelector
(
'
.like-button
'
);
likeButton
.
addEventListener
(
'
click
'
,
()
=>
handleLike
(
post
.
postId
,
likeCount
));
...
...
@@ -70,10 +70,10 @@ function renderPost(post) {
postFeed
.
appendChild
(
postElement
);
}
//
Handle like button click
//
add a like if user had not already liked and remove a like if already liked
async
function
handleLike
(
postId
,
likeCountElement
)
{
try
{
//
C
heck if user ha
s
already liked
the post
//
c
heck if user ha
d
already liked
const
checkResponse
=
await
fetch
(
`
${
API_BASE_URL
}
/
${
postId
}
/hasLiked?userId=
${
MOCK_USER_ID
}
`
);
const
hasLiked
=
await
checkResponse
.
json
();
...
...
@@ -84,11 +84,11 @@ async function handleLike(postId, likeCountElement) {
if
(
!
response
.
ok
)
throw
new
Error
(
'
Failed to update like
'
);
//
U
pdate like count
in UI
//
u
pdate like count
appropriately
const
currentCount
=
parseInt
(
likeCountElement
.
textContent
);
likeCountElement
.
textContent
=
hasLiked
?
currentCount
-
1
:
currentCount
+
1
;
//
Toggle like button appearance
//
change color to show they have liked already
const
button
=
likeCountElement
.
closest
(
'
.like-button
'
);
button
.
classList
.
toggle
(
'
liked
'
,
!
hasLiked
);
...
...
@@ -97,10 +97,9 @@ async function handleLike(postId, likeCountElement) {
}
}
// Initialize the feed
document
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
{
fetchPosts
();
});
// Optional: Add auto-refresh functionality
// setInterval(fetchPosts, 60000); // Refresh every minute
\ No newline at end of file
// refresh posts each minute , though cannot show at moment since not online
setInterval
(
fetchPosts
,
60000
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment