This commit is contained in:
DutchEllie 2022-03-12 15:52:13 +01:00
parent c10a995b63
commit cb3c3c8d30
Signed by: DutchEllie
SSH Key Fingerprint: SHA256:dKq6ZSgN5E3Viqrw/+xAdf2VdR6hdRGNyrYqXXwfjTY
11 changed files with 122 additions and 119 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
.vscode
app
web/*.wasm
web/*.wasm
staticsite

View File

@ -1,6 +1,12 @@
build:
GOARCH=wasm GOOS=js go build -o web/app.wasm
cp web/app.wasm staticsite/web/app.wasm
scp staticsite/web/app.wasm ellieserver:/home/ellie/nicecock/test/web/
go build -o app
build-all: build
cp -r web/* staticsite/web/
scp -r staticsite/* ellieserver:/home/ellie/nicecock/test
run: build
./app

View File

@ -26,14 +26,14 @@ func (g *guestbookForm) Render() app.UI {
Name("name").
Placeholder("Name").
Required(true).
OnInput(g.ValueTo(&g.name)).
OnChange(g.ValueTo(&g.name)).
Value(g.name),
app.Input().
Type("text").
Name("message").
Placeholder("Message").
Required(true).
OnInput(g.ValueTo(&g.message)).
OnChange(g.ValueTo(&g.message)).
Value(g.message),
app.Input().
Type("submit").

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"io"
"net/http"
"time"
"git.home.dutchellie.nl/DutchEllie/proper-website-2/entity"
"github.com/maxence-charriere/go-app/v9/pkg/app"
@ -24,28 +25,28 @@ AND VERY IMPORTANT!
type guestbookPanel struct {
app.Compo
comments []entity.Comment
CommentUpdate bool
comments []entity.Comment
}
func newGuestbookPanel() *guestbookPanel {
return &guestbookPanel{}
g := &guestbookPanel{}
g.LoadComments()
return g
}
func (g *guestbookPanel) Render() app.UI {
g.LoadComments()
return app.Div().Body(
app.Range(g.comments).Slice(func(i int) app.UI {
return &guestbookComment{
Comment: g.comments[i],
}
}),
).Class("content")
).Class("content gbp")
}
func (g *guestbookPanel) LoadComments() {
// TODO: maybe you can put this in a localbrowser storage?
url := "/api/comment"
url := apiurl + "api/comment"
res, err := http.Get(url)
if err != nil {
app.Log(err)
@ -69,13 +70,18 @@ type guestbookComment struct {
app.Compo
Comment entity.Comment
time string
}
func (c *guestbookComment) Render() app.UI {
c.time = c.Comment.PostDate.Format(time.RFC1123)
return app.Div().Body(
app.Span().Text("Name:").Style("font-weight", "800"),
app.P().Text(c.Comment.Name),
app.Span().Text("Comment:").Style("font-weight", "800"),
app.P().Text(c.Comment.Message),
app.Div().Class().Body(
app.P().Text(c.Comment.Name).Class("name"),
app.P().Text(c.time).Class("date"),
).Class("comment-header"),
app.Div().Class("comment-message").Body(
app.P().Text(c.Comment.Message),
),
).Class("comment")
}

View File

@ -10,17 +10,20 @@ import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
)
const (
apiurl = "https://api.quenten.nl/"
)
type Homepage struct {
app.Compo
showGuestbook bool
guestbookUpdated bool
showGuestbook bool
page string
}
func NewHomepage() *Homepage {
return &Homepage{showGuestbook: true, guestbookUpdated: false, page: "home"}
return &Homepage{showGuestbook: true, page: "home"}
}
func (p *Homepage) Render() app.UI {
@ -44,7 +47,7 @@ func (p *Homepage) Render() app.UI {
fmt.Printf("err: %v\n", err)
return
}
url := "/api/comment"
url := apiurl + "api/comment"
req, err := http.Post(url, "application/json", bytes.NewBuffer(jsondata))
if err != nil {
fmt.Printf("err: %v\n", err)

View File

@ -5,7 +5,8 @@ import "github.com/maxence-charriere/go-app/v9/pkg/app"
type homePanel struct {
app.Compo
onShowClick func()
onShowClick func()
updateAvailable bool
}
func newHomePanel() *homePanel {
@ -18,7 +19,11 @@ func (p *homePanel) Render() app.UI {
app.Raw(`<p>This website is my creative outlet and a way of expressing myself.
As of now, it's probably the most impressive thing I've ever coded.
<br><br>
Please enjoy yourself and do sign the guestbook!!</p>`),
Please enjoy yourself and do sign the guestbook!!!</p>`),
app.If(p.updateAvailable,
app.Div().Body(
app.P().Text("An update is available! Reload to update!!"),
)),
app.Div().Body(
app.P().Text("Please sign my guestbook!").Style("font-size", "0.8em"),
app.Img().Src("/web/static/images/email3.gif").Style("width", "40px").Style("position", "absolute").Style("bottom", "0px").Style("right", "0px"),
@ -29,3 +34,7 @@ Please enjoy yourself and do sign the guestbook!!</p>`),
}),
).Class("content")
}
func (p *homePanel) OnAppUpdate(ctx app.Context) {
p.updateAvailable = true
}

17
go.mod
View File

@ -2,22 +2,9 @@ module git.home.dutchellie.nl/DutchEllie/proper-website-2
go 1.17
require (
github.com/maxence-charriere/go-app/v9 v9.3.0
go.mongodb.org/mongo-driver v1.8.3
)
require github.com/maxence-charriere/go-app/v9 v9.3.0
require (
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.0.2 // indirect
github.com/xdg-go/stringprep v1.0.2 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/text v0.3.6 // indirect
)

44
go.sum
View File

@ -1,68 +1,24 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/gomarkdown/markdown v0.0.0-20210408062403-ad838ccf8cdd/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/maxence-charriere/go-app/v9 v9.3.0 h1:PWNZWcme5hnMR9/cSdSRv+9WvPowETj0qhfy+3HCQRM=
github.com/maxence-charriere/go-app/v9 v9.3.0/go.mod h1:zo0n1kh4OMKn7P+MrTUUi7QwUMU2HOfHsZ293TITtxI=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w=
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc=
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
go.mongodb.org/mongo-driver v1.8.3 h1:TDKlTkGDKm9kkJVUOAXDK5/fkqKHJVwYQSpoRfB43R4=
go.mongodb.org/mongo-driver v1.8.3/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY=
golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f h1:aZp0e2vLN4MToVqnjNEYEtrEA8RH8U8FN1CU7JgqsPU=
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

81
main.go
View File

@ -1,23 +1,22 @@
package main
import (
"context"
"fmt"
"log"
"net/http"
"git.home.dutchellie.nl/DutchEllie/proper-website-2/components"
"github.com/maxence-charriere/go-app/v9/pkg/app"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
)
type application struct {
client *mongo.Client
database *mongo.Database
collection *mongo.Collection
}
//type application struct {
// client *mongo.Client
// database *mongo.Database
// collection *mongo.Collection
//}
const (
apiurl = "https://quenten.nl:8007/"
)
func main() {
homepage := components.NewHomepage()
@ -32,33 +31,7 @@ func main() {
// It exits immediately on the server side
app.RunWhenOnBrowser()
uri := "mongodb+srv://guestbook-database:5WUDzpvBKBBiiMCy@cluster0.wtt64.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
if err != nil {
fmt.Println(err)
return
}
defer func() {
if err = client.Disconnect(context.TODO()); err != nil {
panic(err)
}
}()
// Ping the primary
if err := client.Ping(context.TODO(), readpref.Primary()); err != nil {
panic(err)
}
db := client.Database("guestbook")
coll := db.Collection("comments")
apiapp := &application{
client: client,
database: db,
collection: coll,
}
http.Handle("/", &app.Handler{
handler := &app.Handler{
Name: "Internetica Galactica",
Description: "A 1990's style PWA!",
Styles: []string{
@ -68,8 +41,38 @@ func main() {
"/web/static/havakana.css",
},
CacheableResources: []string{},
})
http.HandleFunc("/api/comment", apiapp.Comment)
}
app.GenerateStaticWebsite("./staticsite", handler)
/*
uri := "mongodb+srv://guestbook-database:5WUDzpvBKBBiiMCy@cluster0.wtt64.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
if err != nil {
fmt.Println(err)
return
}
defer func() {
if err = client.Disconnect(context.TODO()); err != nil {
panic(err)
}
}()
// Ping the primary
if err := client.Ping(context.TODO(), readpref.Primary()); err != nil {
panic(err)
}
db := client.Database("guestbook")
coll := db.Collection("comments")
apiapp := &application{
client: client,
database: db,
collection: coll,
}
*/
http.Handle("/", handler)
//http.HandleFunc("/api/comment", apiapp.Comment)
if err := http.ListenAndServe(":8000", nil); err != nil {
log.Fatal(err)

View File

@ -1,5 +1,6 @@
html {
background-image: url(images/background_star.gif);
overflow-y: scroll;
}
body {
@ -62,11 +63,42 @@ body {
margin-bottom: 5px;
}
.gbp {
}
.comment {
border: 2px solid;
border-radius: 3px;
border-radius: 6px;
border-color: aliceblue;
padding: 5px;
padding: 0px 0px 5px 0px;
background-color: darkseagreen;
}
.comment-header {
margin-top: 0px;
margin-left: 0px;
margin-right: 0px;
background-color: aquamarine;
width: 100%;
color: black;
display: flex;
flex-direction: row;
}
div .name {
text-align: left;
}
div .date {
font-size: 0.8em;
margin-right: 10px;
text-align: right;
color: black;
}
.comment-message {
color:white;
}
.friend-frame {