2024-10-10 22:00:20 +00:00
|
|
|
package partials
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/maddalax/htmgo/framework/h"
|
|
|
|
|
"hackernews/internal/news"
|
|
|
|
|
"hackernews/internal/timeformat"
|
|
|
|
|
"strconv"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Story(ctx *h.RequestContext) *h.Partial {
|
|
|
|
|
storyId, err := strconv.ParseInt(ctx.QueryParam("item"), 10, 64)
|
|
|
|
|
|
2024-10-10 22:17:05 +00:00
|
|
|
if storyId == 0 || err != nil {
|
|
|
|
|
return h.NewPartial(
|
2024-10-10 22:00:20 +00:00
|
|
|
h.Div(
|
2024-10-10 22:17:05 +00:00
|
|
|
h.Class("flex justify-center bg-neutral-300"),
|
|
|
|
|
h.Id("story-body"),
|
2024-10-10 22:00:20 +00:00
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
story, err := news.GetStory(int(storyId))
|
|
|
|
|
|
|
|
|
|
if ctx.IsHxRequest() {
|
|
|
|
|
return h.SwapManyPartialWithHeaders(
|
|
|
|
|
ctx,
|
|
|
|
|
h.PushUrlHeader(fmt.Sprintf("/?item=%d", storyId)),
|
|
|
|
|
StoryBody(story),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return h.NewPartial(
|
|
|
|
|
StoryBody(story),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func StoryBody(story *news.Story) *h.Element {
|
|
|
|
|
return h.Div(
|
2024-10-10 22:17:05 +00:00
|
|
|
h.Class("min-w-3xl"),
|
2024-10-10 22:00:20 +00:00
|
|
|
h.Id("story-body"),
|
|
|
|
|
h.Div(
|
2024-10-10 22:17:05 +00:00
|
|
|
h.Class("prose prose-2xl bg-white border-b border-gray-200 pb-3 min-w-3xl max-w-3xl"),
|
2024-10-10 22:00:20 +00:00
|
|
|
h.H5(
|
|
|
|
|
h.Class("flex gap-2 items-center font-bold"),
|
|
|
|
|
h.UnsafeRaw(story.Title),
|
|
|
|
|
),
|
|
|
|
|
h.A(
|
|
|
|
|
h.Href(story.Url),
|
|
|
|
|
h.Class("text-sm text-rose-400 no-underline"),
|
|
|
|
|
h.Text(story.Url),
|
|
|
|
|
),
|
|
|
|
|
h.Div(
|
|
|
|
|
h.Class("text-sm text-gray-600"),
|
|
|
|
|
h.UnsafeRaw(story.Text),
|
|
|
|
|
),
|
|
|
|
|
h.Div(
|
|
|
|
|
h.Class("text-sm text-gray-600 mt-2"),
|
|
|
|
|
h.TextF("%d upvotes ", story.Score),
|
|
|
|
|
h.UnsafeRaw("•"),
|
|
|
|
|
h.TextF(" %s ", story.By),
|
|
|
|
|
h.UnsafeRaw("•"),
|
|
|
|
|
h.TextF(" %s", timeformat.RelativeTime(story.Time)),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
h.Div(
|
2024-10-10 22:17:05 +00:00
|
|
|
h.Class("mt-2 min-w-3xl max-w-3xl"),
|
2024-10-10 22:00:20 +00:00
|
|
|
h.GetPartial(StoryComments, "load"),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}
|