Rms666777 commited on
Commit
eb50261
·
verified ·
1 Parent(s): d4d601a

Upload pages/index.js with huggingface_hub

Browse files
Files changed (1) hide show
  1. pages/index.js +126 -0
pages/index.js ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState, useEffect } from 'react';
2
+ import Layout from '../components/Layout';
3
+ import ChatList from '../components/ChatList';
4
+ import ChatWindow from '../components/ChatWindow';
5
+ import { Lock } from 'lucide-react';
6
+
7
+ // Mock Data Generator
8
+ const generateMockChats = () => [
9
+ {
10
+ id: 1,
11
+ name: "Alice (Encrypted)",
12
+ isGroup: false,
13
+ lastMessage: "Did you get the keys?",
14
+ lastTime: "10:42 AM",
15
+ unread: 2,
16
+ encrypted: true,
17
+ messages: [
18
+ { id: 1, text: "Hey, is this channel secure?", sender: "them", timestamp: "10:30 AM", status: "read" },
19
+ { id: 2, text: "Yes, end-to-end encrypted.", sender: "me", timestamp: "10:31 AM", status: "read" },
20
+ { id: 3, text: "Great. Did you get the keys?", sender: "them", timestamp: "10:42 AM", status: "delivered" }
21
+ ]
22
+ },
23
+ {
24
+ id: 2,
25
+ name: "Dev Team Alpha",
26
+ isGroup: true,
27
+ lastMessage: "Bob: Deployment looks good.",
28
+ lastTime: "Yesterday",
29
+ unread: 0,
30
+ encrypted: true,
31
+ messages: [
32
+ { id: 1, text: "Meeting at 3?", sender: "them", senderName: "Charlie", timestamp: "Yesterday", status: "read" },
33
+ { id: 2, text: "Deployment looks good.", sender: "them", senderName: "Bob", timestamp: "Yesterday", status: "read" }
34
+ ]
35
+ },
36
+ {
37
+ id: 3,
38
+ name: "Secure Backup Bot",
39
+ isGroup: false,
40
+ lastMessage: "Backup completed successfully.",
41
+ lastTime: "Mon",
42
+ unread: 0,
43
+ encrypted: true,
44
+ messages: [
45
+ { id: 1, text: "Backup completed successfully.", sender: "them", timestamp: "Mon", status: "read" }
46
+ ]
47
+ }
48
+ ];
49
+
50
+ export default function Home() {
51
+ const [chats, setChats] = useState([]);
52
+ const [activeChatId, setActiveChatId] = useState(null);
53
+ const [isMobileView, setIsMobileView] = useState(false);
54
+
55
+ useEffect(() => {
56
+ setChats(generateMockChats());
57
+
58
+ const handleResize = () => {
59
+ setIsMobileView(window.innerWidth < 768);
60
+ };
61
+
62
+ handleResize();
63
+ window.addEventListener('resize', handleResize);
64
+ return () => window.removeEventListener('resize', handleResize);
65
+ }, []);
66
+
67
+ const handleSelectChat = (id) => {
68
+ setActiveChatId(id);
69
+ // Mark as read logic could go here
70
+ setChats(prev => prev.map(c => c.id === id ? { ...c, unread: 0 } : c));
71
+ };
72
+
73
+ const handleSendMessage = (chatId, newMessage) => {
74
+ setChats(prev => prev.map(chat => {
75
+ if (chat.id === chatId) {
76
+ return {
77
+ ...chat,
78
+ messages: [...chat.messages, newMessage],
79
+ lastMessage: newMessage.text,
80
+ lastTime: newMessage.timestamp
81
+ };
82
+ }
83
+ return chat;
84
+ }));
85
+ };
86
+
87
+ const handleCreateGroup = () => {
88
+ const newGroup = {
89
+ id: Date.now(),
90
+ name: "New Secure Group",
91
+ isGroup: true,
92
+ lastMessage: "Group created",
93
+ lastTime: "Now",
94
+ unread: 0,
95
+ encrypted: true,
96
+ messages: []
97
+ };
98
+ setChats(prev => [newGroup, ...prev]);
99
+ setActiveChatId(newGroup.id);
100
+ };
101
+
102
+ const activeChat = chats.find(c => c.id === activeChatId);
103
+
104
+ return (
105
+ <Layout>
106
+ {/* Sidebar - Hidden on mobile if chat is active */}
107
+ <div className={`${isMobileView && activeChatId ? 'hidden' : 'flex'} w-full md:w-auto h-full`}>
108
+ <ChatList
109
+ chats={chats}
110
+ activeChatId={activeChatId}
111
+ onSelectChat={handleSelectChat}
112
+ onCreateGroup={handleCreateGroup}
113
+ />
114
+ </div>
115
+
116
+ {/* Main Chat Window - Hidden on mobile if no chat selected */}
117
+ <div className={`${isMobileView && !activeChatId ? 'hidden' : 'flex'} flex-1 h-full`}>
118
+ <ChatWindow
119
+ chat={activeChat}
120
+ onBack={() => setActiveChatId(null)}
121
+ onSendMessage={handleSendMessage}
122
+ />
123
+ </div>
124
+ </Layout>
125
+ );
126
+ }