2025-02-16 16:38:57 +02:00

90 lines
4.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
<title>{{ username }} posts</title>
</head>
<body>
<h1>{{ username }} Posts</h1>
{% if posts %}
<div class="posts">
{% for post in posts %}
<div class="post">
<p class="post-date"><strong>{{ post.post_date.strftime('%Y-%m-%d %H:%M') }}</strong></p>
<p class="post-text">{{ post.text }}</p>
{% if post.media_file %}
<div class="post-media">
<img src="{{ url_for('static', filename='posts/' + post.media_file) }}"
alt="{{ 'GIF' if post.media_file.endswith('.gif') else 'Image' }}"
class="{{ 'gif' if post.media_file.endswith('.gif') else 'image' }}">
</div>
{% endif %}
{% if post.username == current_user.username %}
<form action="{{ url_for('delete_post', post_id=post.id) }}" method="POST" style="display:inline;">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="button" onclick="return confirmDelete()">Delete</button>
</form>
{% endif %}
<section class="comments">
<h2>Comments</h2>
<div class="comments-list">
{% for comment in post.comments %}
<div class="comment">
<a href="{{ url_for('profile', username=comment.username) }}">
<img src="{{ url_for('static', filename='avatars/' + (avatars.get(comment.username) if avatars.get(comment.username) else 'default_avatar.png')) }}"
alt="Avatar of {{ comment.username }}" class="avatar">
<div class="content">
<p>
<a href="{{ url_for('profile', username=comment.username) }}" class="username-link">
<strong>{{ comment.username }}</strong>
</a>
({{ comment.comment_date.strftime('%Y-%m-%d %H:%M') }}):
</p>
<p style="margin-top: 10px;">{{ comment.comment_text }}</p>
</div>
</a>
{% if comment.username == current_user.username %}
<form action="{{ url_for('delete_comment', comment_id=comment.id) }}" method="POST" style="display:inline;">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="delete-button" onclick="return confirm('Are you sure you want to delete this comment?')">Delete</button>
</form>
{% endif %}
</div>
{% else %}
<p>No comments yet. Be the first to comment!</p>
{% endfor %}
</div>
{% if current_user.is_authenticated %}
<form action="{{ url_for('add_comment', username=current_user.username, post_id=post.id) }}" method="POST" class="comment-form">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<textarea name="comment_text" rows="3" maxlength="200" class="input-field" placeholder="Write a comment..." required></textarea>
<button type="submit" class="button">Post Comment</button>
</form>
{% else %}
<p>You need to <a href="{{ url_for('login') }}">log in</a> to post a comment.</p>
{% endif %}
</section>
</div>
{% endfor %}
</div>
{% else %}
<p class="no-posts">{{ username }} hasn't posted yet.</p>
{% endif %}
<a href="{{ url_for('profile', username=username) }}" class="button">Back to Profile</a>
<script>
function confirmDelete() {
return confirm('Are you sure you want to delete this post?');
}
</script>
</body>
</html>