added covers to user comment page

This commit is contained in:
orangix 2023-08-15 19:52:47 +02:00
parent 3faef9aeb9
commit ab95ee5e2b
No known key found for this signature in database
GPG Key ID: C31D4A86601C8416
4 changed files with 59 additions and 45 deletions

View File

@ -111,7 +111,7 @@ func (client *Client) FetchUserComments(username string, page string) ([]Comment
q := req.URL.Query() q := req.URL.Query()
q.Add("client_id", client.ClientID) q.Add("client_id", client.ClientID)
q.Add("filter[account]", "eq:wouldaponybyanyothernamebeasoffencive") q.Add("filter[account]", "eq:"+username)
q.Add("include", "account,post") q.Add("include", "account,post")
q.Add("sort", "new") q.Add("sort", "new")
@ -150,20 +150,30 @@ func (client *Client) FetchUserComments(username string, page string) ([]Comment
} }
func parseSubmission(value gjson.Result) Submission { func parseSubmission(value gjson.Result) Submission {
coverData := value.Get("images.#(id==\"" + value.Get("cover").String() + "\")") var cover Media
cover := Media{ c := value.Get("cover")
Id: value.Get("id").String(), coverData := value.Get("images.#(id==\"" + c.String() + "\")")
Description: value.Get("description").String(), switch {
Type: strings.Split(value.Get("type").String(), "/")[0], case c.Type == gjson.String && coverData.Exists():
Url: strings.ReplaceAll(value.Get("link").String(), "https://i.imgur.com", ""),
}
if coverData.Exists() {
cover = Media{ cover = Media{
Id: coverData.Get("id").String(), Id: coverData.Get("id").String(),
Description: coverData.Get("description").String(), Description: coverData.Get("description").String(),
Type: strings.Split(coverData.Get("type").String(), "/")[0], Type: strings.Split(coverData.Get("type").String(), "/")[0],
Url: strings.ReplaceAll(coverData.Get("link").String(), "https://i.imgur.com", ""), Url: strings.ReplaceAll(coverData.Get("link").String(), "https://i.imgur.com", ""),
} }
// This case is when fetching comments
case c.Type != gjson.Null:
cover = Media{
Id: c.Get("id").String(),
Url: c.Get("url").String(),
}
default:
cover = Media{
Id: value.Get("id").String(),
Description: value.Get("description").String(),
Type: strings.Split(value.Get("type").String(), "/")[0],
Url: strings.ReplaceAll(value.Get("link").String(), "https://i.imgur.com", ""),
}
} }
id := value.Get("id").String() id := value.Get("id").String()

View File

@ -1,6 +1,7 @@
package pages package pages
import ( import (
"fmt"
"strconv" "strconv"
"codeberg.org/rimgo/rimgo/utils" "codeberg.org/rimgo/rimgo/utils"
@ -96,6 +97,8 @@ func HandleUserComments(c *fiber.Ctx) error {
return err return err
} }
fmt.Println(comments[0].Post.Cover.Url) //FIXME:debug
return c.Render("userComments", fiber.Map{ return c.Render("userComments", fiber.Map{
"user": user, "user": user,
"comments": comments, "comments": comments,

View File

@ -1,38 +1,39 @@
<!-- TODO: remove post titles and instead use cover images -->
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<div class="flex gap-2 items-center"> <img src="{{this.Post.Cover.Url}}" alt="">
{{#noteq this.User.Username "[deleted]"}} <!-- https://codeberg.org/orangix/rimgo/src/branch/main/pages/user.go#L100
<img src="{{this.User.Avatar}}" class="rounded-full" width="24" height="24" loading="lazy"> The URL prints properly here, why doesn't it appear?
<p class="whitespace-nowrap text-ellipsis overflow-hidden"></p><a href="/user/{{this.User.Username}}">
<b class="underline">{{this.User.Username}}</b></span> Also TODO, covers can be videos, ???? -->
on <a class="underline" href={{Post.Link}}>post title here {{Post.Title}}</a></p> <div class="flex gap-2 items-center">
</a> {{#noteq this.User.Username "[deleted]"}}
{{/noteq}} <img src="{{this.User.Avatar}}" class="rounded-full" width="24" height="24" loading="lazy">
{{#equal this.User.Username "[deleted]"}} <a href="/user/{{this.User.Username}}">
<p class="whitespace-nowrap text-ellipsis overflow-hidden"><b>[deleted]</b> <p class="whitespace-nowrap text-ellipsis overflow-hidden"><b>{{this.User.Username}}</b></p>
on <a class="underline" href={{Post.Link}}>post title here {{Post.Title}}</a></p> </a>
{{/equal}} {{/noteq}}
{{#equal this.User.Username "[deleted]"}}
<p class="whitespace-nowrap text-ellipsis overflow-hidden"><b>[deleted]</b></p>
{{/equal}}
</div>
<div>
<p>{{{this.Comment}}}</p>
<div class="flex gap-2">
<span title="{{this.CreatedAt}}">{{this.RelTime}}</span>
{{#if this.DeletedAt}}
<span class="text-md">(deleted {{this.DeletedAt}})</span>
{{/if}}
|
<img class="invert icon" src="/static/icons/PhArrowFatUp.svg" alt="Likes" width="24px" height="24px">
{{this.Upvotes}}
<img class="invert icon" src="/static/icons/PhArrowFatDown.svg" alt="Dislikes" width="24px" height="24px">
{{this.Downvotes}}
</div> </div>
<div> </div>
<p>{{{this.Comment}}}</p> {{#if this.Comments}}
<div class="flex gap-2"> <div class="ml-4 p-2 border-solid border-l-2 border-slate-400">
<span title="{{this.CreatedAt}}">{{this.RelTime}}</span> {{#each this.Comments}}
{{#if this.DeletedAt}} {{> partials/comment }}
<span class="text-md">(deleted {{this.DeletedAt}})</span> {{/each}}
{{/if}} </div>
| {{/if}}
<img class="invert icon" src="/static/icons/PhArrowFatUp.svg" alt="Likes" width="24px" height="24px">
{{this.Upvotes}}
<img class="invert icon" src="/static/icons/PhArrowFatDown.svg" alt="Dislikes" width="24px" height="24px">
{{this.Downvotes}}
</div>
</div>
{{#if this.Comments}}
<div class="ml-4 p-2 border-solid border-l-2 border-slate-400">
{{#each this.Comments}}
{{> partials/comment }}
{{/each}}
</div>
{{/if}}
</div> </div>

View File

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>{{user.Username}} - rimgo</title> <title>{{user.Username}}'s comments - rimgo</title>
{{> partials/head }} {{> partials/head }}
</head> </head>