From ab95ee5e2b35c00137159b72201b7b454861d6d6 Mon Sep 17 00:00:00 2001 From: orangix Date: Tue, 15 Aug 2023 19:52:47 +0200 Subject: [PATCH] added covers to user comment page --- api/user.go | 28 ++++++++---- pages/user.go | 3 ++ views/partials/contextComment.hbs | 71 ++++++++++++++++--------------- views/userComments.hbs | 2 +- 4 files changed, 59 insertions(+), 45 deletions(-) diff --git a/api/user.go b/api/user.go index c98758c..4ffd4b3 100644 --- a/api/user.go +++ b/api/user.go @@ -111,7 +111,7 @@ func (client *Client) FetchUserComments(username string, page string) ([]Comment q := req.URL.Query() 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("sort", "new") @@ -150,20 +150,30 @@ func (client *Client) FetchUserComments(username string, page string) ([]Comment } func parseSubmission(value gjson.Result) Submission { - coverData := value.Get("images.#(id==\"" + value.Get("cover").String() + "\")") - 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", ""), - } - if coverData.Exists() { + var cover Media + c := value.Get("cover") + coverData := value.Get("images.#(id==\"" + c.String() + "\")") + switch { + case c.Type == gjson.String && coverData.Exists(): cover = Media{ Id: coverData.Get("id").String(), Description: coverData.Get("description").String(), Type: strings.Split(coverData.Get("type").String(), "/")[0], 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() diff --git a/pages/user.go b/pages/user.go index 0a9cc4b..05b0355 100644 --- a/pages/user.go +++ b/pages/user.go @@ -1,6 +1,7 @@ package pages import ( + "fmt" "strconv" "codeberg.org/rimgo/rimgo/utils" @@ -96,6 +97,8 @@ func HandleUserComments(c *fiber.Ctx) error { return err } + fmt.Println(comments[0].Post.Cover.Url) //FIXME:debug + return c.Render("userComments", fiber.Map{ "user": user, "comments": comments, diff --git a/views/partials/contextComment.hbs b/views/partials/contextComment.hbs index 8088271..1faf833 100644 --- a/views/partials/contextComment.hbs +++ b/views/partials/contextComment.hbs @@ -1,38 +1,39 @@ - -
-
- {{#noteq this.User.Username "[deleted]"}} - -

- {{this.User.Username}} - on post title here {{Post.Title}}

- - {{/noteq}} - {{#equal this.User.Username "[deleted]"}} -

[deleted] - on post title here {{Post.Title}}

- {{/equal}} + + +
+ {{#noteq this.User.Username "[deleted]"}} + + +

{{this.User.Username}}

+
+ {{/noteq}} + {{#equal this.User.Username "[deleted]"}} +

[deleted]

+ {{/equal}} +
+
+

{{{this.Comment}}}

+
+ {{this.RelTime}} + {{#if this.DeletedAt}} + (deleted {{this.DeletedAt}}) + {{/if}} + | + Likes + {{this.Upvotes}} + Dislikes + {{this.Downvotes}}
-
-

{{{this.Comment}}}

-
- {{this.RelTime}} - {{#if this.DeletedAt}} - (deleted {{this.DeletedAt}}) - {{/if}} - | - Likes - {{this.Upvotes}} - Dislikes - {{this.Downvotes}} -
-
- {{#if this.Comments}} -
- {{#each this.Comments}} - {{> partials/comment }} - {{/each}} -
- {{/if}} +
+ {{#if this.Comments}} +
+ {{#each this.Comments}} + {{> partials/comment }} + {{/each}} +
+ {{/if}}
\ No newline at end of file diff --git a/views/userComments.hbs b/views/userComments.hbs index 1069fd1..c7be3e4 100644 --- a/views/userComments.hbs +++ b/views/userComments.hbs @@ -2,7 +2,7 @@ - {{user.Username}} - rimgo + {{user.Username}}'s comments - rimgo {{> partials/head }}