- Add peer-to-peer polling with real-time synchronization via PeerJS - Implement vote changing, unvoting, and proper vote validation - Add modal interface for adding poll options - Fix vote inheritance issues for new users joining rooms - Create sidebar with available polls and connected peers - Add vote count synchronization across all connected peers - Implement proper vote state validation per user - Add localStorage persistence for polls and vote states - Create responsive design with modern UI components - Replace emojis with proper text-based icons - Add comprehensive error handling and user feedback - Support multiple polls with switching capabilities - Implement conflict resolution for concurrent voting
134 lines
5.7 KiB
HTML
134 lines
5.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>P2P Polling App</title>
|
|
<link rel="stylesheet" href="css/styles.css">
|
|
<script src="https://unpkg.com/peerjs@1.5.2/dist/peerjs.min.js"></script>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<header>
|
|
<h1>P2P Polling App</h1>
|
|
<div class="connection-status">
|
|
<span id="peer-id">Loading...</span>
|
|
<span id="connection-indicator" class="status-disconnected">●</span>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="main-content">
|
|
<!-- Sidebar -->
|
|
<aside class="sidebar">
|
|
<div class="sidebar-section">
|
|
<h3>Available Polls</h3>
|
|
<div class="sidebar-hint">
|
|
<p class="hint-text">Click a poll to view and vote</p>
|
|
</div>
|
|
<div id="polls-list" class="polls-list">
|
|
<p class="no-polls">No polls created yet</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="sidebar-section">
|
|
<h3>Connected Peers</h3>
|
|
<div class="peers-info">
|
|
<div class="peers-status">
|
|
<span>Count: <span id="peer-count">0</span></span>
|
|
<span id="connection-status-text" class="status-text">Disconnected</span>
|
|
</div>
|
|
<ul id="peers" class="peers-sidebar"></ul>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
|
|
<main>
|
|
<!-- Connection Setup -->
|
|
<section id="connection-section" class="section">
|
|
<h2>Connect to Peer</h2>
|
|
<div class="connection-info">
|
|
<p><strong>Host:</strong> Share your Peer ID below with others</p>
|
|
<p><strong>Joiner:</strong> Enter the host's Peer ID to connect</p>
|
|
</div>
|
|
<div class="connection-controls">
|
|
<input type="text" id="room-id" placeholder="Enter host's Peer ID to connect">
|
|
<button id="join-btn">Connect to Host / Create New Poll</button>
|
|
<button id="copy-id-btn">Copy Your Peer ID</button>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- Poll Creation -->
|
|
<section id="poll-creation" class="section hidden">
|
|
<h2>Create Poll</h2>
|
|
<div class="poll-form">
|
|
<input type="text" id="poll-question" placeholder="Enter your poll question">
|
|
<div id="options-container">
|
|
<div class="option-input">
|
|
<input type="text" class="option-text" placeholder="Option 1">
|
|
<button class="remove-option-btn hidden">Remove</button>
|
|
</div>
|
|
<div class="option-input">
|
|
<input type="text" class="option-text" placeholder="Option 2">
|
|
<button class="remove-option-btn hidden">Remove</button>
|
|
</div>
|
|
</div>
|
|
<button id="add-option-btn">+ Add Option</button>
|
|
<button id="create-poll-btn">Create Poll</button>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- Active Poll -->
|
|
<section id="active-poll" class="section hidden">
|
|
<div class="poll-header">
|
|
<h2 id="poll-question-display"></h2>
|
|
<button id="add-poll-option-btn" class="small-btn">+ Add Option</button>
|
|
</div>
|
|
|
|
<div class="vote-hint">
|
|
<p class="hint-text">Click any option to vote. Click your voted option again to remove your vote.</p>
|
|
</div>
|
|
|
|
<div id="poll-options" class="options-list"></div>
|
|
|
|
<div class="poll-actions">
|
|
<button id="reset-poll-btn">Reset Poll</button>
|
|
<button id="new-poll-btn" class="small-btn">New Poll</button>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
</div>
|
|
|
|
<!-- Loading Overlay -->
|
|
<div id="loading-overlay" class="overlay hidden">
|
|
<div class="loading-spinner"></div>
|
|
<p>Connecting...</p>
|
|
</div>
|
|
|
|
<!-- Notification Toast -->
|
|
<div id="notification" class="notification hidden"></div>
|
|
|
|
<!-- Add Option Modal -->
|
|
<div id="add-option-modal" class="modal hidden">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h3>Add New Option</h3>
|
|
<button class="modal-close" id="close-modal-btn">×</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<input type="text" id="new-option-input" placeholder="Enter new option text">
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button id="cancel-modal-btn" class="btn-secondary">Cancel</button>
|
|
<button id="save-option-btn" class="btn-primary">Add Option</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="js/peer-manager.js"></script>
|
|
<script src="js/poll-manager.js"></script>
|
|
<script src="js/ui-controller.js"></script>
|
|
<script src="js/app.js"></script>
|
|
</body>
|
|
</html>
|