mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-08 16:15:33 +00:00
comment/post saving. fixes #6
This commit is contained in:
parent
6184bddd02
commit
5a24937781
|
@ -89,7 +89,7 @@ code {
|
|||
.dark .score form.link-btn input {
|
||||
color: #646464;
|
||||
}
|
||||
.comment form.link-btn input {
|
||||
.comment .score form.link-btn input {
|
||||
line-height: 17px;
|
||||
}
|
||||
.score form.like.link-btn input:first-child, .score .like div {
|
||||
|
@ -386,7 +386,7 @@ form.nsfw div {
|
|||
border-left: 2px solid #c5c1ad;
|
||||
padding: 0 8px;
|
||||
}
|
||||
.buttons a, .buttons form input {
|
||||
.buttons a, .buttons form input, .comment .buttons form input {
|
||||
text-decoration: none;
|
||||
color: #888;
|
||||
padding-right: 4px;
|
||||
|
|
|
@ -35,7 +35,7 @@ function commentClick(e) {
|
|||
e = e || window.event;
|
||||
var targ = e.currentTarget || e.srcElement || e;
|
||||
if (targ.nodeType == 3) targ = targ.parentNode;
|
||||
if (e.target.name=="vote") {
|
||||
if (e.target.name=="submit") {
|
||||
e.preventDefault()
|
||||
var form = e.target.parentNode
|
||||
if (form) {
|
||||
|
|
26
routes.go
26
routes.go
|
@ -860,6 +860,30 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
state.Error = 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":
|
||||
postid, _ := strconv.Atoi(r.FormValue("postid"))
|
||||
post := types.DeletePost{
|
||||
|
@ -900,7 +924,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
case "vote_comment":
|
||||
var score int16
|
||||
score = 1
|
||||
if r.FormValue("vote") != "▲" {
|
||||
if r.FormValue("submit") != "▲" {
|
||||
score = -1
|
||||
}
|
||||
if r.FormValue("undo") == strconv.Itoa(int(score)) {
|
||||
|
|
12
state.go
12
state.go
|
@ -169,6 +169,11 @@ func (state *State) ParseQuery(RawQuery string) {
|
|||
if len(m["xhr"]) > 0 {
|
||||
state.XHR = true
|
||||
}
|
||||
if len(m["view"]) > 0 {
|
||||
if m["view"][0] == "Saved" {
|
||||
state.Op = "Saved"
|
||||
}
|
||||
}
|
||||
//if len(m["op"]) > 0 {
|
||||
// state.Op = m["op"][0]
|
||||
//}
|
||||
|
@ -363,9 +368,10 @@ func (state *State) GetUser(username string) {
|
|||
limit = 1
|
||||
}
|
||||
resp, err := state.Client.PersonDetails(context.Background(), types.GetPersonDetails{
|
||||
Username: types.NewOptional(state.UserName),
|
||||
Page: types.NewOptional(int64(state.Page)),
|
||||
Limit: types.NewOptional(int64(limit)),
|
||||
Username: types.NewOptional(state.UserName),
|
||||
Page: types.NewOptional(int64(state.Page)),
|
||||
Limit: types.NewOptional(int64(limit)),
|
||||
SavedOnly: types.NewOptional(state.Op == "Saved"),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
{{ if .State.Session }}
|
||||
<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">
|
||||
<input type="submit" name="vote" value="▲">
|
||||
<input type="submit" name="submit" value="▲">
|
||||
<div></div>
|
||||
{{ if .P.MyVote.IsValid}}
|
||||
<input type="hidden" name="undo" value="{{.P.MyVote.String}}">
|
||||
{{ end}}
|
||||
<input type="hidden" name="op" value="vote_comment">
|
||||
<input type="hidden" name="commentid" value="{{.P.Comment.ID }}">
|
||||
<input type="submit" name="vote" value="▼">
|
||||
<input type="submit" name="submit" value="▼">
|
||||
</form>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
@ -49,9 +49,8 @@
|
|||
{{ else }}
|
||||
<li><a class="source" for="c{{.P.Comment.ID}}" href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?">hide source</a></li>
|
||||
{{ end }}
|
||||
|
||||
{{ 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>
|
||||
<form class="delete" method="POST">
|
||||
|
@ -61,8 +60,24 @@
|
|||
</form>
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ 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>
|
||||
<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" }}
|
||||
<li>
|
||||
<a class="reply" for="c{{.P.Comment.ID}}" href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?reply">
|
||||
reply
|
||||
</a>
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
|
|
|
@ -48,7 +48,10 @@
|
|||
{{ end }}
|
||||
<ul>
|
||||
{{ 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 -}}
|
||||
<li class="selected"><a href="">comments</a></li>
|
||||
{{ else if .Activities }}
|
||||
|
|
|
@ -54,7 +54,18 @@
|
|||
<input type="submit" value="delete">
|
||||
{{ end }}
|
||||
</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 class="expando {{ if eq .Rank 0 }}open{{ end}}">
|
||||
{{ if (and .Post.Body.IsValid (ne .Post.Body.String "")) }}
|
||||
|
|
Loading…
Reference in a new issue