comment/post saving. fixes #6

This commit is contained in:
Ryan Stafford 2023-07-05 10:20:07 -04:00
parent 6184bddd02
commit 5a24937781
7 changed files with 74 additions and 15 deletions

View file

@ -89,7 +89,7 @@ code {
.dark .score form.link-btn input { .dark .score form.link-btn input {
color: #646464; color: #646464;
} }
.comment form.link-btn input { .comment .score form.link-btn input {
line-height: 17px; line-height: 17px;
} }
.score form.like.link-btn input:first-child, .score .like div { .score form.like.link-btn input:first-child, .score .like div {
@ -386,7 +386,7 @@ form.nsfw div {
border-left: 2px solid #c5c1ad; border-left: 2px solid #c5c1ad;
padding: 0 8px; padding: 0 8px;
} }
.buttons a, .buttons form input { .buttons a, .buttons form input, .comment .buttons form input {
text-decoration: none; text-decoration: none;
color: #888; color: #888;
padding-right: 4px; padding-right: 4px;

View file

@ -35,7 +35,7 @@ function commentClick(e) {
e = e || window.event; e = e || window.event;
var targ = e.currentTarget || e.srcElement || e; var targ = e.currentTarget || e.srcElement || e;
if (targ.nodeType == 3) targ = targ.parentNode; if (targ.nodeType == 3) targ = targ.parentNode;
if (e.target.name=="vote") { if (e.target.name=="submit") {
e.preventDefault() e.preventDefault()
var form = e.target.parentNode var form = e.target.parentNode
if (form) { if (form) {

View file

@ -860,6 +860,30 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state.Error = err state.Error = err
fmt.Println(err) fmt.Println(err)
} }
case "save_post":
postid, _ := strconv.Atoi(r.FormValue("postid"))
_, err := state.Client.SavePost(context.Background(), types.SavePost{
PostID: postid,
Save: r.FormValue("submit") == "save",
})
if err != nil {
fmt.Println(err)
}
case "save_comment":
commentid, _ := strconv.Atoi(r.FormValue("commentid"))
_, err := state.Client.SaveComment(context.Background(), types.SaveComment{
CommentID: commentid,
Save: r.FormValue("submit") == "save",
})
if err != nil {
fmt.Println(err)
}
if r.FormValue("xhr") != "" {
state.XHR = true
state.GetComment(commentid)
Render(w, "index.html", state)
return
}
case "delete_post": case "delete_post":
postid, _ := strconv.Atoi(r.FormValue("postid")) postid, _ := strconv.Atoi(r.FormValue("postid"))
post := types.DeletePost{ post := types.DeletePost{
@ -900,7 +924,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
case "vote_comment": case "vote_comment":
var score int16 var score int16
score = 1 score = 1
if r.FormValue("vote") != "▲" { if r.FormValue("submit") != "▲" {
score = -1 score = -1
} }
if r.FormValue("undo") == strconv.Itoa(int(score)) { if r.FormValue("undo") == strconv.Itoa(int(score)) {

View file

@ -169,6 +169,11 @@ func (state *State) ParseQuery(RawQuery string) {
if len(m["xhr"]) > 0 { if len(m["xhr"]) > 0 {
state.XHR = true state.XHR = true
} }
if len(m["view"]) > 0 {
if m["view"][0] == "Saved" {
state.Op = "Saved"
}
}
//if len(m["op"]) > 0 { //if len(m["op"]) > 0 {
// state.Op = m["op"][0] // state.Op = m["op"][0]
//} //}
@ -366,6 +371,7 @@ func (state *State) GetUser(username string) {
Username: types.NewOptional(state.UserName), Username: types.NewOptional(state.UserName),
Page: types.NewOptional(int64(state.Page)), Page: types.NewOptional(int64(state.Page)),
Limit: types.NewOptional(int64(limit)), Limit: types.NewOptional(int64(limit)),
SavedOnly: types.NewOptional(state.Op == "Saved"),
}) })
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

View file

@ -3,14 +3,14 @@
{{ if .State.Session }} {{ if .State.Session }}
<div class="score"> <div class="score">
<form class="link-btn{{ if eq .P.MyVote.String "1"}} like{{ else if eq .P.MyVote.String "-1"}} dislike{{end}}" method="POST"> <form class="link-btn{{ if eq .P.MyVote.String "1"}} like{{ else if eq .P.MyVote.String "-1"}} dislike{{end}}" method="POST">
<input type="submit" name="vote" value="▲"> <input type="submit" name="submit" value="▲">
<div></div> <div></div>
{{ if .P.MyVote.IsValid}} {{ if .P.MyVote.IsValid}}
<input type="hidden" name="undo" value="{{.P.MyVote.String}}"> <input type="hidden" name="undo" value="{{.P.MyVote.String}}">
{{ end}} {{ end}}
<input type="hidden" name="op" value="vote_comment"> <input type="hidden" name="op" value="vote_comment">
<input type="hidden" name="commentid" value="{{.P.Comment.ID }}"> <input type="hidden" name="commentid" value="{{.P.Comment.ID }}">
<input type="submit" name="vote" value="▼"> <input type="submit" name="submit" value="▼">
</form> </form>
</div> </div>
{{ end }} {{ end }}
@ -49,7 +49,6 @@
{{ else }} {{ else }}
<li><a class="source" for="c{{.P.Comment.ID}}" href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?">hide source</a></li> <li><a class="source" for="c{{.P.Comment.ID}}" href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?">hide source</a></li>
{{ end }} {{ end }}
{{ if .State.Session }} {{ if .State.Session }}
{{ if and (eq .P.Comment.CreatorID .State.Session.UserID) (ne .Op "edit") }} {{ if and (eq .P.Comment.CreatorID .State.Session.UserID) (ne .Op "edit") }}
<li><a class="edit" for="c{{.P.Comment.ID}}" href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?edit">edit</a></li> <li><a class="edit" for="c{{.P.Comment.ID}}" href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?edit">edit</a></li>
@ -61,8 +60,24 @@
</form> </form>
</li> </li>
{{ end }} {{ end }}
<li>
<form class="link-btn" method="POST">
<input type="hidden" name="commentid" value="{{.P.Comment.ID}}">
<input type="hidden" name="op" value="save_comment">
{{ if .P.Saved }}
<input type="submit" name="submit" value="unsave">
{{ else }}
<input type="submit" name="submit" value="save">
{{ end }}
</form>
</li>
{{ if ne .Op "reply" }} {{ if ne .Op "reply" }}
<li><a class="reply" for="c{{.P.Comment.ID}}" href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?reply">reply</a></li> <li>
<a class="reply" for="c{{.P.Comment.ID}}" href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?reply">
reply
</a>
</li>
{{ end }} {{ end }}
{{ end }} {{ end }}
</ul> </ul>

View file

@ -48,7 +48,10 @@
{{ end }} {{ end }}
<ul> <ul>
{{ if .User }} {{ if .User }}
<li class="selected"><a href="">overview</a></li> <li {{if eq .Op "" }}class="selected"{{end}}><a href="">overview</a></li>
{{ if eq .User.PersonView.Person.ID .Session.UserID}}
<li {{if eq .Op "Saved"}}class="selected"{{end}}><a href="?view=Saved">saved</a></li>
{{ end }}
{{ else if .Comments -}} {{ else if .Comments -}}
<li class="selected"><a href="">comments</a></li> <li class="selected"><a href="">comments</a></li>
{{ else if .Activities }} {{ else if .Activities }}

View file

@ -55,6 +55,17 @@
{{ end }} {{ end }}
</form> </form>
{{ end}} {{ end}}
{{ if .State.Session }}
<form class="link-btn" method="POST">
<input type="hidden" name="postid" value="{{.Post.ID }}">
<input type="hidden" name="op" value="save_post">
{{ if .PostView.Saved }}
<input type="submit" name="submit" value="unsave">
{{ else }}
<input type="submit" name="submit" value="save">
{{ end }}
</form>
{{end}}
</div> </div>
<div class="expando {{ if eq .Rank 0 }}open{{ end}}"> <div class="expando {{ if eq .Rank 0 }}open{{ end}}">
{{ if (and .Post.Body.IsValid (ne .Post.Body.String "")) }} {{ if (and .Post.Body.IsValid (ne .Post.Body.String "")) }}