Display sub list from list in cookie.

Very basic sub list setup. Cookie must be manually added in devtools.
This commit is contained in:
Matthew Crossman 2021-01-30 16:00:55 +11:00
parent 49a6168607
commit 75bbcefbec
No known key found for this signature in database
GPG Key ID: C6B942B019794CC2
10 changed files with 95 additions and 2 deletions

View File

@ -129,6 +129,7 @@ pub struct Preferences {
pub wide: String,
pub hide_nsfw: String,
pub comment_sort: String,
pub subs: Vec<String>,
}
//
@ -144,6 +145,7 @@ pub fn prefs(req: HttpRequest) -> Preferences {
wide: cookie(&req, "wide"),
hide_nsfw: cookie(&req, "hide_nsfw"),
comment_sort: cookie(&req, "comment_sort"),
subs: cookie(&req, "subreddits").split(",").map(|s| s.to_string()).collect(),
}
}

View File

@ -68,6 +68,7 @@ pre, form, fieldset, table, th, td, select, input {
body {
background: var(--background);
font-size: 15px;
padding-top: 60px;
}
nav {
@ -108,7 +109,7 @@ main {
justify-content: center;
max-width: 1000px;
padding: 10px 20px;
margin: 60px auto 20px auto
margin: 0 auto;
}
.wide main {
@ -232,6 +233,45 @@ aside {
color: var(--accent);
}
/* Subscriptions/Favorites */
#sub_subscription {
margin-top: 30px;
}
#sub_subscription > a {
padding: 10px 20px;
border-radius: 5px;
color: var(--foreground);
}
#sub_subscription > .add { color: var(--foreground); background-color: var(--accent); }
#sub_subscription > .remove { color: var(--text); background-color: var(--highlighted); }
#sub_list {
display: flex;
align-items: center;
justify-content: center;
padding: 10px 20px;
}
#subs {
border-radius: 5px;
box-shadow: var(--shadow);
background: var(--outside);
display: flex;
overflow: auto;
}
#subs a {
padding: 10px 20px;
}
#subs > .selected {
background-color: var(--accent);
color: var(--foreground);
}
/* Wiki Pages */
#wiki {
@ -954,10 +994,12 @@ td, th {
}
@media screen and (max-width: 800px) {
body { padding-top: 100px }
main {
flex-direction: column-reverse;
padding: 10px;
margin: 100px 0 10px 0;
margin: 0 0 10px 0;
max-width: 100%;
}
@ -967,6 +1009,8 @@ td, th {
width: calc(100% - 20px);
}
#sub_list { padding: 10px; }
aside, #subreddit, #user {
margin: 0;
max-width: 100%;

View File

@ -27,6 +27,10 @@
<a id="code" href="https://github.com/spikecodes/libreddit">code</a>
</nav>
<!-- SUBSCRIBED SUBREDDITS -->
{% block sub_list %}
{% endblock %}
<!-- MAIN CONTENT -->
{% block body %}
<main>

View File

@ -13,6 +13,10 @@
<meta name="author" content="u/{{ post.author.name }}">
{% endblock %}
{% block sub_list %}
{% call utils::sub_list(post.community.as_str()) %}
{% endblock %}
<!-- OPEN COMMENT MACRO -->
{% macro comment(item) -%}
<div id="{{ item.id }}" class="comment">

View File

@ -3,6 +3,10 @@
{% block title %}Libreddit: search results - {{ params.q }}{% endblock %}
{% block sub_list %}
{% call utils::sub_list("") %}
{% endblock %}
{% block content %}
<div id="column_one">
<form id="search_sort">

View File

@ -7,6 +7,10 @@
{% call utils::search("".to_owned(), "", "") %}
{% endblock %}
{% block sub_list %}
{% call utils::sub_list("") %}
{% endblock %}
{% block content %}
<form id="settings" action="/settings" method="POST">
<div id="prefs">

View File

@ -11,6 +11,10 @@
{% call utils::search(["/r/", sub.name.as_str()].concat(), "") %}
{% endblock %}
{% block sub_list %}
{% call utils::sub_list(sub.name.as_str()) %}
{% endblock %}
{% block body %}
<main>
<div id="column_one">
@ -121,6 +125,13 @@
<div>{{ sub.members }}</div>
<div>{{ sub.active }}</div>
</div>
<div id="sub_subscription">
{% if prefs.subs.contains(sub.name) %}
<a class="subscribe remove">Unsubscribe</a>
{% else %}
<a class="subscribe add">Subscribe</a>
{% endif %}
</div>
</div>
</div>
<details class="panel" id="sidebar">

View File

@ -7,6 +7,10 @@
{% block title %}{{ user.name.replace("u/", "") }} (u/{{ user.name }}) - Libreddit{% endblock %}
{% block sub_list %}
{% call utils::sub_list("") %}
{% endblock %}
{% block body %}
<main>
<div id="column_one">

View File

@ -39,3 +39,15 @@
{% else if flair_part.flair_part_type == "text" %}<span>{{ flair_part.value }}</span>{% endif %}
{% endfor %}
{%- endmacro %}
{% macro sub_list(current) -%}
{% if prefs.subs.len() > 0 %}
<div id="sub_list">
<div id="subs">
{% for sub in prefs.subs %}
<a href="/r/{{ sub }}" {% if sub == current %}class="selected"{% endif %}>{{ sub }}</a>
{% endfor %}
</div>
</div>
{% endif %}
{%- endmacro %}

View File

@ -10,6 +10,10 @@
{% call utils::search(["/r/", sub.as_str()].concat(), "") %}
{% endblock %}
{% block sub_list %}
{% call utils::sub_list(sub.as_str()) %}
{% endblock %}
{% block body %}
<main>
<div class="panel" id="column_one">