Blogposts are a thing now
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5e688e3870
commit
4eb00e38bc
@ -1,4 +1,74 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"dutchellie.nl/DutchEllie/proper-website-2/entity"
|
||||||
|
"github.com/maxence-charriere/go-app/v9/pkg/app"
|
||||||
|
)
|
||||||
|
|
||||||
type blogLinks struct {
|
type blogLinks struct {
|
||||||
|
app.Compo
|
||||||
|
|
||||||
|
blogposts []entity.BlogPost
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *blogLinks) OnMount(ctx app.Context) {
|
||||||
|
b.LoadPosts(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *blogLinks) Render() app.UI {
|
||||||
|
return newUIBlock().
|
||||||
|
Class("left").
|
||||||
|
Class("leftbarblock").
|
||||||
|
Class("blogpost-bar").
|
||||||
|
UI(
|
||||||
|
app.P().
|
||||||
|
Class("p-h3").
|
||||||
|
Style("margin-left", "10px").
|
||||||
|
Style("margin-top", "10px").
|
||||||
|
Style("text-decoration", "underline").
|
||||||
|
Text("Posts"),
|
||||||
|
app.Range(b.blogposts).Slice(func(i int) app.UI {
|
||||||
|
return app.P().
|
||||||
|
Class("blogpost-titles").
|
||||||
|
Style("cursor", "pointer").
|
||||||
|
Text(b.blogposts[i].Title).
|
||||||
|
OnClick(func(ctx app.Context, e app.Event) {
|
||||||
|
//e.PreventDefault()
|
||||||
|
|
||||||
|
// Calling the update-blogpost action defined in the blogpage.go file.
|
||||||
|
// There it's updated
|
||||||
|
ctx.NewAction("update-blogpost", app.T("blogpost", b.blogposts[i].Path))
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *blogLinks) LoadPosts(ctx app.Context) {
|
||||||
|
// TODO: maybe you can put this in a localbrowser storage?
|
||||||
|
url := ApiURL + "/blogpost"
|
||||||
|
ctx.Async(func() {
|
||||||
|
res, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
app.Log(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
jsondata, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
app.Log(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Dispatch(func(ctx app.Context) {
|
||||||
|
err = json.Unmarshal(jsondata, &b.blogposts)
|
||||||
|
if err != nil {
|
||||||
|
app.Log(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/maxence-charriere/go-app/v9/pkg/app"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/maxence-charriere/go-app/v9/pkg/app"
|
||||||
|
)
|
||||||
|
|
||||||
type BlogPage struct {
|
type BlogPage struct {
|
||||||
app.Compo
|
app.Compo
|
||||||
|
|
||||||
|
display bool
|
||||||
|
currentPostPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: write the backend API for this
|
// TODO: write the backend API for this
|
||||||
@ -18,11 +25,30 @@ func NewBlogPage() *BlogPage {
|
|||||||
return &BlogPage{}
|
return &BlogPage{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BlogPage) OnMount(ctx app.Context) {
|
||||||
|
ctx.Handle("update-blogpost", b.onUpdateBlogPost)
|
||||||
|
b.display = false
|
||||||
|
}
|
||||||
|
|
||||||
func (b *BlogPage) Render() app.UI {
|
func (b *BlogPage) Render() app.UI {
|
||||||
return newPage().
|
return newPage().
|
||||||
Title("Blog").
|
Title("Blog").
|
||||||
LeftBar(
|
LeftBar(
|
||||||
newHTMLBlock().
|
&blogLinks{},
|
||||||
Class("left leftbarblock"),
|
).
|
||||||
|
Main(
|
||||||
|
app.If(b.display,
|
||||||
|
newHTMLBlock().
|
||||||
|
Class("right").
|
||||||
|
Class("contentblock").
|
||||||
|
Src(b.currentPostPath),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BlogPage) onUpdateBlogPost(ctx app.Context, a app.Action) {
|
||||||
|
fmt.Printf("Called the update-blogpost ActionHandler\n")
|
||||||
|
blogpost := a.Tags.Get("blogpost")
|
||||||
|
b.currentPostPath = blogpost
|
||||||
|
b.display = true
|
||||||
|
}
|
||||||
|
@ -20,12 +20,11 @@ func main() {
|
|||||||
aboutpage := NewAboutPage()
|
aboutpage := NewAboutPage()
|
||||||
galaxiespage := NewGalaxiesPage()
|
galaxiespage := NewGalaxiesPage()
|
||||||
undertalePage := NewUndertalePage()
|
undertalePage := NewUndertalePage()
|
||||||
emptyPage := NewEmptyPage()
|
|
||||||
app.Route("/", homepage)
|
app.Route("/", homepage)
|
||||||
app.Route("/about", aboutpage)
|
app.Route("/about", aboutpage)
|
||||||
app.Route("/galaxies", galaxiespage)
|
app.Route("/galaxies", galaxiespage)
|
||||||
app.Route("/undertale", undertalePage)
|
app.Route("/undertale", undertalePage)
|
||||||
app.Route("/empty", emptyPage)
|
app.Route("/blog", NewBlogPage())
|
||||||
|
|
||||||
app.Handle(getHTML, handleGetHTML)
|
app.Handle(getHTML, handleGetHTML)
|
||||||
|
|
||||||
|
6
web/blocks/blogposts/testpost1.html
Normal file
6
web/blocks/blogposts/testpost1.html
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<p class="p-h1">Test blogpost</p>
|
||||||
|
<p>This is some text under the title</p>
|
||||||
|
<p class="p-h2">Header 2</p>
|
||||||
|
<p class="p-h3">Header 3</p>
|
||||||
|
<p>Regular text here</p>
|
||||||
|
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Minus, omnis nesciunt beatae dolorem laudantium quidem? Eos fugiat doloribus, ipsam, suscipit repudiandae culpa laboriosam accusamus alias atque esse rerum, tenetur illum.</p>
|
@ -138,6 +138,15 @@ body {
|
|||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.blogpost-bar {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.blogpost-titles {
|
||||||
|
margin-left: 10px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: rgb(252, 230, 255);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
.content p {
|
.content p {
|
||||||
|
Loading…
Reference in New Issue
Block a user