distinguished posts/comemnts, nsfw blue/warnings

This commit is contained in:
Ryan Stafford 2023-07-05 09:49:41 -04:00
parent 1e0f1fc184
commit 6184bddd02
8 changed files with 138 additions and 59 deletions

View file

@ -24,6 +24,14 @@ code {
.clearleft {
clear: left;
}
.img-blur {
filter: blur(10px);
-webkit-filter: blur(10px);
-moz-filter: blur(10px);
-o-filter: blur(10px);
-ms-filter: blur(10px);
transform: scale(1.03);
}
.post {
margin: 6px;
}
@ -31,10 +39,16 @@ code {
height: 52px;
width: 70px;
margin: 0px 4px;
position: relative;
overflow: hidden;
--background-color: #e7e7e7;
}
.post .thumb div {
height: 52px;
width: 70px;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
--background-color: #e7e7e7;
}
.rank {
color: #c6c6c6;
@ -94,6 +108,10 @@ code {
font-size: medium;
text-decoration: none;
}
.post.distinguished .title a {
color: #228822;
font-weight: bold;
}
.dark .title a {
color: #dedede;
}
@ -207,6 +225,13 @@ code {
border-radius: 3px;
padding: 0px 2px;
}
.comment .meta a.distinguished {
background-color: #228822;
color: white;
font-weight: bold;
border-radius: 3px;
padding: 0px 2px;
}
.commentmenu {
font-size: 16px;
margin: 0px 0px 10px 10px;
@ -281,6 +306,31 @@ code {
.left {
float: left;
}
span.nsfw {
color: #d10023;
font-size: 10px;
line-height: 14px;
border-radius:3px;
border: 1px solid #d10023;
padding: 0 4px;
display: inline-block;
font-weight: 400;
}
form.nsfw {
text-align: center;
margin: 50px auto;
width: 650px;
font-size: 18px;
}
form.nsfw div {
font-size: 40px;
background-color: #ff575b;
display: inline-block;
padding: 20px 10px;
border-radius: 50%;
font-weight: bold;
color: white;
}
.gray {
color: #808080;
}
@ -843,13 +893,16 @@ form.create input[type=file], form.create select {
content: "*";
color: red;
}
.preferences {
margin: 20px;
}
.preferences div {
font-size: 13px;
margin: 10px;
}
.preferences label{
display: inline-block;
width: 100px;
width: 120px;
text-align: right;
}

View file

@ -170,6 +170,7 @@ func Initialize(Host string, r *http.Request) (State, error) {
state.Listing = getCookie(r, "DefaultListingType")
state.Sort = getCookie(r, "DefaultSortType")
state.Dark = getCookie(r, "Dark") != ""
state.ShowNSFW = getCookie(r, "ShowNSFW") != ""
state.ParseQuery(r.URL.RawQuery)
if state.Sort == "" {
state.Sort = "Hot"
@ -497,11 +498,19 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
deleteCookie(w, state.Host, "Dark")
state.Dark = false
}
if r.FormValue("shownsfw") != "" {
setCookie(w, state.Host, "ShowNSFW", "1")
state.ShowNSFW = true
} else {
deleteCookie(w, state.Host, "ShowNSFW")
state.ShowNSFW = false
}
state.Listing = r.FormValue("DefaultListingType")
state.Sort = r.FormValue("DefaultSortType")
// TODO save user settings
case "GET":
if state.Session != nil {
// TODO fetch server settings
// TODO fetch user settings
}
}
Render(w, "settings.html", state)
@ -540,6 +549,7 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
if resp.JWT.IsValid() {
token = resp.JWT.String()
username = r.FormValue("username")
deleteCookie(w, state.Host, "ShowNSFW")
}
case "sign up":
register := types.Register{
@ -959,6 +969,12 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
r.URL.Fragment = "c" + commentid
r.URL.RawQuery = ""
}
case "shownsfw":
if r.FormValue("submit") == "continue" {
setCookie(w, state.Host, "ShowNSFW", "1")
} else {
r.URL.Path = "/" + state.Host
}
}
http.Redirect(w, r, r.URL.String(), 301)
}

View file

@ -88,6 +88,7 @@ type State struct {
SearchType string
Captcha *types.CaptchaResponse
Dark bool
ShowNSFW bool
}
func (p State) SortBy(v string) string {

View file

@ -21,7 +21,7 @@
[-]
{{ end }}
</a>
<a {{if .Submitter }}class="submitter"{{end}} href="/{{.State.Host}}/u/{{fullname .P.Creator}}">{{fullname .P.Creator}}</a>
<a {{ if .P.Comment.Distinguished}}class="distinguished"{{ else if .Submitter }}class="submitter"{{end}} href="/{{.State.Host}}/u/{{fullname .P.Creator}}">{{fullname .P.Creator}}</a>
{{.P.Counts.Score}} points <span title="{{.P.Comment.Published.Time}}">{{ humanize .P.Comment.Published.Time }}</span>
{{- if gt .P.Comment.Updated.Time.Unix .P.Comment.Published.Time.Unix -}}
* (last edited <span title="{{.P.Comment.Updated.Time}}">{{ humanize .P.Comment.Updated.Time }}</span>)

View file

@ -18,32 +18,36 @@
</noscript>
{{ template "nav.html" . -}}
{{ if and (not .ShowNSFW) .Community .Community.CommunityView.Community.NSFW }}
{{ template "nsfw.html" }}
{{ else }}
<main>
{{ if or (contains .Sort "Top") (and (not .PostID) (not .User) (not .Community) (not .Activities) (eq .Op ""))}}
{{ template "menu.html" . }}
{{ end}}
{{ if or (contains .Sort "Top") (and (not .PostID) (not .User) (not .Community) (not .Activities) (eq .Op ""))}}
{{ template "menu.html" . }}
{{ end}}
{{ if .Error }}
{{ if .Error }}
<div class="error">{{.Error}}</div>
{{ end }}
{{ end }}
{{ range .Posts }}
{{ template "post.html" . }}
{{ end }}
{{ range .Posts }}
{{ template "post.html" . }}
{{ end }}
{{ if or (and (not .Op) (not .Activities) (not .Comments) (not .Posts) (not .Communities)) (and (not .Comments) .PostID) (and (not .Activities) (not .Query) .User) }}
<div class="error">there doesn't seem to be anything here</div>
{{ end }}
{{ if or (and (not .Op) (not .Activities) (not .Comments) (not .Posts) (not .Communities)) (and (not .Comments) .PostID) (and (not .Activities) (not .Query) .User) }}
<div class="error">there doesn't seem to be anything here</div>
{{ end }}
{{ if or .Query (eq .SearchType "Communities") (eq (len .Posts) 25) (and .Comments (and (eq .CommentCount 200) (gt (index .Posts 0).Counts.Comments .CommentCount))) (and .User (or (gt .User.PersonView.Counts.CommentCount 10) (gt .User.PersonView.Counts.PostCount 10))) }}
<div class="pager">
view more: {{if gt .Page 1 }}<a href="{{ .PrevPage }}"> prev</a>{{ end }} <a href="{{ .NextPage }}">next </a>
</div>
{{ end }}
{{ if or .Query (eq .SearchType "Communities") (eq (len .Posts) 25) (and .Comments (and (eq .CommentCount 200) (gt (index .Posts 0).Counts.Comments .CommentCount))) (and .User (or (gt .User.PersonView.Counts.CommentCount 10) (gt .User.PersonView.Counts.PostCount 10))) }}
<div class="pager">
view more: {{if gt .Page 1 }}<a href="{{ .PrevPage }}"> prev</a>{{ end }} <a href="{{ .NextPage }}">next </a>
</div>
{{ end }}
{{ template "sidebar.html" . }}
{{ template "sidebar.html" . }}
</main>
{{ end }}
<script src="/_/static/utils.js?1"></script>
</body>
</html>

View file

@ -18,12 +18,15 @@
</noscript>
{{ template "nav.html" . -}}
{{ if and (not .ShowNSFW) .Community .Community.CommunityView.Community.NSFW }}
{{ template "nsfw.html" }}
{{ else }}
<main>
{{ if or (contains .Sort "Top") (and (not .PostID) (not .User) (not .Community) (not .Activities) (eq .Op ""))}}
{{ if or (contains .Sort "Top") (and (not .PostID) (not .User) (not .Community) (not .Activities) (eq .Op ""))}}
{{ template "menu.html" . }}
{{ end}}
{{ end}}
{{ if or (ne .Query "") .Communities }}
{{ if or (ne .Query "") .Communities }}
<form class="search" method="GET">
<div>search</div>
<div class="query">
@ -45,34 +48,34 @@
<input type="hidden" name="searchtype" value="Communities">
{{ end }}
</form>
{{ end}}
{{ end}}
{{ if .Error }}
{{ if .Error }}
<div class="error">{{.Error}}</div>
{{ end }}
{{ end }}
{{ range .Communities }}
{{ range .Communities }}
{{ template "community.html" . }}
{{ end }}
{{ end }}
{{ if eq .Op "create_community" "edit_community" }}
{{ template "create_community.html" . }}
{{ end }}
{{ if eq .Op "create_community" "edit_community" }}
{{ template "create_community.html" . }}
{{ end }}
{{ range .Posts }}
{{ range .Posts }}
{{ template "post.html" . }}
{{ end }}
{{ end }}
{{ if eq .Op "create_post" "edit_post" }}
{{ template "create_post.html" . }}
{{ end }}
{{ if eq .Op "create_post" "edit_post" }}
{{ template "create_post.html" . }}
{{ end }}
{{ if and .PostID .Posts}}
{{ if .CommentID}}
{{ if and .PostID .Posts}}
{{ if .CommentID}}
<div class="warning">you are viewing a single comment's thread<br>
<a href="../post/{{.PostID}}/#c{{.CommentID}}">view the rest of the comments</a>
</div>
{{ else }}
{{ else }}
<div class="commentmenu">
{{if .Comments}}{{if gt .Page 1}}next{{else if or (lt .CommentCount 200) (lt (index .Posts 0).Counts.Comments .CommentCount) }}all{{else}}top{{end}} {{.CommentCount}} comments{{else}} no comments (yet){{end}}
<div>
@ -83,7 +86,7 @@
<a {{ if eq .Sort "Old"}}class="selected"{{end}} href="{{ .SortBy "Old"}}">old</a>
</div>
</div>
{{ if and .Session (ne .Op "edit_post") }}
{{ if and .Session (ne .Op "edit_post") }}
<form class="savecomment" method="POST">
<div>
<textarea required name="content" {{ if (index .Posts 0).Post.Deleted }} disabled {{end}}></textarea>
@ -91,34 +94,35 @@
<input type="hidden" name="op" value="create_comment">
<input type="submit" value="save"{{ if (index .Posts 0).Post.Deleted }} disabled {{end}}>
</form>
{{ end }}
{{ end }}
{{ end }}
{{ end}}
{{ end}}
{{ range $i, $comment := .Comments }}
{{ range $i, $comment := .Comments }}
{{ template "comment.html" $comment }}
{{ end }}
{{ end }}
{{ if eq .Op "send_message" }}
{{ template "send_message.html" . }}
{{ else }}
{{ template "activities.html" . }}
{{ end }}
{{ if eq .Op "send_message" }}
{{ template "send_message.html" . }}
{{ else }}
{{ template "activities.html" . }}
{{ end }}
{{ if or (and (not .Op) (not .Activities) (not .Comments) (not .Posts) (not .Communities)) (and (not .Comments) .PostID) (and (not .Activities) (not .Query) .User) }}
<div class="error">there doesn't seem to be anything here</div>
{{ end }}
{{ if or (and (not .Op) (not .Activities) (not .Comments) (not .Posts) (not .Communities)) (and (not .Comments) .PostID) (and (not .Activities) (not .Query) .User) }}
<div class="error">there doesn't seem to be anything here</div>
{{ end }}
{{ if or .Query (eq .SearchType "Communities") (eq (len .Posts) 25) (and .Comments (and (eq .CommentCount 200) (gt (index .Posts 0).Counts.Comments .CommentCount))) (and .User (or (gt .User.PersonView.Counts.CommentCount 10) (gt .User.PersonView.Counts.PostCount 10))) }}
{{ if or .Query (eq .SearchType "Communities") (eq (len .Posts) 25) (and .Comments (and (eq .CommentCount 200) (gt (index .Posts 0).Counts.Comments .CommentCount))) (and .User (or (gt .User.PersonView.Counts.CommentCount 10) (gt .User.PersonView.Counts.PostCount 10))) }}
<div class="pager">
view more: {{if gt .Page 1 }}<a href="{{ .PrevPage }}"> prev</a>{{ end }} <a href="{{ .NextPage }}">next </a>
</div>
{{ end }}
{{ end }}
<script src="/_/static/utils.js?1"></script>
{{ template "sidebar.html" . }}
</main>
{{ end }}
</body>
</html>

View file

@ -1,5 +1,5 @@
{{ if not .State.XHR }}
<div class="post {{if .Post.Deleted}}deleted{{end}}" onclick="postClick(event)">
<div class="post{{if .Post.Deleted}} deleted{{end}}{{ if or .Post.FeaturedCommunity .Post.FeaturedLocal }} distinguished{{end}}" onclick="postClick(event)">
{{ if gt .Rank 0 }}
<div class="rank"> {{ .Rank }} </div>
{{ end }}
@ -21,13 +21,12 @@
{{ end }}
{{ if not .State.XHR}}
</div>
<div class="thumb" style="background-image: url({{if .Post.ThumbnailURL.IsValid}}{{.Post.ThumbnailURL.String}}?format=jpg&thumbnail=96{{else if .Post.URL.IsValid}}/_/static/link.png{{else}}/_/static/text.png{{end}})"></div>
<div class="thumb"><div {{ if and .Post.NSFW (not (and .State.Community .State.Community.CommunityView.Community.NSFW))}}class="img-blur"{{end}} style="background-image: url({{if .Post.ThumbnailURL.IsValid}}{{.Post.ThumbnailURL.String}}?format=jpg&thumbnail=96{{else if .Post.URL.IsValid}}/_/static/link.png{{else}}/_/static/text.png{{end}})"></div></div>
<div class="entry">
<div class="title">
<a class="url" href="{{ if .Post.URL.IsValid }}{{ .Post.URL }}{{ else }}/{{ .State.Host }}/post/{{ .Post.ID }}{{ end }}">{{ .Post.Name }}</a>
({{ domain . }})
</div>
<div class="expando-button {{ if and (not (and .Post.Body.IsValid .Post.Body.String )) (not (isImage .Post.URL.String)) }}hidden{{else if eq .Rank 0}}open{{ end }}"></div>
<div class="meta">
submitted
@ -41,8 +40,9 @@
<a href="/{{ .State.Host }}/c/{{ fullcname .Community }}">c/{{ fullcname .Community}}</a>
</div>
<div class="buttons">
{{ if .Post.NSFW }}<span class="nsfw">NSFW</span>{{end}}
<a href="/{{ .State.Host }}/post/{{ .Post.ID }}">{{ .Counts.Comments }} comments</a>
{{ if and .State.Session (eq .State.Session.UserID .Post.CreatorID) }}
{{ if and .State.Session (eq .State.Session.UserID .Post.CreatorID) }}
{{ if not .Post.Deleted }}<a href="/{{ .State.Host }}/post/{{ .Post.ID }}?edit">edit</a>{{end}}
<form class="link-btn" method="POST">
<input type="hidden" name="postid" value="{{.Post.ID }}">

View file

@ -89,6 +89,7 @@
dark mode
</label>
<input type="checkbox" name="darkmode" {{ if .Dark }}checked{{end}}>
</div>
<div>
<label></label>
<input type="submit" value="save">