Skip to content

Commit

Permalink
compact ui + better post css
Browse files Browse the repository at this point in the history
  • Loading branch information
trinkey committed Dec 7, 2024
1 parent 526b744 commit 9f34cae
Show file tree
Hide file tree
Showing 25 changed files with 461 additions and 445 deletions.
7 changes: 5 additions & 2 deletions compile-less.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Run to compile .less files into css. Optionally specify specific files to compile

import os
import sys
from pathlib import Path

CONFIG = {
Expand All @@ -7,6 +10,6 @@
"compress": True
}

for i in os.listdir(CONFIG["in_directory"]):
for i in [i if i.endswith(".less") else f"{i}.less" for i in sys.argv[1::]] or os.listdir(CONFIG["in_directory"]):
os.system(f"lessc {CONFIG['in_directory'] / i} {CONFIG['out_directory'] / i.replace('.less', '.css')} {'--clean-css' if CONFIG['compress'] else ''}")
print(i)
print(i)
16 changes: 4 additions & 12 deletions smiggins/backend/api/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def comment_create(request, data: NewComment) -> APIResponse:
return {
"success": True,
"actions": [
{ "name": "prepend_timeline", "post": get_post_json(comment, user.user_id, True), "comment": True },
{ "name": "prepend_timeline", "post": get_post_json(comment, user, True), "comment": True },
{ "name": "update_element", "query": "#post-text", "value": "" },
{ "name": "update_element", "query": "#c-warning", "value": "", "focus": True }
]
Expand All @@ -121,15 +121,13 @@ def comment_list(request, id: int, comment: bool, sort: str, offset: int=0) -> A
try:
user = User.objects.get(token=token)
lang = get_lang(user)
logged_in = True
except User.DoesNotExist:
if not ENABLE_LOGGED_OUT_CONTENT:
return 400, {
"success": False
}

lang = DEFAULT_LANG
logged_in = False

try:
if id < 0 or (Comment.objects.latest("comment_id").comment_id if comment else Post.objects.latest("post_id").post_id) < id:
Expand All @@ -149,7 +147,6 @@ def comment_list(request, id: int, comment: bool, sort: str, offset: int=0) -> A
else:
parent = Post.objects.get(pk=id)

user_id = user.user_id if logged_in else 0
comments = Comment.objects.filter(comment_id__in=parent.comments)

if sort == "liked":
Expand All @@ -170,19 +167,14 @@ def comment_list(request, id: int, comment: bool, sort: str, offset: int=0) -> A
outputList = []
offset = 0

if logged_in:
self_user = User.objects.get(token=token)
else:
self_user = None

for comment_object in comments:
can_view = can_view_post(self_user, comment_object.creator, comment_object)
can_view = can_view_post(user, comment_object.creator, comment_object)
if can_view[0] is False and (can_view[1] == "blocked" or can_view[1] == "private"):
offset += 1
continue

else:
outputList.append(get_post_json(comment_object, user_id, True))
outputList.append(get_post_json(comment_object, user, True))

if len(outputList) + offset >= POSTS_PER_REQUEST:
break
Expand Down Expand Up @@ -343,7 +335,7 @@ def comment_edit(request, data: EditComment) -> APIResponse:
return {
"success": True,
"actions": [
{ "name": "reset_post_html", "post_id": data.id, "comment": True, "post": get_post_json(data.id, user.user_id, True) }
{ "name": "reset_post_html", "post_id": data.id, "comment": True, "post": get_post_json(data.id, user, True) }
]
}

Expand Down
25 changes: 11 additions & 14 deletions smiggins/backend/api/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def post_create(request, data: NewPost) -> APIResponse:
return {
"success": True,
"actions": [
{ "name": "prepend_timeline", "post": get_post_json(post, user.user_id), "comment": False },
{ "name": "prepend_timeline", "post": get_post_json(post, user), "comment": False },
{ "name": "update_element", "query": "#post-text", "value": "", "disabled": False, "focus": True},
{ "name": "update_element", "query": "#c-warning", "value": "" },
{ "name": "update_element", "query": "#poll input", "value": "", "all": True }
Expand Down Expand Up @@ -280,8 +280,8 @@ def quote_create(request, data: NewQuote) -> APIResponse:
return {
"success": True,
"actions": [
{ "name": "prepend_timeline", "post": get_post_json(post, user.user_id), "comment": False },
{ "name": "update_element", "query": f".post-container[data-{'comment' if data.quote_is_comment else 'post'}-id='{data.quote_id}'] .post-after", "html": "" },
{ "name": "prepend_timeline", "post": get_post_json(post, user), "comment": False },
{ "name": "update_element", "query": f".post-container[data-{'comment' if data.quote_is_comment else 'post'}-id='{data.quote_id}'] .quote-inputs", "html": "" },
{ "name": "update_element", "query": f".post-container[data-{'comment' if data.quote_is_comment else 'post'}-id='{data.quote_id}'] .quote-number", "inc": 1 }
]
}
Expand All @@ -296,9 +296,8 @@ def hashtag_list(request, hashtag: str, sort: str, offset: int=0) -> APIResponse

try:
user = User.objects.get(token=request.COOKIES.get("token"))
user_id = user.user_id
except User.DoesNotExist:
user_id = 0
...

try:
tag = Hashtag.objects.get(tag=hashtag)
Expand All @@ -320,7 +319,7 @@ def hashtag_list(request, hashtag: str, sort: str, offset: int=0) -> APIResponse

offset = 0
for post in posts:
x = get_post_json(post, user_id)
x = get_post_json(post, user)

if "can_view" in x and x["can_view"]:
post_list.append(x)
Expand Down Expand Up @@ -361,7 +360,7 @@ def post_list_following(request, offset: int=-1) -> APIResponse:

for post in combined_posts:
try:
post_json = get_post_json(post, user.user_id)
post_json = get_post_json(post, user)
except Post.DoesNotExist:
offset += 1
continue
Expand Down Expand Up @@ -419,7 +418,7 @@ def post_list_recent(request, offset: int=-1) -> APIResponse:
offset += 1

else:
outputList.append(get_post_json(i, user.user_id))
outputList.append(get_post_json(current_post, user))

i -= 1

Expand All @@ -437,7 +436,6 @@ def post_list_user(request, username: str, offset: int=-1) -> APIResponse:

try:
self_user = User.objects.get(token=request.COOKIES.get("token"))
self_user_id = self_user.user_id
lang = get_lang(self_user)
logged_in = True
except User.DoesNotExist:
Expand All @@ -446,7 +444,6 @@ def post_list_user(request, username: str, offset: int=-1) -> APIResponse:
"success": False
}

self_user_id = 0
lang = DEFAULT_LANG
logged_in = False

Expand All @@ -471,7 +468,7 @@ def post_list_user(request, username: str, offset: int=-1) -> APIResponse:
c = 0
for i in potential:
c += 1
x = get_post_json(i, self_user_id if logged_in else 0)
x = get_post_json(i, self_user if logged_in else 0)

if "private_acc" not in x or not x["private_acc"]:
outputList.append(x)
Expand All @@ -482,7 +479,7 @@ def post_list_user(request, username: str, offset: int=-1) -> APIResponse:
pinned_post = None
if ENABLE_PINNED_POSTS:
if user.pinned:
pinned_post = get_post_json(user.pinned, self_user_id if logged_in else 0, False)
pinned_post = get_post_json(user.pinned, self_user if logged_in else 0, False)

return {
"success": True,
Expand Down Expand Up @@ -684,7 +681,7 @@ def poll_vote(request, data: Poll) -> APIResponse:
return {
"success": True,
"actions": [
{ "name": "reset_post_html", "post_id": data.id, "comment": False, "post": get_post_json(post, user.user_id, False) }
{ "name": "reset_post_html", "post_id": data.id, "comment": False, "post": get_post_json(post, user, False) }
]
}

Expand Down Expand Up @@ -766,7 +763,7 @@ def post_edit(request, data: EditPost) -> APIResponse:
return {
"success": True,
"actions": [
{ "name": "reset_post_html", "post_id": data.id, "comment": False, "post": get_post_json(post, user.user_id, False) }
{ "name": "reset_post_html", "post_id": data.id, "comment": False, "post": get_post_json(post, user, False) }
]
}

Expand Down
15 changes: 12 additions & 3 deletions smiggins/backend/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,16 @@ def read_notifs(request) -> APIResponse:
return {
"success": True,
"actions": [
{ "name": "refresh_timeline", "special": "notifications" }
{ "name": "update_element", "query": ".post[data-notif-unread]", "all": True, "attribute": [
{ "name": "data-notif-unread", "value": None },
{ "name": "data-color", "value": "gray" }
]},
{ "name": "update_element", "query": "hr[data-notif-hr]", "attribute": [
{ "name": "hidden", "value": "" }
]},
{ "name": "update_element", "query": "[data-add-notification-dot]", "set_class": [
{ "class_name": "dot", "enable": False }
]}
]
}

Expand All @@ -523,12 +532,12 @@ def notifications_list(request) -> APIResponse:
}

notifs_list = []
self_id = self_user.user_id

all_notifs = self_user.notifications.all().order_by("-notif_id")

for notification in all_notifs:
try:
x = get_post_json(notification.event_id, self_id, notification.event_type in ["comment", "ping_c"])
x = get_post_json(notification.event_id, self_user, notification.event_type in ["comment", "ping_c"])

if "content" in x:
notifs_list.append({
Expand Down
13 changes: 8 additions & 5 deletions smiggins/backend/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def can_view_post(self_user: User | None, creator: User | None, post: Post | Com

return True,

def get_post_json(post_id: int | Post | Comment, current_user_id: int=0, comment: bool=False) -> dict[str, str | int | dict]:
def get_post_json(post_id: int | Post | Comment, current_user_id: int | User | None=None, comment: bool=False) -> dict[str, str | int | dict]:
# Returns a dict object that includes information about the specified post
# When editing the json content response of this function, make sure you also
# correct the schema in static/ts/globals.d.ts
Expand All @@ -306,10 +306,13 @@ def get_post_json(post_id: int | Post | Comment, current_user_id: int=0, comment

creator = post.creator

try:
user = User.objects.get(user_id=current_user_id)
except User.DoesNotExist:
user = None
if isinstance(current_user_id, int):
try:
user = User.objects.get(user_id=current_user_id)
except User.DoesNotExist:
user = None
else:
user = current_user_id

can_delete_all = user is not None and (current_user_id == OWNER_USER_ID or user.admin_level % 2 == 1)

Expand Down
4 changes: 2 additions & 2 deletions smiggins/backend/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def post(request, post_id: int) -> HttpResponse:
request, "404-post.html", status=404
)

post_json = get_post_json(post_id, user.user_id if user is not None else 0)
post_json = get_post_json(post_id, user)
lang = get_lang(user)
mentions = find_mentions(post.content + " @" + post.creator.username, exclude_users=[user.username if user else ""])
cw = post.content_warning or ""
Expand Down Expand Up @@ -294,7 +294,7 @@ def comment(request, comment_id: int) -> HttpResponse:
request, "404-post.html", status=404
)

comment_json = get_post_json(comment_id, user.user_id if user is not None else 0, True)
comment_json = get_post_json(comment_id, user, True)
lang = get_lang(user if user is not None else None)
mentions = find_mentions(comment.content + " @" + comment.creator.username, exclude_users=[user.username if user else ""])
cw = comment.content_warning or ""
Expand Down
2 changes: 2 additions & 0 deletions smiggins/lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@
"oled": "Black"
},

"cosmetic_compact": "Compact UI?",
"cosmetic_expand": "Always expand content warnings?",

"cosmetic_bar": "Icon bar position",
Expand All @@ -481,6 +482,7 @@
"cosmetic_bar_ll": "Lower left",
"cosmetic_bar_h": "Horizontal",
"cosmetic_bar_v": "Vertical",

"cosmetic_language": "Language",
"cosmetic_color": "Color",
"cosmetic_example_post_display_name": "Example",
Expand Down
4 changes: 2 additions & 2 deletions smiggins/less/fonts.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:root {
--x: "{% load static %}";
some-element-that-doesnt-exist {
content: "{% load static %}";
}

/* Monospace font */
Expand Down
Loading

0 comments on commit 9f34cae

Please sign in to comment.