2024-01-22 15:22:16 +00:00
|
|
|
package news
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2024-09-11 00:52:18 +00:00
|
|
|
"mhtml/database"
|
2024-01-22 15:22:16 +00:00
|
|
|
"mhtml/h"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func StoryList() *h.Node {
|
|
|
|
|
|
2024-09-11 00:52:18 +00:00
|
|
|
posts, _ := database.GetOrSet[[]Post]("posts", func() []Post {
|
|
|
|
|
p, _ := List()
|
|
|
|
|
return p
|
|
|
|
|
})
|
2024-01-22 15:22:16 +00:00
|
|
|
|
2024-09-11 00:52:18 +00:00
|
|
|
if len(*posts) == 0 {
|
2024-01-22 15:22:16 +00:00
|
|
|
return h.P("No results found")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return h.Fragment(
|
2024-09-11 00:52:18 +00:00
|
|
|
h.VStack(h.List(*posts, func(item Post) *h.Node {
|
2024-01-22 15:22:16 +00:00
|
|
|
return StoryCard(item)
|
|
|
|
|
})),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func StoryCard(post Post) *h.Node {
|
|
|
|
|
url := fmt.Sprintf("/news/%d", post.Id)
|
|
|
|
|
return h.VStack(
|
2024-09-11 00:52:18 +00:00
|
|
|
h.Class("items-center bg-indigo-200 p-4 rounded"),
|
2024-01-22 15:22:16 +00:00
|
|
|
h.A(post.Title, h.Href(url)),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func StoryFull(id string) *h.Node {
|
|
|
|
|
post, err := Get(id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return h.P(err.Error())
|
|
|
|
|
}
|
|
|
|
|
return StoryCard(post)
|
|
|
|
|
}
|