Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions eco_project/backend/static/forest_seeds.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.video-container {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
padding: 20px;
}

.video-item {
width: 300px;
margin: 15px;
border: 1px solid #ccc;
box-shadow: 0 0 5px rgba(0,0,0,0.1);
}

.video-item iframe {
width: 100%;
height: 170px;
}

.video-item-title {
padding: 10px;
font-weight: bold;
}
39 changes: 39 additions & 0 deletions eco_project/backend/static/forest_seeds.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Forest Seeds Promotion - Environment Protection</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="forest_seeds.css">
</head>
<body>
<header>
<h1>Forest Seeds Promotion</h1>
<nav>
<a href="index.html">Home</a>
</nav>
</header>
<main>
<section id="video-submission">
<h2>Share a Video</h2>
<form id="video-form">
<input type="text" id="video-title" placeholder="Video Title" required>
<input type="url" id="video-url" placeholder="Video URL" required>
<button type="submit">Share Video</button>
</form>
<div id="error-message" class="error"></div>
</section>
<section id="videos">
<h2>Featured Videos</h2>
<div class="video-container">
<!-- Video embeds will go here -->
</div>
</section>
</main>
<footer>
<p>&copy; 2025 Environment Protection Initiative</p>
</footer>
<script src="forest_seeds.js"></script>
</body>
</html>
83 changes: 83 additions & 0 deletions eco_project/backend/static/forest_seeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
document.addEventListener('DOMContentLoaded', () => {
const videoContainer = document.querySelector('.video-container');
const videoForm = document.getElementById('video-form');

async function fetchVideos() {
try {
const response = await fetch('/api/forest_seeds_videos');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const videos = await response.json();
displayVideos(videos);
} catch (error) {
videoContainer.innerHTML = `<p>Error fetching videos: ${error.message}</p>`;
}
}

function displayVideos(videos) {
if (videos.length === 0) {
videoContainer.innerHTML = '<p>No videos to display.</p>';
return;
}
let html = '';
videos.forEach(video => {
const embedUrl = video.url.includes('youtube.com/watch?v=')
? video.url.replace('watch?v=', 'embed/')
: video.url;

html += `
<div class="video-item">
<iframe src="${embedUrl}" frameborder="0" allowfullscreen></iframe>
<div class="video-item-title">${video.title}</div>
</div>
`;
});
videoContainer.innerHTML = html;
}

videoForm.addEventListener('submit', async (event) => {
event.preventDefault();

const titleInput = document.getElementById('video-title');
const urlInput = document.getElementById('video-url');
const errorMessage = document.getElementById('error-message');

errorMessage.textContent = '';

let videoUrl = urlInput.value;
if (videoUrl.includes('youtube.com/watch?v=')) {
videoUrl = videoUrl.replace('watch?v=', 'embed/');
}

const newVideo = {
title: titleInput.value,
url: videoUrl,
};

try {
const response = await fetch('/api/forest_seeds_videos', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(newVideo),
});

if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
}

titleInput.value = '';
urlInput.value = '';

fetchVideos(); // Refresh the list of videos
} catch (error) {
console.error('Failed to submit video:', error);
errorMessage.textContent = `Error: ${error.message}`;
}
});

fetchVideos();
});
1 change: 1 addition & 0 deletions eco_project/backend/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ <h2>Community</h2>
<p>Share your ideas and connect with others.</p>
<ul>
<li><a href="videos.html">Watch Videos</a></li>
<li><a href="forest_seeds.html">Forest Seeds Promotion</a></li>
<li><a href="chat.html">Join the Chat</a></li>
</ul>
</section>
Expand Down
Loading