wip notification view
This commit is contained in:
parent
af557ffc6e
commit
12ae7504a0
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-bell"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"></path><path d="M13.73 21a2 2 0 0 1-3.46 0"></path></svg>
|
After Width: | Height: | Size: 321 B |
|
@ -14,14 +14,17 @@
|
|||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
|
||||
background-color: #fff;
|
||||
color: #111;
|
||||
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
|
||||
--accent-color: rgb(245, 141, 210);
|
||||
--accent-color-bri: rgb(255, 191, 234);
|
||||
accent-color: var(--accent-color);
|
||||
|
||||
--text-color: #111;
|
||||
--background-color: #fff;
|
||||
|
||||
background-color: var(--background-color);
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
::selection {
|
||||
|
@ -47,8 +50,8 @@ a:hover {
|
|||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
background-color: #111;
|
||||
color: #fff;
|
||||
--text-color: #fff;
|
||||
--background-color: #111;
|
||||
}
|
||||
|
||||
.dim {
|
||||
|
@ -112,4 +115,37 @@ pre {
|
|||
|
||||
.error {
|
||||
color: #f33;
|
||||
}
|
||||
|
||||
.circle-button {
|
||||
border-radius: 10px;
|
||||
border: 1px solid var(--accent-color);
|
||||
color: var(--accent-color);
|
||||
transition: 0.1s border-color, 0.1s color;
|
||||
padding: 0.5em;
|
||||
margin: 0.5em;
|
||||
height: 48px;
|
||||
width: 48px;
|
||||
}
|
||||
.circle-button:hover {
|
||||
border-color: var(--accent-color-bri);
|
||||
color: var(--accent-color-bri);
|
||||
}
|
||||
.circle-button > svg, .circle-button > img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
@media (max-width: 650px) {
|
||||
/* mobile layout gets bigger buttons */
|
||||
.circle-button {
|
||||
height: 54px;
|
||||
width: 54px;
|
||||
}
|
||||
}
|
||||
|
||||
.circle-button.notifications-unread > svg {
|
||||
fill: currentColor;
|
||||
}
|
|
@ -21,7 +21,6 @@
|
|||
color: #000;
|
||||
border-radius: 1.5em;
|
||||
padding: 1em;
|
||||
margin: 1em;
|
||||
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
@ -85,26 +84,48 @@
|
|||
margin: auto;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.header {
|
||||
height: 96px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 1em;
|
||||
margin: 1em;
|
||||
}
|
||||
.header > .greeting {
|
||||
flex: 1 1 0px;
|
||||
min-width: 0;
|
||||
}
|
||||
.header > .circle-button {
|
||||
flex: 0 0 auto;
|
||||
max-width: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<a href="/"><img src="/favicon.png" width="64" height="auto" class="spinny favicon"></a><br>
|
||||
|
||||
<div class="greeting">
|
||||
<img src="https://gdicon.oat.zone/icon.png?type=<%=type_str%>&value=<%=icon_value%>&color1=<%=color1%>&color2=<%=color2%><%=glow ? "&glow=1" : ""%>" width="150" height="150" class="greeting-l">
|
||||
<div class="greeting-r">
|
||||
<div class="greeting-top">
|
||||
<div class="greeting-top-left">
|
||||
hewwo, <b><%= username %></b>!
|
||||
<div class="header">
|
||||
<div class="greeting">
|
||||
<img src="https://gdicon.oat.zone/icon.png?type=<%=type_str%>&value=<%=icon_value%>&color1=<%=color1%>&color2=<%=color2%><%=glow ? "&glow=1" : ""%>" width="150" height="150" class="greeting-l">
|
||||
<div class="greeting-r">
|
||||
<div class="greeting-top">
|
||||
<div class="greeting-top-left">
|
||||
hewwo, <b><%= username %></b>!
|
||||
</div>
|
||||
<div class="greeting-stats">
|
||||
<%= stars %> <img src="https://gdbrowser.com/assets/star.png"> <%= diamonds %> <img src="https://gdbrowser.com/assets/diamond.png"> <%= coins %> <img src="https://gdbrowser.com/assets/coin.png"> <%= user_coins %> <img src="https://gdbrowser.com/assets/silvercoin.png"> <%= demons %> <img src="https://gdbrowser.com/assets/demon.png">
|
||||
</div>
|
||||
</div>
|
||||
<div class="greeting-stats">
|
||||
<%= stars %> <img src="https://gdbrowser.com/assets/star.png"> <%= diamonds %> <img src="https://gdbrowser.com/assets/diamond.png"> <%= coins %> <img src="https://gdbrowser.com/assets/coin.png"> <%= user_coins %> <img src="https://gdbrowser.com/assets/silvercoin.png"> <%= demons %> <img src="https://gdbrowser.com/assets/demon.png">
|
||||
<div class="greeting-bottom">
|
||||
<a href="/accounts/settings">Settings</a> · <a>Log out</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="greeting-bottom">
|
||||
<a href="/accounts/settings">Settings</a> · <a>Log out</a>
|
||||
</div>
|
||||
</div>
|
||||
<a href="/accounts/notifications/" title="Notifiations" class="circle-button notifications <%= unread_notifications ? "notifications-unread" : "" %>">
|
||||
<%= File.read("public/assets/icons/bell.svg") %>
|
||||
</a>
|
||||
</div>
|
||||
<br><br>
|
||||
blablabla lorem ipsum whatever. put stuff here later
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/png" href="/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="/style.css" />
|
||||
<title>Account Management</title>
|
||||
<style>
|
||||
body {
|
||||
max-width: 800px;
|
||||
margin: auto;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
.header {
|
||||
height: 96px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: x-large;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 0.5em;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<a href="/accounts/" title="<%=username%>" class="circle-button">
|
||||
<img src="https://gdicon.oat.zone/icon.png?type=<%=type_str%>&value=<%=icon_value%>&color1=<%=color1%>&color2=<%=color2%><%=glow ? "&glow=1" : ""%>" class="icon">
|
||||
</a>
|
||||
<span class="title">
|
||||
<a href="/"><img src="/favicon.png" width="64" height="auto" class="spinny favicon"></a>
|
||||
Notifications
|
||||
</span>
|
||||
<a href="/accounts/notifications/" title="Notifiations" class="circle-button notifications <%= unread_notifications ? "notifications-unread" : "" %>">
|
||||
<%= # todo: unhardcode public dir location
|
||||
File.read("public/assets/icons/bell.svg") %>
|
||||
</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -109,12 +109,12 @@ CrystalGauntlet.endpoints["/suggestGJStars20.php"] = ->(context : HTTP::Server::
|
|||
stars = params["stars"].to_i
|
||||
difficulty = stars_to_difficulty(params["stars"].to_i) || LevelDifficulty::Easy
|
||||
|
||||
author_account_id = DATABASE.query_one("select users.account_id from levels left join users on users.id = levels.user_id where levels.id = ?", level_id, as: {Int32?})
|
||||
author_account_id, level_name = DATABASE.query_one("select users.account_id, levels.name from levels left join users on users.id = levels.user_id where levels.id = ?", level_id, as: {Int32?, String})
|
||||
if author_account_id
|
||||
notif_type = params["feature"] == "1" ? "authored_level_featured" : "authored_level_rated"
|
||||
|
||||
Notifications.clear_previous_notifications(author_account_id, notif_type, level_id)
|
||||
Notifications.send_notification(author_account_id, notif_type, level_id, {"stars" => stars.to_i64, "difficulty" => difficulty.to_i64})
|
||||
Notifications.send_notification(author_account_id, notif_type, level_id, {"stars" => stars.to_i64, "difficulty" => difficulty.to_i64, "level_name" => level_name})
|
||||
end
|
||||
|
||||
DATABASE.exec "update levels set stars = ?, featured = ?, difficulty = ? where id = ?", stars, params["feature"].to_i, difficulty.to_i, level_id
|
||||
|
|
|
@ -5,13 +5,34 @@ include CrystalGauntlet
|
|||
module CrystalGauntlet::Notifications
|
||||
extend self
|
||||
|
||||
alias NotificationValue = Hash(String, String | Int64 | Bool | Float64 | Nil)
|
||||
alias NotificationDetails = Hash(String, String | Int64 | Bool | Float64 | Nil)
|
||||
|
||||
def clear_previous_notifications(account_id : Int32, type : String, target : Int32)
|
||||
DATABASE.exec("delete from notifications where account_id = ? and type = ? and target = ?", account_id, type, target)
|
||||
end
|
||||
|
||||
def send_notification(account_id : Int32, type : String, target : Int32?, details : NotificationValue? = nil)
|
||||
def send_notification(account_id : Int32, type : String, target : Int32?, details : NotificationDetails? = nil)
|
||||
DATABASE.exec("insert into notifications (id, account_id, type, target, details) values (?, ?, ?, ?, ?)", IDs.get_next_id("notifications"), account_id, type, target, details.try &.to_json || "{}")
|
||||
end
|
||||
|
||||
NOTIFICATION_STRINGS = {
|
||||
"authored_level_featured" => %(Your level <b>%{level_name}</b> has been featured!),
|
||||
"authored_level_rated" => %(Your level <b>%{level_name}</b> has been rated!)
|
||||
}
|
||||
|
||||
def format_notification(type : String, target : Int32, details : NotificationDetails? = nil, html_safe : Bool = false)
|
||||
details = details || {} of String => String | Int64 | Bool | Float64 | Nil
|
||||
string = NOTIFICATION_STRINGS[type]
|
||||
|
||||
#case type
|
||||
#when "authored_level_featured", "authored_level_rated"
|
||||
# details["action"] = (type == "authored_level_featured") ? "featured" : "rated"
|
||||
#end
|
||||
|
||||
if html_safe
|
||||
string % details.transform_values ->HTML.escape
|
||||
else
|
||||
string % details
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,7 @@ CrystalGauntlet.template_endpoints["/#{config_get("general.append_path").as(Stri
|
|||
CrystalGauntlet.template_endpoints["/accounts"] = ->(context : HTTP::Server::Context) {
|
||||
context.response.content_type = "text/html"
|
||||
|
||||
account_id = nil
|
||||
user_id = nil
|
||||
username = nil
|
||||
Templates.auth()
|
||||
|
@ -17,5 +18,7 @@ CrystalGauntlet.template_endpoints["/accounts"] = ->(context : HTTP::Server::Con
|
|||
icon_value = [cube, ship, ball, ufo, wave, robot, spider][icon_type]
|
||||
type_str = ["cube", "ship", "ball", "ufo", "wave", "robot", "spider"][icon_type]
|
||||
|
||||
unread_notifications = DATABASE.scalar("select count(*) from notifications where account_id = ? and read_at is null", account_id).as(Int64) > 0
|
||||
|
||||
ECR.embed("./public/template/account_management.ecr", context.response)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
include CrystalGauntlet
|
||||
|
||||
CrystalGauntlet.template_endpoints["/accounts/notifications"] = ->(context : HTTP::Server::Context) {
|
||||
context.response.content_type = "text/html"
|
||||
|
||||
account_id = nil
|
||||
user_id = nil
|
||||
username = nil
|
||||
Templates.auth()
|
||||
|
||||
icon_type, color1, color2, cube, ship, ball, ufo, wave, robot, spider, glow = DATABASE.query_one("select icon_type, color1, color2, cube, ship, ball, ufo, wave, robot, spider, glow from users where id = ?", user_id, as: {Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32})
|
||||
|
||||
icon_value = [cube, ship, ball, ufo, wave, robot, spider][icon_type]
|
||||
type_str = ["cube", "ship", "ball", "ufo", "wave", "robot", "spider"][icon_type]
|
||||
|
||||
notification_count = DATABASE.scalar("select count(*) from notifications where account_id = ? and read_at is null", account_id).as(Int64)
|
||||
unread_notifications = notification_count > 0
|
||||
|
||||
ECR.embed("./public/template/notifications.ecr", context.response)
|
||||
}
|
Loading…
Reference in New Issue