feat: full page for thread

This commit is contained in:
Ayo Ayco 2024-04-25 14:43:38 +02:00
parent 5f4971f7c5
commit d25a2dd6b3
2 changed files with 47 additions and 31 deletions

View file

@ -22,19 +22,7 @@
color: white;
}
}
main {
& p, & img, & video {
margin-top: 5px;
}
}
summary:hover {
text-decoration: underline;
}
summary {
color: blue;
cursor: pointer;
margin-top: 1em;
}
ul {
list-style: none;
}
@ -62,6 +50,10 @@
content: '...'
}
& img, & video, & p {
margin-bottom: 1em;
}
& img, & video {
border-radius: 5px;
max-width: 100%;
@ -81,6 +73,13 @@
}
}
& .action {
color: blue;
margin: 1em 0;
cursor: pointer;
margin-top: 1em;
}
}
.card_avatar img {
@ -99,6 +98,7 @@
<p>See the <a href="https://ayco.io/sh/threads">source code</a>. Or <a href="/">go home</a>.</p>
</header>
<main>
<ul>
{% for thread in threads %}
<li class="card">
@ -111,9 +111,7 @@
<div class="card_content">
<div class="meta">
<a href="{{thread.url}}" target="_blank">{{ thread.created_at }}</a>
</div>
{{thread.content | safe}}
{% for media in thread.media_attachments %}
@ -127,8 +125,11 @@
{% endif %}
{% endfor %}
<details>
<summary>See more ({{ thread.descendants | length }})</summary>
{% if thread.descendants %}
<div class="meta">
<a href="{{thread.url}}" target="_blank">{{ thread.created_at }}</a>
</div>
<ul>
{% for descendant in thread.descendants %}
<li class="card descendant">
@ -139,9 +140,6 @@
</div>
<div class="card_content">
<div class="meta">
<a href="{{descendant.url}}" target="_blank">{{ descendant.created_at }}</a>
</div>
{{ descendant.content | safe }}
{% for media in descendant.media_attachments%}
{% if media.type == 'image'%}
@ -153,11 +151,17 @@
</video>
{% endif %}
{% endfor %}
<div class="meta">
<a href="{{descendant.url}}" target="_blank">{{ descendant.created_at }}</a>
</div>
</div>
<li>
{% endfor %}
</ul>
</details>
{% else %}
<a class="action" href="{{ url_for('threads.thread', id=thread.id) }}">Read full thread</a>
{% endif %}
</div>
</li>

View file

@ -7,24 +7,36 @@ threads = Blueprint('threads', __name__, template_folder='template')
server = 'https://social.ayco.io'
thread_ids = ['112319729193615365', '112258065967208438']
# TODO: fetch only parent statuses
@threads.route('/')
def home():
threads = fetch_threads();
return render_template('threads.html', threads=threads)
statuses = fetch_statuses()
return render_template('threads.html', threads=statuses)
# TODO: given parent status id, show page for full thread
@threads.route('/<path:id>')
def thread(id):
thread = fetch_thread(id)
return thread
@threads.route('/api')
def api():
threads = fetch_threads();
return threads;
return fetch_threads();
def fetch_threads():
threads = []
def fetch_statuses():
statuses = []
for id in thread_ids:
status = requests.get(server + '/api/v1/statuses/' + id ).json()
status = clean_status(status)
status['descendants'] = get_descendants(server, status)
threads.append(status)
return threads
statuses.append(status)
return statuses
def fetch_thread(id):
status = requests.get(server + '/api/v1/statuses/' + id ).json()
status = clean_status(status)
status['descendants'] = get_descendants(server, status)
return render_template('threads.html', threads=[status])
def get_descendants(server, status):
author_id = status['account']['id']