undefined / index.html
akkysuru's picture
The Buttons are not working properly. Fix this issue.
6ed7e7f verified
Raw History Blame Contribute Delete
29.3 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GlassGram ✨</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
* {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
.glass-effect {
background: rgba(255, 255, 255, 0.25);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.18);
}
.tab-active {
background: rgba(255, 255, 255, 0.35);
border-radius: 16px;
}
.post-card {
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
border: 1px solid rgba(255, 255, 255, 0.1);
}
</style>
</head>
<body class="bg-white min-h-screen">
<!-- Auth Screen -->
<div id="authScreen" class="min-h-screen flex items-center justify-center p-4">
<div class="glass-effect rounded-2xl p-8 w-full max-w-md">
<div class="text-center mb-8">
<h1 class="text-3xl font-bold text-gray-900 mb-2">GlassGram</h1>
<p class="text-gray-600">Share your moments in style ✨</p>
</div>
<form id="authForm" class="space-y-4">
<div id="nameField" class="hidden">
<input type="text" id="fullName" placeholder="Full Name"
class="w-full px-4 py-3 rounded-xl bg-white/50 border border-gray-200 focus:border-blue-500 focus:ring-2 focus:ring-blue-200 transition-all duration-200">
</div>
<input type="text" id="username" placeholder="Username"
class="w-full px-4 py-3 rounded-xl bg-white/50 border border-gray-200 focus:border-blue-500 focus:ring-2 focus:ring-blue-200 transition-all duration-200">
<input type="password" id="password" placeholder="Password"
class="w-full px-4 py-3 rounded-xl bg-white/50 border border-gray-200 focus:border-blue-500 focus:ring-2 focus:ring-blue-200 transition-all duration-200">
<button type="submit" id="authButton"
class="w-full bg-black text-white py-3 rounded-xl font-semibold hover:bg-gray-800 transition-colors duration-200">
Sign In
</button>
</form>
<div class="text-center mt-6">
<button id="toggleAuth" class="text-blue-600 font-medium hover:text-blue-700 transition-colors">
Don't have an account? Sign Up
</button>
</div>
<div id="authError" class="mt-4 p-3 bg-red-100 text-red-700 rounded-xl hidden text-center">
Authentication error
</div>
</div>
</div>
<!-- Main App -->
<div id="mainApp" class="hidden min-h-screen pb-20">
<!-- Top Navigation -->
<nav class="glass-effect fixed top-0 left-0 right-0 z-50 p-4">
<div class="flex justify-between items-center">
<h1 class="text-xl font-bold text-gray-900">GlassGram</h1>
<div class="flex space-x-4">
<button id="notificationsBtn" class="p-2 rounded-full hover:bg-white/30 transition-colors">
<i data-feather="bell"></i>
</button>
<button id="logoutBtn" class="p-2 rounded-full hover:bg-white/30 transition-colors">
<i data-feather="log-out"></i>
</button>
</div>
</div>
</nav>
<!-- Main Content -->
<main class="pt-20 px-4">
<!-- Home Tab -->
<div id="homeTab" class="tab-content space-y-4">
<!-- Feed will be populated here -->
</div>
<!-- Search Tab -->
<div id="searchTab" class="tab-content hidden">
<div class="mb-4">
<input type="text" id="searchInput" placeholder="Search users..."
class="w-full px-4 py-3 rounded-xl bg-white/50 border border-gray-200 focus:border-blue-500 focus:ring-2 focus:ring-blue-200 transition-all duration-200">
</div>
<div id="searchResults" class="space-y-3"></div>
<div id="trendingSection" class="mt-6">
<h3 class="font-semibold text-gray-900 mb-3">Trending Posts</h3>
<div id="trendingPosts" class="space-y-3"></div>
</div>
</div>
<!-- Add Post Tab -->
<div id="addPostTab" class="tab-content hidden">
<div class="post-card rounded-2xl p-6 space-y-4">
<textarea id="postCaption" placeholder="What's on your mind?"
class="w-full h-32 px-4 py-3 rounded-xl bg-white/50 border border-gray-200 focus:border-blue-500 focus:ring-2 focus:ring-blue-200 transition-all duration-200 resize-none"></textarea>
<div id="mediaPreview" class="hidden">
<img id="previewImage" class="w-full rounded-xl max-h-64 object-cover">
</div>
<div class="flex space-x-3">
<input type="file" id="mediaUpload" accept="image/*,video/*" class="hidden">
<button id="uploadMediaBtn" class="flex-1 bg-gray-100 text-gray-700 py-3 rounded-xl font-medium hover:bg-gray-200 transition-colors">
<i data-feather="image" class="w-4 h-4 inline mr-2"></i>
Add Media
</button>
<button id="publishPostBtn" class="flex-1 bg-black text-white py-3 rounded-xl font-semibold hover:bg-gray-800 transition-colors">
<i data-feather="send" class="w-4 h-4 inline mr-2"></i>
Post
</button>
</div>
</div>
</div>
<!-- Profile Tab -->
<div id="profileTab" class="tab-content hidden">
<div class="post-card rounded-2xl p-6">
<div class="flex items-center space-x-4 mb-6">
<div class="relative">
<img id="profilePicture" src="http://static.photos/people/200x200/1"
class="w-20 h-20 rounded-full object-cover border-2 border-white">
<button id="changeProfilePic" class="absolute bottom-0 right-0 bg-blue-500 text-white p-1 rounded-full">
<i data-feather="camera" class="w-3 h-3"></i>
</button>
</div>
<div class="flex-1">
<h2 id="profileUsername" class="text-xl font-bold text-gray-900"></h2>
<p id="profileBio" class="text-gray-600 text-sm">No bio yet</p>
</div>
<button id="editProfileBtn" class="bg-gray-100 text-gray-700 px-4 py-2 rounded-xl font-medium hover:bg-gray-200 transition-colors">
Edit
</button>
</div>
<div class="flex justify-around text-center mb-6">
<div>
<div id="postsCount" class="font-bold text-gray-900">0</div>
<div class="text-xs text-gray-600">Posts</div>
</div>
<div>
<div id="followersCount" class="font-bold text-gray-900">0</div>
<div class="text-xs text-gray-600">Followers</div>
</div>
<div>
<div id="followingCount" class="font-bold text-gray-900">0</div>
<div class="text-xs text-gray-600">Following</div>
</div>
</div>
<div id="userPostsGrid" class="grid grid-cols-3 gap-1">
<!-- User posts will be populated here -->
</div>
</div>
</div>
<!-- Settings Tab -->
<div id="settingsTab" class="tab-content hidden">
<div class="post-card rounded-2xl p-6 space-y-4">
<div class="space-y-2">
<h3 class="font-semibold text-gray-900">Account</h3>
<button class="w-full text-left p-3 rounded-xl bg-white/50 hover:bg-white/70 transition-colors">
Change Password
</button>
<button class="w-full text-left p-3 rounded-xl bg-white/50 hover:bg-white/70 transition-colors">
Privacy Settings
</button>
</div>
<div class="space-y-2">
<h3 class="font-semibold text-gray-900">About</h3>
<div class="text-sm text-gray-600 p-3">
GlassGram v1.0.0<br>
Built with ❤️ for sharing moments
</div>
</div>
<button id="confirmLogout" class="w-full bg-red-100 text-red-600 py-3 rounded-xl font-semibold hover:bg-red-200 transition-colors">
Log Out
</button>
</div>
</div>
</main>
<!-- Bottom Navigation -->
<nav class="glass-effect fixed bottom-0 left-0 right-0 z-50 p-4">
<div class="flex justify-around items-center">
<button class="tab-btn p-3 rounded-xl transition-all duration-200 tab-active" data-tab="home">
<i data-feather="home"></i>
</button>
<button class="tab-btn p-3 rounded-xl transition-all duration-200" data-tab="search">
<i data-feather="search"></i>
</button>
<button class="tab-btn p-3 rounded-xl transition-all duration-200" data-tab="addPost">
<i data-feather="plus-square"></i>
</button>
<button class="tab-btn p-3 rounded-xl transition-all duration-200" data-tab="profile">
<i data-feather="user"></i>
</button>
<button class="tab-btn p-3 rounded-xl transition-all duration-200" data-tab="settings">
<i data-feather="settings"></i>
</button>
</div>
</nav>
</div>
<!-- TypeScript Code -->
<script>
// Supabase Configuration
const supabaseUrl = 'https://xoiqxuzwmtidrfgmvrjp.supabase.co';
const supabaseKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhvaXF4dXp3bXRpZHJmZ212cmpwIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjA1ODkzNTYsImV4cCI6MjA3NjE2NTM1Nn0.iB7eYcHlTG7-I9_iiAPA2ckWuZ0ISMPrNwjjhT_CMhc';
const supabase = window.supabase.createClient(supabaseUrl, supabaseKey);
// App State
let currentUser = null;
let isSignUp = false;
// DOM Elements
const authScreen = document.getElementById('authScreen');
const mainApp = document.getElementById('mainApp');
const authForm = document.getElementById('authForm');
const authButton = document.getElementById('authButton');
const toggleAuth = document.getElementById('toggleAuth');
const nameField = document.getElementById('nameField');
const authError = document.getElementById('authError');
// Initialize App
document.addEventListener('DOMContentLoaded', function() {
feather.replace();
checkAuthState();
setupEventListeners();
});
// Check if user is already authenticated
async function checkAuthState() {
const { data: { session } } = await supabase.auth.getSession();
if (session) {
currentUser = session.user;
showMainApp();
loadFeed();
}
}
// Setup event listeners
function setupEventListeners() {
// Auth form submission
authForm.addEventListener('submit', handleAuth);
// Toggle between sign in/sign up
toggleAuth.addEventListener('click', function() {
isSignUp = !isSignUp;
nameField.classList.toggle('hidden', !isSignUp);
authButton.textContent = isSignUp ? 'Sign Up' : 'Sign In';
toggleAuth.textContent = isSignUp ? 'Already have an account? Sign In' : 'Don\'t have an account? Sign Up';
authError.classList.add('hidden');
});
// Tab navigation
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', function() {
const tab = this.getAttribute('data-tab');
switchTab(tab);
});
});
// Media upload
document.getElementById('uploadMediaBtn').addEventListener('click', function() {
document.getElementById('mediaUpload').click();
});
document.getElementById('mediaUpload').addEventListener('change', function(e) {
if (e.target.files[0]) {
const reader = new FileReader();
reader.onload = function(event) {
document.getElementById('previewImage').src = event.target.result;
document.getElementById('mediaPreview').classList.remove('hidden');
};
reader.readAsDataURL(e.target.files[0]);
});
// Publish post
document.getElementById('publishPostBtn').addEventListener('click', createPost);
// Logout
document.getElementById('confirmLogout').addEventListener('click', handleLogout);
}
// Authentication handler
async function handleAuth(e) {
e.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
if (!username || !password) {
showAuthError('Please fill in all fields');
return;
}
try {
if (isSignUp) {
const fullName = document.getElementById('fullName').value;
if (!fullName) {
showAuthError('Please enter your full name');
return;
}
const { data, error } = await supabase.auth.signUp({
email: `${username}@glassgram.app`,
password: password
});
if (error) throw error;
// Create user profile
const { error: profileError } = await supabase
.from('users')
.insert([
{
id: data.user.id,
username: username,
full_name: fullName,
bio: '',
profile_pic_url: `http://static.photos/people/200x200/${Math.floor(Math.random() * 100)}`
}
]);
if (profileError) throw profileError;
showAuthError('Account created successfully! Please sign in.', false);
isSignUp = false;
toggleAuth.click();
} else {
const { data, error } = await supabase.auth.signInWithPassword({
email: `${username}@glassgram.app`,
password: password
});
if (error) throw error;
currentUser = data.user;
showMainApp();
loadFeed();
}
} catch (error) {
showAuthError(error.message);
}
}
// Show authentication error/success message
function showAuthError(message, isError = true) {
authError.textContent = message;
authError.className = `mt-4 p-3 rounded-xl text-center ${isError ? 'bg-red-100 text-red-700' : 'bg-green-100 text-green-700'}`;
authError.classList.remove('hidden');
}
// Show main app
function showMainApp() {
authScreen.classList.add('hidden');
mainApp.classList.remove('hidden');
updateProfileInfo();
}
// Switch between tabs
function switchTab(tabName) {
// Hide all tab contents
document.querySelectorAll('.tab-content').forEach(tab => {
tab.classList.add('hidden');
});
// Remove active state from all tabs
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.classList.remove('tab-active');
});
// Show selected tab content
document.getElementById(`${tabName}Tab`).classList.remove('hidden');
// Add active state to current tab
document.querySelector(`[data-tab="${tabName}"]`).classList.add('tab-active');
// Load tab-specific data
switch(tabName) {
case 'home':
loadFeed();
break;
case 'search':
loadTrendingPosts();
break;
case 'profile':
loadUserProfile();
break;
}
}
// Load feed posts
async function loadFeed() {
const homeTab = document.getElementById('homeTab');
// Simulate loading
homeTab.innerHTML = `
<div class="flex justify-center items-center h-32">
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"></div>
</div>
`;
try {
const { data: posts, error } = await supabase
.from('posts')
.select(`
*,
users (username, profile_pic_url)
`)
.order('created_at', { ascending: false });
if (error) throw error;
if (posts && posts.length > 0) {
homeTab.innerHTML = posts.map(post => `
<div class="post-card rounded-2xl p-4">
<div class="flex items-center space-x-3 mb-3">
<img src="${post.users.profile_pic_url}"
class="w-10 h-10 rounded-full object-cover">
<div>
<div class="font-semibold text-gray-900">${post.users.username}</div>
</div>
</div>
${post.media_url ? `
<img src="${post.media_url}"
class="w-full rounded-xl mb-3 object-cover max-h-96">
` : ''}
<p class="text-gray-900 mb-3">${post.caption}</p>
<div class="flex items-center space-x-4 text-gray-600">
<button class="flex items-center space-x-1 hover:text-red-500 transition-colors">
<i data-feather="heart" class="w-4 h-4"></i>
<span>${post.likes_count || 0}</span>
</button>
<button class="flex items-center space-x-1 hover:text-blue-500 transition-colors">
<i data-feather="message-circle" class="w-4 h-4"></i>
<span>Comment</span>
</button>
</div>
</div>
`).join('');
} else {
homeTab.innerHTML = `
<div class="text-center py-12">
<i data-feather="camera" class="w-12 h-12 text-gray-400 mx-auto mb-4"></i>
<h3 class="text-lg font-semibold text-gray-900 mb-2">No posts yet</h3>
<p class="text-gray-600">Be the first to share something!</p>
</div>
`;
}
feather.replace();
} catch (error) {
homeTab.innerHTML = `
<div class="text-center py-12 text-red-600">
Error loading posts
</div>
`;
}
}
// Load trending posts
async function loadTrendingPosts() {
const trendingPosts = document.getElementById('trendingPosts');
try {
const { data: posts, error } = await supabase
.from('posts')
.select(`
*,
users (username, profile_pic_url)
`)
.order('likes_count', { ascending: false })
.limit(5);
if (error) throw error;
if (posts && posts.length > 0) {
trendingPosts.innerHTML = posts.map(post => `
<div class="post-card rounded-2xl p-3">
<div class="flex items-center space-x-2 mb-2">
<img src="${post.users.profile_pic_url}"
class="w-8 h-8 rounded-full object-cover">
<span class="font-medium text-gray-900">${post.users.username}</span>
</div>
<p class="text-sm text-gray-700">${post.caption.substring(0, 100)}${post.caption.length > 100 ? '...' : ''}</p>
</div>
`).join('');
} else {
trendingPosts.innerHTML = `
<div class="text-center py-8 text-gray-600">
No trending posts yet
</div>
`;
}
} catch (error) {
trendingPosts.innerHTML = 'Error loading trending posts';
}
}
// Create new post
async function createPost() {
const caption = document.getElementById('postCaption').value;
const mediaFile = document.getElementById('mediaUpload').files[0];
if (!caption.trim() && !mediaFile) {
alert('Please add a caption or media to your post');
return;
}
try {
let mediaUrl = null;
if (mediaFile) {
// In a real app, you would upload to Supabase Storage here
mediaUrl = `http://static.photos/nature/640x360/${Math.floor(Math.random() * 100)}`;
}
const { data, error } = await supabase
.from('posts')
.insert([
{
user_id: currentUser.id,
caption: caption,
media_url: mediaUrl,
likes_count: 0
}
]);
if (error) throw error;
// Reset form
document.getElementById('postCaption').value = '';
document.getElementById('mediaPreview').classList.add('hidden');
document.getElementById('mediaUpload').value = '';
// Switch to home tab and reload feed
switchTab('home');
} catch (error) {
alert('Error creating post: ' + error.message);
}
}
// Load user profile
async function loadUserProfile() {
try {
const { data: userData, error: userError } = await supabase
.from('users')
.select('*')
.eq('id', currentUser.id)
.single();
if (userError) throw userError;
// Load user posts
const { data: posts, error: postsError } = await supabase
.from('posts')
.select('*')
.eq('user_id', currentUser.id)
.order('created_at', { ascending: false });
if (postsError) throw postsError;
const postsGrid = document.getElementById('userPostsGrid');
if (posts && posts.length > 0) {
postsGrid.innerHTML = posts.map(post => `
<div class="aspect-square bg-gray-100 rounded-lg overflow-hidden">
${post.media_url ? `
<img src="${post.media_url}"
class="w-full h-full object-cover">
` : `
<div class="w-full h-full flex items-center justify-center text-gray-400">
<i data-feather="file-text" class="w-6 h-6"></i>
</div>
`}
</div>
`).join('');
} else {
postsGrid.innerHTML = `
<div class="col-span-3 text-center py-12 text-gray-600">
No posts yet
</div>
`;
}
feather.replace();
} catch (error) {
console.error('Error loading profile:', error);
}
}
// Update profile information
async function updateProfileInfo() {
try {
const { data: userData, error } = await supabase
.from('users')
.select('*')
.eq('id', currentUser.id)
.single();
if (error) throw error;
document.getElementById('profileUsername').textContent = userData.username;
document.getElementById('profileBio').textContent = userData.bio || 'No bio yet';
document.getElementById('profilePicture').src = userData.profile_pic_url;
// Update counts (simulated)
document.getElementById('postsCount').textContent = Math.floor(Math.random() * 20);
document.getElementById('followersCount').textContent = Math.floor(Math.random() * 100);
document.getElementById('followingCount').textContent = Math.floor(Math.random() * 50);
} catch (error) {
console.error('Error updating profile info:', error);
}
}
// Handle logout
async function handleLogout() {
const { error } = await supabase.auth.signOut();
if (error) {
alert('Error logging out: ' + error.message);
return;
}
currentUser = null;
mainApp.classList.add('hidden');
authScreen.classList.remove('hidden');
// Reset auth form
authForm.reset();
isSignUp = false;
nameField.classList.add('hidden');
authButton.textContent = 'Sign In';
toggleAuth.textContent = 'Don\'t have an account? Sign Up';
}
</script>
</body>
</html>