diff --git a/assets/style.css b/assets/style.css index b0ee548..19c5121 100644 --- a/assets/style.css +++ b/assets/style.css @@ -3,12 +3,14 @@ body { margin: 0 auto; padding: 1em; font-family: Verdana; + background-color: azure; + color: midnightblue; } -section { - padding: 1em; - background-color: lightblue; -} +/*section {*/ +/* padding: 1em;*/ +/* background-color: lightblue;*/ +/*}*/ .flash { background-color: lightgreen; @@ -50,13 +52,13 @@ dd { margin-bottom: 1em; } -nav { - margin-bottom: 1em; -} +/*nav {*/ +/* margin-bottom: 1em;*/ +/*}*/ -h1, h2 { - margin-top: 0; -} +/*h1, h2 {*/ +/* !*margin-top: 0;*!*/ +/*}*/ .tools { list-style-position: inside; @@ -65,11 +67,12 @@ h1, h2 { @media (min-width: 650px) { .cols { - grid-template-columns: repeat(2, 1fr); - grid-gap: 1em; + grid-template-columns: 1fr 2fr; + grid-gap: 2em; } } +.radio { display: inline-block } .field { margin-bottom: 1rem; max-width: 500px; } .field > label { margin-bottom: .25rem; } .field > * { display: block; width: 100%; box-sizing: border-box; } \ No newline at end of file diff --git a/model/status.go b/model/status.go index 1929413..cd03a54 100644 --- a/model/status.go +++ b/model/status.go @@ -10,6 +10,7 @@ type Status struct { Id int64 User string Content string + Face string CreatedAt time.Time } diff --git a/storage/migration.go b/storage/migration.go index b3ac4a2..83842fb 100644 --- a/storage/migration.go +++ b/storage/migration.go @@ -7,7 +7,7 @@ import ( "strconv" ) -const schemaVersion = 7 +const schemaVersion = 8 func Migrate(db *sql.DB) { var currentVersion int diff --git a/storage/sql.go b/storage/sql.go index 2cd228a..93866b7 100644 --- a/storage/sql.go +++ b/storage/sql.go @@ -40,4 +40,6 @@ alter column about TYPE TEXT;`, add column picture varchar(500) not null DEFAULT '';`, "schema_version_7": `alter table users add column email varchar(500) not null DEFAULT '';`, + "schema_version_8": `alter table statuses + add column face varchar(1) not null DEFAULT '🙂';`, } diff --git a/storage/sql/schema_version_8.sql b/storage/sql/schema_version_8.sql new file mode 100644 index 0000000..d8245a0 --- /dev/null +++ b/storage/sql/schema_version_8.sql @@ -0,0 +1,2 @@ +alter table statuses + add column face varchar(1) not null DEFAULT '🙂'; \ No newline at end of file diff --git a/storage/status.go b/storage/status.go index b4f46ef..0858053 100644 --- a/storage/status.go +++ b/storage/status.go @@ -15,7 +15,7 @@ type statusQueryBuilder struct { } func (p statusQueryBuilder) build() string { - query := []string{`SELECT id, author, content, created_at from statuses`} + query := []string{`SELECT id, author, content, created_at, face from statuses`} if p.where != "" { query = append(query, `WHERE`, p.where) } @@ -31,7 +31,7 @@ func (p statusQueryBuilder) build() string { func (s *Storage) populateStatus(rows *sql.Rows) (model.Status, error) { var status model.Status - err := rows.Scan(&status.Id, &status.User, &status.Content, &status.CreatedAt) + err := rows.Scan(&status.Id, &status.User, &status.Content, &status.CreatedAt, &status.Face) if err != nil { return status, err } @@ -45,8 +45,8 @@ func (s *Storage) CreateStatus(status model.Status) error { if err != nil { return err } - if err := tx.QueryRowContext(ctx, `INSERT INTO statuses (author, content) VALUES ($1, $2) RETURNING id`, - status.User, status.Content).Scan(&statusId); err != nil { + if err := tx.QueryRowContext(ctx, `INSERT INTO statuses (author, content, face) VALUES ($1, $2, $3) RETURNING id`, + status.User, status.Content, status.Face).Scan(&statusId); err != nil { tx.Rollback() return err } @@ -121,7 +121,8 @@ func (s *Storage) LatestStatuses() ([]model.Status, error) { statuses.id, users.name, statuses.content, - statuses.created_at + statuses.created_at, + statuses.face from users inner join statuses @@ -143,11 +144,11 @@ func (s *Storage) LatestStatuses() ([]model.Status, error) { } func (s *Storage) UpdateStatus(status model.Status) error { - stmt, err := s.db.Prepare(`UPDATE statuses SET content = $1 WHERE id = $2 and author = $3;`) + stmt, err := s.db.Prepare(`UPDATE statuses SET content = $1, face = $2 WHERE id = $3 and author = $4;`) if err != nil { return err } - _, err = stmt.Exec(status.Content, status.Id, status.User) + _, err = stmt.Exec(status.Content, status.Face, status.Id, status.User) return err } @@ -186,7 +187,13 @@ func (s *Storage) DeleteStatus(id int64, author string) error { tx.Rollback() return err } + } else { + if _, err := tx.ExecContext(ctx, `UPDATE users set status_id=$1 where name=$2`, latestId, author); err != nil { + tx.Rollback() + return err + } } + err = tx.Commit() return err } diff --git a/web/handler/common.go b/web/handler/common.go index f42fec1..30be482 100644 --- a/web/handler/common.go +++ b/web/handler/common.go @@ -42,7 +42,7 @@ var TplCommonMap = map[string]string{ {{ define "head" }}{{ end }} `, "status": `{{ define "status" }} -
{{ .User }}, {{ .TimeAgo }}
+
{{ .User }} {{ .Face }} {{ .TimeAgo }}

{{ .Content }}

{{ end }}`, } diff --git a/web/handler/form/status.go b/web/handler/form/status.go index 888574b..627f7dd 100644 --- a/web/handler/form/status.go +++ b/web/handler/form/status.go @@ -8,6 +8,7 @@ import ( type StatusForm struct { Id int64 Content string + Face string Error string } @@ -17,5 +18,6 @@ func NewStatusForm(r *http.Request) *StatusForm { return &StatusForm{ Id: id, Content: r.FormValue("content"), + Face: r.FormValue("face"), } } diff --git a/web/handler/html.go b/web/handler/html.go index 5a649b9..7f9cebf 100644 --- a/web/handler/html.go +++ b/web/handler/html.go @@ -63,6 +63,19 @@ var TplMap = map[string]string{ `, "current_status": `{{ define "content" }} +

Current Status Widget

@@ -79,7 +92,21 @@ var TplMap = map[string]string{

Past this code into your HTML file:

- + +

Past this code into your CSS file:

+ +

Make it your own! The CSS above is only an example. Tweak it so that it integrates well with your sites's colors.

Preview

@@ -90,19 +117,6 @@ var TplMap = map[string]string{ {{ end }}
- {{ end }}`, "edit_status": `{{ define "content" }}
@@ -112,10 +126,58 @@ var TplMap = map[string]string{ {{ end }} {{ template "flash" .flash }}
-
-
- +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
@@ -130,15 +192,65 @@ var TplMap = map[string]string{ {{ end }} {{ template "flash" .flash }}
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
-
+

Status stream

@@ -149,7 +261,8 @@ var TplMap = map[string]string{ {{ end }}
-{{ end }}`, +{{ end }} +`, "intro": `{{ define "content" }}

Introduction

diff --git a/web/handler/html/common/status.html b/web/handler/html/common/status.html index 2b97063..f06431e 100644 --- a/web/handler/html/common/status.html +++ b/web/handler/html/common/status.html @@ -1,4 +1,4 @@ {{ define "status" }} -
{{ .User }}, {{ .TimeAgo }}
+
{{ .User }} {{ .Face }} {{ .TimeAgo }}

{{ .Content }}

{{ end }} \ No newline at end of file diff --git a/web/handler/html/current_status.html b/web/handler/html/current_status.html index 914342a..876be29 100644 --- a/web/handler/html/current_status.html +++ b/web/handler/html/current_status.html @@ -1,4 +1,17 @@ {{ define "content" }} +

Current Status Widget

@@ -15,7 +28,21 @@

Past this code into your HTML file:

- + +

Past this code into your CSS file:

+ +

Make it your own! The CSS above is only an example. Tweak it so that it integrates well with your sites's colors.

Preview

@@ -26,17 +53,4 @@ {{ end }}
- {{ end }} \ No newline at end of file diff --git a/web/handler/html/edit_status.html b/web/handler/html/edit_status.html index abb1b4d..a7cccdc 100644 --- a/web/handler/html/edit_status.html +++ b/web/handler/html/edit_status.html @@ -6,10 +6,58 @@ {{ end }} {{ template "flash" .flash }}
-
-
- +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
diff --git a/web/handler/html/index.html b/web/handler/html/index.html index ae34eca..c25e551 100644 --- a/web/handler/html/index.html +++ b/web/handler/html/index.html @@ -7,15 +7,65 @@ {{ end }} {{ template "flash" .flash }}
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
-
+

Status stream

@@ -26,4 +76,4 @@ {{ end }}
-{{ end }} \ No newline at end of file +{{ end }} diff --git a/web/handler/status_save.go b/web/handler/status_save.go index 5a0b884..2c74731 100644 --- a/web/handler/status_save.go +++ b/web/handler/status_save.go @@ -16,6 +16,7 @@ func (h *Handler) saveStatus(w http.ResponseWriter, r *http.Request) { status := model.Status{ User: user, Content: f.Content, + Face: f.Face, } if err := status.Validate(); err != nil { f.Error = err.Error() diff --git a/web/handler/status_update.go b/web/handler/status_update.go index f5dff0f..6453a01 100644 --- a/web/handler/status_update.go +++ b/web/handler/status_update.go @@ -30,6 +30,7 @@ func (h *Handler) updateStatus(w http.ResponseWriter, r *http.Request) { } f := form.NewStatusForm(r) status.Content = f.Content + status.Face = f.Face if err := status.Validate(); err != nil { f.Error = err.Error() h.renderLayout(w, "edit_post", map[string]interface{}{ diff --git a/web/handler/widget_show.go b/web/handler/widget_show.go index 3d78791..d72ec94 100644 --- a/web/handler/widget_show.go +++ b/web/handler/widget_show.go @@ -15,7 +15,7 @@ fetch("https://status.cafe/users/` + name + `/status.json") document.getElementById("statuscafe-content").innerHTML = "No status yet." return } - document.getElementById("statuscafe-username").innerHTML = '' + r.author + '\'s status, updated ' + r.timeAgo + document.getElementById("statuscafe-username").innerHTML = '' + r.author + ', ' + r.timeAgo document.getElementById("statuscafe-content").innerHTML = r.content }) `))