<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>{% block title %}Rant Community{% endblock %}</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
:root {
|
|
--primary: #d55161;
|
|
--primary-dark: #c44154;
|
|
--secondary: #7bc8a4;
|
|
--background: #0a0a0a;
|
|
--surface: #1a1a1a;
|
|
--surface-light: #2a2a2a;
|
|
--text: #e0e0e0;
|
|
--text-dim: #a0a0a0;
|
|
--success: #4caf50;
|
|
--error: #f44336;
|
|
--warning: #ff9800;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
background: var(--background);
|
|
color: var(--text);
|
|
line-height: 1.6;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
/* Navigation */
|
|
nav {
|
|
background: var(--surface);
|
|
padding: 1rem 0;
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 1000;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.5);
|
|
}
|
|
|
|
.nav-container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 0 2rem;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
|
|
.logo {
|
|
font-size: 1.5rem;
|
|
font-weight: bold;
|
|
color: var(--primary);
|
|
text-decoration: none;
|
|
}
|
|
|
|
.nav-links {
|
|
display: flex;
|
|
gap: 2rem;
|
|
align-items: center;
|
|
}
|
|
|
|
.nav-links a {
|
|
color: var(--text);
|
|
text-decoration: none;
|
|
transition: color 0.3s;
|
|
}
|
|
|
|
.nav-links a:hover {
|
|
color: var(--primary);
|
|
}
|
|
|
|
.btn {
|
|
background: var(--primary);
|
|
color: white;
|
|
border: none;
|
|
padding: 0.5rem 1.5rem;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 1rem;
|
|
transition: all 0.3s;
|
|
text-decoration: none;
|
|
display: inline-block;
|
|
}
|
|
|
|
.btn:hover {
|
|
background: var(--primary-dark);
|
|
transform: translateY(-1px);
|
|
}
|
|
|
|
.btn-secondary {
|
|
background: var(--surface-light);
|
|
}
|
|
|
|
.btn-secondary:hover {
|
|
background: #3a3a3a;
|
|
}
|
|
|
|
/* Container */
|
|
.container {
|
|
max-width: 800px;
|
|
margin: 2rem auto;
|
|
padding: 0 2rem;
|
|
}
|
|
|
|
/* Rant Card */
|
|
.rant-card {
|
|
background: var(--surface);
|
|
border-radius: 8px;
|
|
padding: 1.5rem;
|
|
margin-bottom: 1rem;
|
|
transition: transform 0.2s;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.rant-card:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
|
|
}
|
|
|
|
.rant-header {
|
|
display: flex;
|
|
align-items: center;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.avatar {
|
|
width: 40px;
|
|
height: 40px;
|
|
border-radius: 50%;
|
|
margin-right: 1rem;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-weight: bold;
|
|
color: white;
|
|
}
|
|
|
|
.user-info {
|
|
flex: 1;
|
|
}
|
|
|
|
.username {
|
|
font-weight: bold;
|
|
color: var(--primary);
|
|
}
|
|
|
|
.score {
|
|
color: var(--text-dim);
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.rant-content {
|
|
margin-bottom: 1rem;
|
|
white-space: pre-wrap;
|
|
word-wrap: break-word;
|
|
}
|
|
|
|
.rant-image {
|
|
max-width: 100%;
|
|
border-radius: 4px;
|
|
margin: 1rem 0;
|
|
}
|
|
|
|
.rant-footer {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
color: var(--text-dim);
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.rant-actions {
|
|
display: flex;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.action-btn {
|
|
background: none;
|
|
border: none;
|
|
color: var(--text-dim);
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.3rem;
|
|
transition: color 0.3s;
|
|
padding: 0.3rem 0.6rem;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.action-btn:hover {
|
|
color: var(--primary);
|
|
background: rgba(213, 81, 97, 0.1);
|
|
}
|
|
|
|
.action-btn.voted {
|
|
color: var(--primary);
|
|
}
|
|
|
|
.action-btn.downvoted {
|
|
color: var(--error);
|
|
}
|
|
|
|
/* Tags */
|
|
.tags {
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
flex-wrap: wrap;
|
|
margin: 0.5rem 0;
|
|
}
|
|
|
|
.tag {
|
|
background: var(--surface-light);
|
|
padding: 0.2rem 0.8rem;
|
|
border-radius: 20px;
|
|
font-size: 0.85rem;
|
|
color: var(--secondary);
|
|
}
|
|
|
|
/* Forms */
|
|
.form-group {
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
margin-bottom: 0.5rem;
|
|
color: var(--text-dim);
|
|
}
|
|
|
|
input, textarea, select {
|
|
width: 100%;
|
|
padding: 0.75rem;
|
|
background: var(--surface-light);
|
|
border: 1px solid transparent;
|
|
border-radius: 4px;
|
|
color: var(--text);
|
|
font-size: 1rem;
|
|
transition: border-color 0.3s;
|
|
}
|
|
|
|
input:focus, textarea:focus, select:focus {
|
|
outline: none;
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
textarea {
|
|
resize: vertical;
|
|
min-height: 120px;
|
|
}
|
|
|
|
/* Modal */
|
|
.modal {
|
|
display: none;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background: rgba(0,0,0,0.8);
|
|
z-index: 2000;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.modal.active {
|
|
display: flex;
|
|
}
|
|
|
|
.modal-content {
|
|
background: var(--surface);
|
|
padding: 2rem;
|
|
border-radius: 8px;
|
|
max-width: 500px;
|
|
width: 90%;
|
|
max-height: 90vh;
|
|
overflow-y: auto;
|
|
position: relative;
|
|
}
|
|
|
|
.modal-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
|
|
.close-btn {
|
|
background: none;
|
|
border: none;
|
|
color: var(--text-dim);
|
|
font-size: 1.5rem;
|
|
cursor: pointer;
|
|
padding: 0;
|
|
width: 30px;
|
|
height: 30px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
border-radius: 50%;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.close-btn:hover {
|
|
background: var(--surface-light);
|
|
color: var(--text);
|
|
}
|
|
|
|
/* Loading */
|
|
.loading {
|
|
text-align: center;
|
|
padding: 2rem;
|
|
color: var(--text-dim);
|
|
}
|
|
|
|
.spinner {
|
|
border: 3px solid var(--surface-light);
|
|
border-top: 3px solid var(--primary);
|
|
border-radius: 50%;
|
|
width: 40px;
|
|
height: 40px;
|
|
animation: spin 1s linear infinite;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
/* Comments */
|
|
.comments-section {
|
|
background: var(--surface);
|
|
border-radius: 8px;
|
|
padding: 1.5rem;
|
|
margin-top: 2rem;
|
|
}
|
|
|
|
.comment {
|
|
padding: 1rem 0;
|
|
border-bottom: 1px solid var(--surface-light);
|
|
}
|
|
|
|
.comment:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.comment-form {
|
|
margin-top: 1.5rem;
|
|
padding-top: 1.5rem;
|
|
border-top: 1px solid var(--surface-light);
|
|
}
|
|
|
|
/* Sort Options */
|
|
.sort-options {
|
|
display: flex;
|
|
gap: 1rem;
|
|
margin-bottom: 2rem;
|
|
justify-content: center;
|
|
}
|
|
|
|
.sort-btn {
|
|
background: var(--surface);
|
|
border: 1px solid var(--surface-light);
|
|
padding: 0.5rem 1.5rem;
|
|
border-radius: 20px;
|
|
color: var(--text-dim);
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.sort-btn:hover {
|
|
border-color: var(--primary);
|
|
color: var(--primary);
|
|
}
|
|
|
|
.sort-btn.active {
|
|
background: var(--primary);
|
|
color: white;
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
/* Profile */
|
|
.profile-header {
|
|
background: var(--surface);
|
|
border-radius: 8px;
|
|
padding: 2rem;
|
|
margin-bottom: 2rem;
|
|
text-align: center;
|
|
}
|
|
|
|
.profile-avatar {
|
|
width: 100px;
|
|
height: 100px;
|
|
border-radius: 50%;
|
|
margin: 0 auto 1rem;
|
|
font-size: 2rem;
|
|
}
|
|
|
|
.profile-stats {
|
|
display: flex;
|
|
justify-content: center;
|
|
gap: 3rem;
|
|
margin-top: 1.5rem;
|
|
}
|
|
|
|
.stat {
|
|
text-align: center;
|
|
}
|
|
|
|
.stat-value {
|
|
font-size: 1.5rem;
|
|
font-weight: bold;
|
|
color: var(--primary);
|
|
}
|
|
|
|
.stat-label {
|
|
color: var(--text-dim);
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
/* Tabs */
|
|
.tabs {
|
|
display: flex;
|
|
justify-content: center;
|
|
gap: 1rem;
|
|
margin-bottom: 2rem;
|
|
border-bottom: 1px solid var(--surface-light);
|
|
}
|
|
|
|
.tab {
|
|
padding: 1rem 2rem;
|
|
background: none;
|
|
border: none;
|
|
color: var(--text-dim);
|
|
cursor: pointer;
|
|
position: relative;
|
|
transition: color 0.3s;
|
|
}
|
|
|
|
.tab:hover {
|
|
color: var(--text);
|
|
}
|
|
|
|
.tab.active {
|
|
color: var(--primary);
|
|
}
|
|
|
|
.tab.active::after {
|
|
content: '';
|
|
position: absolute;
|
|
bottom: -1px;
|
|
left: 0;
|
|
right: 0;
|
|
height: 2px;
|
|
background: var(--primary);
|
|
}
|
|
|
|
/* Alert */
|
|
.alert {
|
|
padding: 1rem;
|
|
border-radius: 4px;
|
|
margin-bottom: 1rem;
|
|
display: none;
|
|
}
|
|
|
|
.alert.active {
|
|
display: block;
|
|
}
|
|
|
|
.alert.success {
|
|
background: rgba(76, 175, 80, 0.1);
|
|
border: 1px solid var(--success);
|
|
color: var(--success);
|
|
}
|
|
|
|
.alert.error {
|
|
background: rgba(244, 67, 54, 0.1);
|
|
border: 1px solid var(--error);
|
|
color: var(--error);
|
|
}
|
|
|
|
/* Search */
|
|
.search-box {
|
|
background: var(--surface);
|
|
padding: 1rem;
|
|
border-radius: 8px;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.search-form {
|
|
display: flex;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.search-form input {
|
|
flex: 1;
|
|
}
|
|
|
|
/* Floating Action Button */
|
|
.fab {
|
|
position: fixed;
|
|
bottom: 2rem;
|
|
right: 2rem;
|
|
width: 60px;
|
|
height: 60px;
|
|
border-radius: 50%;
|
|
background: var(--primary);
|
|
color: white;
|
|
border: none;
|
|
font-size: 1.5rem;
|
|
cursor: pointer;
|
|
box-shadow: 0 4px 20px rgba(213, 81, 97, 0.4);
|
|
transition: all 0.3s;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.fab:hover {
|
|
transform: scale(1.1);
|
|
box-shadow: 0 6px 30px rgba(213, 81, 97, 0.6);
|
|
}
|
|
|
|
/* Responsive */
|
|
@media (max-width: 768px) {
|
|
.nav-links {
|
|
gap: 1rem;
|
|
}
|
|
|
|
.nav-links span {
|
|
display: none;
|
|
}
|
|
|
|
.profile-stats {
|
|
gap: 1.5rem;
|
|
}
|
|
|
|
.tabs {
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.tab {
|
|
padding: 1rem;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<!-- Navigation Component -->
|
|
{% include 'components/navigation.html' %}
|
|
|
|
<!-- Main Content Container -->
|
|
<div id="content" class="container">
|
|
{% block content %}{% endblock %}
|
|
</div>
|
|
|
|
<!-- Floating Action Button -->
|
|
{% if current_user %}
|
|
<button class="fab" onclick="showModal('create-rant')">+</button>
|
|
{% endif %}
|
|
|
|
<!-- Modals -->
|
|
{% include 'components/modals.html' %}
|
|
|
|
<script>
|
|
// Auth token management
|
|
const authToken = {% if current_user %}{ id: {{ current_user.id }}, token_id: {{ current_user.token_id }}, token_key: "{{ current_user.token_key }}" }{% else %}null{% endif %};
|
|
const APP_ID = 3;
|
|
|
|
// API call helper
|
|
async function apiCall(endpoint, options = {}) {
|
|
let url = `/api${endpoint}`;
|
|
|
|
// Add auth to FormData or URLSearchParams if logged in
|
|
if (authToken && options.body) {
|
|
if (options.body instanceof FormData) {
|
|
options.body.append('app', APP_ID);
|
|
options.body.append('token_id', authToken.token_id);
|
|
options.body.append('token_key', authToken.token_key);
|
|
options.body.append('user_id', authToken.id);
|
|
} else if (options.body instanceof URLSearchParams) {
|
|
options.body.append('app', APP_ID);
|
|
options.body.append('token_id', authToken.token_id);
|
|
options.body.append('token_key', authToken.token_key);
|
|
options.body.append('user_id', authToken.id);
|
|
}
|
|
}
|
|
|
|
// Add auth to query params for GET requests
|
|
if (authToken && (options.method === 'GET' || !options.method)) {
|
|
const separator = endpoint.includes('?') ? '&' : '?';
|
|
url += `${separator}app=${APP_ID}&token_id=${authToken.token_id}&token_key=${authToken.token_key}&user_id=${authToken.id}`;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch(url, options);
|
|
const data = await response.json();
|
|
return data;
|
|
} catch (error) {
|
|
console.error('API Error:', error);
|
|
return { success: false, error: error.message };
|
|
}
|
|
}
|
|
|
|
// Modal functions
|
|
function showModal(type) {
|
|
const modal = document.getElementById('modal');
|
|
modal.classList.add('active');
|
|
|
|
switch(type) {
|
|
case 'login':
|
|
document.getElementById('loginModal').style.display = 'block';
|
|
document.getElementById('registerModal').style.display = 'none';
|
|
document.getElementById('createRantModal').style.display = 'none';
|
|
document.getElementById('editProfileModal').style.display = 'none';
|
|
break;
|
|
case 'register':
|
|
document.getElementById('loginModal').style.display = 'none';
|
|
document.getElementById('registerModal').style.display = 'block';
|
|
document.getElementById('createRantModal').style.display = 'none';
|
|
document.getElementById('editProfileModal').style.display = 'none';
|
|
break;
|
|
case 'create-rant':
|
|
document.getElementById('loginModal').style.display = 'none';
|
|
document.getElementById('registerModal').style.display = 'none';
|
|
document.getElementById('createRantModal').style.display = 'block';
|
|
document.getElementById('editProfileModal').style.display = 'none';
|
|
break;
|
|
case 'edit-profile':
|
|
document.getElementById('loginModal').style.display = 'none';
|
|
document.getElementById('registerModal').style.display = 'none';
|
|
document.getElementById('createRantModal').style.display = 'none';
|
|
document.getElementById('editProfileModal').style.display = 'block';
|
|
break;
|
|
}
|
|
}
|
|
|
|
function closeModal() {
|
|
const modal = document.getElementById('modal');
|
|
modal.classList.remove('active');
|
|
}
|
|
|
|
// Vote functions
|
|
async function voteRant(rantId, vote) {
|
|
if (!authToken) {
|
|
showModal('login');
|
|
return;
|
|
}
|
|
|
|
const formData = new FormData();
|
|
formData.append('vote', vote);
|
|
if (vote === -1) {
|
|
formData.append('reason', 0);
|
|
}
|
|
|
|
const data = await apiCall(`/rant/rants/${rantId}/vote`, {
|
|
method: 'POST',
|
|
body: formData
|
|
});
|
|
|
|
if (data.success) {
|
|
location.reload();
|
|
}
|
|
}
|
|
|
|
async function voteComment(commentId, vote) {
|
|
if (!authToken) {
|
|
showModal('login');
|
|
return;
|
|
}
|
|
|
|
const formData = new FormData();
|
|
formData.append('vote', vote);
|
|
|
|
const data = await apiCall(`/comments/${commentId}/vote`, {
|
|
method: 'POST',
|
|
body: formData
|
|
});
|
|
|
|
if (data.success) {
|
|
location.reload();
|
|
}
|
|
}
|
|
|
|
async function toggleFavorite(rantId, subscribed) {
|
|
if (!authToken) {
|
|
showModal('login');
|
|
return;
|
|
}
|
|
|
|
const endpoint = subscribed ? 'unfavorite' : 'favorite';
|
|
const formData = new FormData();
|
|
|
|
const data = await apiCall(`/rant/rants/${rantId}/${endpoint}`, {
|
|
method: 'POST',
|
|
body: formData
|
|
});
|
|
|
|
if (data.success) {
|
|
location.reload();
|
|
}
|
|
}
|
|
|
|
async function deleteRant(rantId) {
|
|
if (!confirm('Are you sure you want to delete this rant?')) return;
|
|
|
|
const params = new URLSearchParams();
|
|
params.append('app', APP_ID);
|
|
params.append('token_id', authToken.token_id);
|
|
params.append('token_key', authToken.token_key);
|
|
params.append('user_id', authToken.id);
|
|
|
|
const data = await apiCall(`/rant/rants/${rantId}?${params}`, {
|
|
method: 'DELETE'
|
|
});
|
|
|
|
if (data.success) {
|
|
window.location.href = '/';
|
|
}
|
|
}
|
|
|
|
async function deleteComment(commentId) {
|
|
if (!confirm('Are you sure you want to delete this comment?')) return;
|
|
|
|
const params = new URLSearchParams();
|
|
params.append('app', APP_ID);
|
|
params.append('token_id', authToken.token_id);
|
|
params.append('token_key', authToken.token_key);
|
|
params.append('user_id', authToken.id);
|
|
|
|
const data = await apiCall(`/comments/${commentId}?${params}`, {
|
|
method: 'DELETE'
|
|
});
|
|
|
|
if (data.success) {
|
|
location.reload();
|
|
}
|
|
}
|
|
|
|
// Form submissions
|
|
async function submitCreateRant(event) {
|
|
event.preventDefault();
|
|
const formData = new FormData(event.target);
|
|
|
|
const data = await apiCall('/rant/rants', {
|
|
method: 'POST',
|
|
body: formData
|
|
});
|
|
|
|
if (data.success) {
|
|
window.location.href = `/rant/${data.rant_id}`;
|
|
} else {
|
|
document.getElementById('rantError').textContent = data.error;
|
|
document.getElementById('rantError').classList.add('active');
|
|
}
|
|
}
|
|
|
|
async function submitEditProfile(event) {
|
|
event.preventDefault();
|
|
const formData = new FormData(event.target);
|
|
|
|
// Add profile_ prefix to all fields
|
|
const profileData = new FormData();
|
|
for (let [key, value] of formData.entries()) {
|
|
profileData.append(`profile_${key}`, value);
|
|
}
|
|
|
|
const data = await apiCall('/users/me/edit-profile', {
|
|
method: 'POST',
|
|
body: profileData
|
|
});
|
|
|
|
if (data.success) {
|
|
location.reload();
|
|
}
|
|
}
|
|
|
|
// Modal close on background click
|
|
document.getElementById('modal')?.addEventListener('click', (e) => {
|
|
if (e.target.id === 'modal') {
|
|
closeModal();
|
|
}
|
|
});
|
|
</script>
|
|
|
|
{% block scripts %}{% endblock %}
|
|
</body>
|
|
</html>
|