feat: Add landing page and version history functionality

- Implemented ConditionalHome component to show LandingPage for guests and Home for authenticated users.
- Created LandingPage with login options for Google and GitHub.
- Added VersionHistoryPanel component for managing document versions.
- Integrated version history functionality into EditorPage.
- Updated API client to handle FormData correctly.
- Added styles for LandingPage and VersionHistoryPanel.
- Created version management API methods for creating, listing, restoring, and fetching document versions.
This commit is contained in:
M1ngdaXie
2026-01-19 16:14:56 -08:00
parent e363b99966
commit 0ec58ca866
10 changed files with 1577 additions and 13 deletions

View File

@@ -0,0 +1,258 @@
package handlers
import (
"fmt"
"io"
"net/http"
"strconv"
"github.com/M1ngdaXie/realtime-collab/internal/auth"
"github.com/M1ngdaXie/realtime-collab/internal/models"
"github.com/M1ngdaXie/realtime-collab/internal/store"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
type VersionHandler struct {
store *store.PostgresStore
}
func NewVersionHandler(s *store.PostgresStore) *VersionHandler {
return &VersionHandler{store: s}
}
// CreateVersion creates a manual snapshot (requires edit permission)
func (h *VersionHandler) CreateVersion(c *gin.Context) {
userID := auth.GetUserFromContext(c)
if userID == nil {
respondUnauthorized(c, "Authentication required")
return
}
documentID, err := uuid.Parse(c.Param("id"))
if err != nil {
respondBadRequest(c, "Invalid document ID")
return
}
// Check edit permission (only editors can create versions)
canEdit, err := h.store.CanEditDocument(c.Request.Context(), documentID, *userID)
if err != nil {
respondInternalError(c, "Failed to check permissions", err)
return
}
if !canEdit {
respondForbidden(c, "Edit permission required to create versions")
return
}
// Parse multipart form data
if err := c.Request.ParseMultipartForm(10 << 20); err != nil { // 10MB limit
respondBadRequest(c, "Invalid multipart form")
return
}
// Get version label (optional)
versionLabel := c.PostForm("version_label")
var labelPtr *string
if versionLabel != "" {
labelPtr = &versionLabel
}
// Get text preview (required)
textPreview := c.PostForm("text_preview")
if textPreview == "" {
respondBadRequest(c, "text_preview is required")
return
}
// Get Yjs snapshot binary (required)
file, _, err := c.Request.FormFile("yjs_snapshot")
if err != nil {
respondBadRequest(c, "yjs_snapshot file is required")
return
}
defer file.Close()
snapshotData, err := io.ReadAll(file)
if err != nil || len(snapshotData) == 0 {
respondBadRequest(c, "Failed to read snapshot data")
return
}
// Validate snapshot size (max 10MB)
if len(snapshotData) > 10*1024*1024 {
respondBadRequest(c, "Snapshot too large (max 10MB)")
return
}
// Create version (manual snapshot)
version, err := h.store.CreateDocumentVersion(
c.Request.Context(),
documentID,
*userID,
snapshotData,
&textPreview,
labelPtr,
false, // is_auto_generated = false
)
if err != nil {
respondInternalError(c, "Failed to create version", err)
return
}
c.JSON(http.StatusCreated, version)
}
// ListVersions returns paginated version history (requires view permission)
func (h *VersionHandler) ListVersions(c *gin.Context) {
userID := auth.GetUserFromContext(c)
if userID == nil {
respondUnauthorized(c, "Authentication required")
return
}
documentID, err := uuid.Parse(c.Param("id"))
if err != nil {
respondBadRequest(c, "Invalid document ID")
return
}
// Check view permission
canView, err := h.store.CanViewDocument(c.Request.Context(), documentID, *userID)
if err != nil {
respondInternalError(c, "Failed to check permissions", err)
return
}
if !canView {
respondForbidden(c, "View permission required")
return
}
// Parse pagination params
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "50"))
offset, _ := strconv.Atoi(c.DefaultQuery("offset", "0"))
if limit > 100 {
limit = 100 // Max limit
}
versions, total, err := h.store.ListDocumentVersions(c.Request.Context(), documentID, limit, offset)
if err != nil {
respondInternalError(c, "Failed to list versions", err)
return
}
c.JSON(http.StatusOK, models.VersionListResponse{
Versions: versions,
Total: total,
})
}
// GetVersionSnapshot returns the Yjs binary snapshot for a specific version
func (h *VersionHandler) GetVersionSnapshot(c *gin.Context) {
userID := auth.GetUserFromContext(c)
if userID == nil {
respondUnauthorized(c, "Authentication required")
return
}
versionID, err := uuid.Parse(c.Param("versionId"))
if err != nil {
respondBadRequest(c, "Invalid version ID")
return
}
// Get version
version, err := h.store.GetDocumentVersion(c.Request.Context(), versionID)
if err != nil {
respondNotFound(c, "version")
return
}
// Check permission on parent document
canView, err := h.store.CanViewDocument(c.Request.Context(), version.DocumentID, *userID)
if err != nil {
respondInternalError(c, "Failed to check permissions", err)
return
}
if !canView {
respondForbidden(c, "View permission required")
return
}
// Return binary snapshot
c.Data(http.StatusOK, "application/octet-stream", version.YjsSnapshot)
}
// RestoreVersion creates a new version from an old snapshot (non-destructive)
func (h *VersionHandler) RestoreVersion(c *gin.Context) {
userID := auth.GetUserFromContext(c)
if userID == nil {
respondUnauthorized(c, "Authentication required")
return
}
documentID, err := uuid.Parse(c.Param("id"))
if err != nil {
respondBadRequest(c, "Invalid document ID")
return
}
// Check edit permission
canEdit, err := h.store.CanEditDocument(c.Request.Context(), documentID, *userID)
if err != nil {
respondInternalError(c, "Failed to check permissions", err)
return
}
if !canEdit {
respondForbidden(c, "Edit permission required to restore versions")
return
}
var req models.RestoreVersionRequest
if err := c.ShouldBindJSON(&req); err != nil {
respondWithValidationError(c, err)
return
}
// Get the version to restore
oldVersion, err := h.store.GetDocumentVersion(c.Request.Context(), req.VersionID)
if err != nil {
respondNotFound(c, "version")
return
}
// Verify version belongs to this document
if oldVersion.DocumentID != documentID {
respondBadRequest(c, "Version does not belong to this document")
return
}
// Update current document state with old snapshot
if err := h.store.UpdateDocumentState(documentID, oldVersion.YjsSnapshot); err != nil {
respondInternalError(c, "Failed to restore document state", err)
return
}
// Create new version entry marking it as a restore
restoreLabel := fmt.Sprintf("Restored from version %d", oldVersion.VersionNumber)
newVersion, err := h.store.CreateDocumentVersion(
c.Request.Context(),
documentID,
*userID,
oldVersion.YjsSnapshot,
oldVersion.TextPreview,
&restoreLabel,
false, // Manual restore
)
if err != nil {
respondInternalError(c, "Failed to create restore version", err)
return
}
c.JSON(http.StatusOK, gin.H{
"message": "Version restored successfully",
"new_version": newVersion,
})
}

View File

@@ -142,7 +142,7 @@ func (s *PostgresStore) ListDocumentVersions(
// GetDocumentVersion retrieves a specific version with full snapshot
func (s *PostgresStore) GetDocumentVersion(ctx context.Context, versionID uuid.UUID) (*models.DocumentVersion, error) {
query := `
SELECT id, document_id, yjs_snapshot, text_preview, ve rsion_number,
SELECT id, document_id, yjs_snapshot, text_preview, version_number,
created_by, version_label, is_auto_generated, created_at
FROM document_versions
WHERE id = $1

View File

@@ -1,11 +1,27 @@
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { AuthProvider } from "./contexts/AuthContext";
import { AuthProvider, useAuth } from "./contexts/AuthContext";
import ProtectedRoute from "./components/ProtectedRoute";
import LoginPage from "./pages/LoginPage";
import AuthCallback from "./pages/AuthCallback";
import EditorPage from "./pages/EditorPage.tsx";
import Home from "./pages/Home.tsx";
import KanbanPage from "./pages/KanbanPage.tsx";
import LandingPage from "./pages/LandingPage.tsx";
// Conditional component that shows LandingPage for guests, Home for authenticated users
function ConditionalHome() {
const { user, loading } = useAuth();
if (loading) {
return <div className="loading">Loading...</div>;
}
if (!user) {
return <LandingPage />;
}
return <Home />;
}
function App() {
return (
@@ -14,14 +30,7 @@ function App() {
<Routes>
<Route path="/login" element={<LoginPage />} />
<Route path="/auth/callback" element={<AuthCallback />} />
<Route
path="/"
element={
<ProtectedRoute>
<Home />
</ProtectedRoute>
}
/>
<Route path="/" element={<ConditionalHome />} />
<Route
path="/editor/:id"
element={

View File

@@ -3,9 +3,13 @@ const API_BASE_URL = import.meta.env.VITE_API_URL || "https://docnest-backend-mi
export async function authFetch(url: string, options?: RequestInit): Promise<Response> {
const token = localStorage.getItem('auth_token');
const headers: Record<string, string> = {
'Content-Type': 'application/json',
};
const headers: Record<string, string> = {};
// Only set Content-Type for non-FormData requests
// FormData needs browser to auto-set multipart/form-data with boundary
if (!(options?.body instanceof FormData)) {
headers['Content-Type'] = 'application/json';
}
// Merge existing headers if provided
if (options?.headers) {

View File

@@ -84,3 +84,86 @@ export const documentsApi = {
return response.json();
},
};
// Version History Types
export type DocumentVersion = {
id: string;
document_id: string;
text_preview: string | null;
version_number: number;
created_by: string | null;
version_label: string | null;
is_auto_generated: boolean;
created_at: string;
author?: {
id: string;
email: string;
name: string;
avatar_url?: string;
};
};
export type VersionListResponse = {
versions: DocumentVersion[];
total: number;
};
// Version History API
export const versionsApi = {
// Create manual snapshot
create: async (
documentId: string,
yjsSnapshot: Uint8Array,
textPreview: string,
versionLabel?: string
): Promise<DocumentVersion> => {
const formData = new FormData();
// Create a copy of the buffer to ensure compatibility
const buffer = new ArrayBuffer(yjsSnapshot.byteLength);
new Uint8Array(buffer).set(yjsSnapshot);
formData.append('yjs_snapshot', new Blob([buffer]));
formData.append('text_preview', textPreview);
if (versionLabel) {
formData.append('version_label', versionLabel);
}
const response = await authFetch(`${API_BASE_URL}/documents/${documentId}/versions`, {
method: 'POST',
body: formData,
});
if (!response.ok) throw new Error('Failed to create version');
return response.json();
},
// List versions (paginated)
list: async (
documentId: string,
limit: number = 50,
offset: number = 0
): Promise<VersionListResponse> => {
const response = await authFetch(
`${API_BASE_URL}/documents/${documentId}/versions?limit=${limit}&offset=${offset}`
);
if (!response.ok) throw new Error('Failed to fetch versions');
return response.json();
},
// Get version snapshot (binary)
getSnapshot: async (documentId: string, versionId: string): Promise<Uint8Array> => {
const response = await authFetch(
`${API_BASE_URL}/documents/${documentId}/versions/${versionId}/snapshot`
);
if (!response.ok) throw new Error('Failed to fetch snapshot');
return new Uint8Array(await response.arrayBuffer());
},
// Restore version
restore: async (documentId: string, versionId: string): Promise<{ message: string }> => {
const response = await authFetch(`${API_BASE_URL}/documents/${documentId}/restore`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ version_id: versionId }),
});
if (!response.ok) throw new Error('Failed to restore version');
return response.json();
},
};

View File

@@ -0,0 +1,374 @@
.version-panel-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.3);
z-index: 1000;
animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes slideIn {
from {
transform: translateX(100%);
}
to {
transform: translateX(0);
}
}
.version-panel {
position: fixed;
right: 0;
top: 0;
width: 400px;
height: 100vh;
background: white;
box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
display: flex;
flex-direction: column;
animation: slideIn 0.2s ease;
}
.version-panel-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 24px;
border-bottom: 1px solid #e2e8f0;
}
.version-panel-header h2 {
margin: 0;
font-size: 18px;
font-weight: 600;
color: #1a202c;
}
.close-button {
background: none;
border: none;
font-size: 28px;
color: #718096;
cursor: pointer;
padding: 0;
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 6px;
transition: all 0.2s ease;
}
.close-button:hover {
background: #f7fafc;
color: #2d3748;
}
.version-panel-actions {
padding: 16px 24px;
border-bottom: 1px solid #e2e8f0;
}
.create-version-btn {
width: 100%;
padding: 10px 16px;
background: #667eea;
color: white;
border: none;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
.create-version-btn:hover {
background: #5568d3;
}
.version-panel-content {
flex: 1;
overflow-y: auto;
padding: 16px 24px;
}
.loading-state,
.empty-state {
text-align: center;
padding: 40px 20px;
color: #718096;
}
.empty-state p {
margin: 0 0 8px 0;
font-size: 15px;
}
.empty-state small {
font-size: 13px;
color: #a0aec0;
}
.message {
padding: 12px 16px;
border-radius: 6px;
margin-bottom: 16px;
font-size: 14px;
}
.message.error {
background: #fff5f5;
color: #c53030;
border: 1px solid #feb2b2;
}
.version-list {
display: flex;
flex-direction: column;
gap: 12px;
}
.version-item {
background: #f7fafc;
border: 1px solid #e2e8f0;
border-radius: 8px;
padding: 14px;
transition: all 0.2s ease;
}
.version-item:hover {
border-color: #cbd5e0;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.version-header {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
flex-wrap: wrap;
}
.version-number {
font-weight: 600;
font-size: 14px;
color: #2d3748;
}
.auto-badge {
background: #e8f4fd;
color: #3182ce;
padding: 2px 8px;
border-radius: 10px;
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
}
.version-label {
color: #667eea;
font-size: 13px;
font-weight: 500;
}
.version-meta {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 13px;
color: #718096;
margin-bottom: 8px;
}
.version-author {
display: flex;
align-items: center;
gap: 6px;
}
.author-avatar {
width: 20px;
height: 20px;
border-radius: 50%;
object-fit: cover;
}
.version-time {
color: #a0aec0;
}
.version-preview {
font-size: 13px;
color: #4a5568;
line-height: 1.5;
margin-bottom: 12px;
padding: 8px;
background: white;
border-radius: 4px;
border: 1px solid #edf2f7;
max-height: 60px;
overflow: hidden;
}
.restore-btn {
width: 100%;
padding: 8px 12px;
background: white;
color: #667eea;
border: 1px solid #667eea;
border-radius: 6px;
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
.restore-btn:hover:not(:disabled) {
background: #667eea;
color: white;
}
.restore-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.pagination {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 0;
margin-top: 16px;
border-top: 1px solid #e2e8f0;
}
.pagination button {
padding: 8px 16px;
background: #f7fafc;
border: 1px solid #e2e8f0;
border-radius: 6px;
font-size: 13px;
cursor: pointer;
transition: all 0.2s ease;
}
.pagination button:hover:not(:disabled) {
background: #edf2f7;
}
.pagination button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.pagination span {
font-size: 13px;
color: #718096;
}
/* Create Version Modal */
.create-modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 2000;
}
.create-modal {
background: white;
border-radius: 12px;
padding: 24px;
width: 90%;
max-width: 400px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.create-modal h3 {
margin: 0 0 8px 0;
font-size: 18px;
color: #1a202c;
}
.create-modal p {
margin: 0 0 20px 0;
font-size: 14px;
color: #718096;
}
.create-modal label {
display: block;
font-size: 14px;
font-weight: 500;
color: #2d3748;
margin-bottom: 8px;
}
.create-modal input {
width: 100%;
padding: 10px 12px;
border: 1px solid #e2e8f0;
border-radius: 6px;
font-size: 14px;
margin-bottom: 20px;
box-sizing: border-box;
}
.create-modal input:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.modal-buttons {
display: flex;
gap: 12px;
justify-content: flex-end;
}
.modal-buttons button {
padding: 10px 20px;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
.modal-buttons button:not(.primary) {
background: #f7fafc;
color: #4a5568;
border: 1px solid #e2e8f0;
}
.modal-buttons button:not(.primary):hover {
background: #edf2f7;
}
.modal-buttons button.primary {
background: #667eea;
color: white;
border: none;
}
.modal-buttons button.primary:hover:not(:disabled) {
background: #5568d3;
}
.modal-buttons button:disabled {
opacity: 0.6;
cursor: not-allowed;
}

View File

@@ -0,0 +1,298 @@
import { useState, useEffect } from 'react';
import { versionsApi, type DocumentVersion } from '../../api/document';
import * as Y from 'yjs';
import './VersionHistoryPanel.css';
interface VersionHistoryPanelProps {
documentId: string;
ydoc: Y.Doc | null;
canEdit: boolean;
onClose: () => void;
}
function formatTimeAgo(dateString: string): string {
const date = new Date(dateString);
const now = new Date();
const seconds = Math.floor((now.getTime() - date.getTime()) / 1000);
if (seconds < 60) return 'just now';
if (seconds < 3600) return `${Math.floor(seconds / 60)} min ago`;
if (seconds < 86400) return `${Math.floor(seconds / 3600)} hours ago`;
if (seconds < 604800) return `${Math.floor(seconds / 86400)} days ago`;
return date.toLocaleDateString();
}
function VersionHistoryPanel({ documentId, ydoc, canEdit, onClose }: VersionHistoryPanelProps) {
const [versions, setVersions] = useState<DocumentVersion[]>([]);
const [total, setTotal] = useState(0);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [restoring, setRestoring] = useState<string | null>(null);
const [offset, setOffset] = useState(0);
const [showCreateModal, setShowCreateModal] = useState(false);
const [versionLabel, setVersionLabel] = useState('');
const [creating, setCreating] = useState(false);
const LIMIT = 20;
useEffect(() => {
loadVersions();
}, [documentId, offset]);
const loadVersions = async () => {
setLoading(true);
setError(null);
try {
const data = await versionsApi.list(documentId, LIMIT, offset);
setVersions(data.versions || []);
setTotal(data.total);
} catch (err) {
console.error('Failed to load versions:', err);
setError('Failed to load version history');
} finally {
setLoading(false);
}
};
const handleRestore = async (version: DocumentVersion) => {
if (!canEdit) {
alert('You need edit permission to restore versions');
return;
}
if (!confirm(`Restore to version ${version.version_number}? This will create a new version from the restored content.`)) {
return;
}
setRestoring(version.id);
try {
await versionsApi.restore(documentId, version.id);
// Clear IndexedDB cache so restored state is used on reload
// (y-indexeddb uses documentId as the database name)
await new Promise<void>((resolve, reject) => {
const request = indexedDB.deleteDatabase(documentId);
request.onsuccess = () => resolve();
request.onerror = () => reject(request.error);
});
alert('Version restored successfully! The page will reload to sync changes.');
window.location.reload();
} catch (err) {
console.error('Failed to restore version:', err);
alert('Failed to restore version');
} finally {
setRestoring(null);
}
};
const handleCreateVersion = async (e: React.FormEvent) => {
e.preventDefault();
if (!ydoc) {
alert('Document not loaded');
return;
}
setCreating(true);
try {
// Get Yjs state
const yjsSnapshot = Y.encodeStateAsUpdate(ydoc);
// Extract text preview from document (use placeholder if empty)
const textPreview = extractTextFromYjs(ydoc) || '(empty document)';
await versionsApi.create(documentId, yjsSnapshot, textPreview, versionLabel || undefined);
setShowCreateModal(false);
setVersionLabel('');
await loadVersions();
alert('Version created successfully!');
} catch (err) {
console.error('Failed to create version:', err);
alert('Failed to create version');
} finally {
setCreating(false);
}
};
const extractTextFromYjs = (doc: Y.Doc): string => {
try {
const xmlFragment = doc.getXmlFragment('default');
let text = '';
const extractText = (item: Y.XmlElement | Y.XmlText | Y.Item): void => {
if (item instanceof Y.XmlText) {
text += item.toString();
} else if (item instanceof Y.XmlElement) {
// Add newline for block elements
if (['paragraph', 'heading', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'].includes(item.nodeName)) {
if (text.length > 0) text += '\n';
}
item.toArray().forEach((child) => extractText(child as Y.XmlElement | Y.XmlText));
}
};
xmlFragment.toArray().forEach((item) => extractText(item as Y.XmlElement | Y.XmlText));
return text.trim();
} catch (err) {
console.error('Failed to extract text:', err);
return '';
}
};
const handleNextPage = () => {
if (offset + LIMIT < total) {
setOffset(offset + LIMIT);
}
};
const handlePrevPage = () => {
if (offset > 0) {
setOffset(Math.max(0, offset - LIMIT));
}
};
return (
<div className="version-panel-overlay" onClick={onClose}>
<div className="version-panel" onClick={(e) => e.stopPropagation()}>
<div className="version-panel-header">
<h2>Version History</h2>
<button className="close-button" onClick={onClose}>&times;</button>
</div>
{canEdit && (
<div className="version-panel-actions">
<button
className="create-version-btn"
onClick={() => setShowCreateModal(true)}
>
+ Save Current Version
</button>
</div>
)}
<div className="version-panel-content">
{error && <div className="message error">{error}</div>}
{loading ? (
<div className="loading-state">Loading versions...</div>
) : versions.length === 0 ? (
<div className="empty-state">
<p>No versions yet</p>
<small>Versions are created when you save manually or automatically over time</small>
</div>
) : (
<div className="version-list">
{versions.map((version) => (
<div key={version.id} className="version-item">
<div className="version-header">
<span className="version-number">v{version.version_number}</span>
{version.is_auto_generated && (
<span className="auto-badge">Auto</span>
)}
{version.version_label && (
<span className="version-label">{version.version_label}</span>
)}
</div>
<div className="version-meta">
{version.author ? (
<div className="version-author">
{version.author.avatar_url && (
<img
src={version.author.avatar_url}
alt={version.author.name}
className="author-avatar"
/>
)}
<span>{version.author.name || version.author.email}</span>
</div>
) : (
<span className="version-author">Unknown user</span>
)}
<span className="version-time">{formatTimeAgo(version.created_at)}</span>
</div>
{version.text_preview && (
<div className="version-preview">
{version.text_preview.length > 150
? version.text_preview.substring(0, 150) + '...'
: version.text_preview}
</div>
)}
{canEdit && (
<button
className="restore-btn"
onClick={() => handleRestore(version)}
disabled={restoring === version.id}
>
{restoring === version.id ? 'Restoring...' : 'Restore'}
</button>
)}
</div>
))}
</div>
)}
{total > LIMIT && (
<div className="pagination">
<button onClick={handlePrevPage} disabled={offset === 0}>
&larr; Previous
</button>
<span>
{offset + 1}-{Math.min(offset + LIMIT, total)} of {total}
</span>
<button onClick={handleNextPage} disabled={offset + LIMIT >= total}>
Next &rarr;
</button>
</div>
)}
</div>
{/* Create Version Modal */}
{showCreateModal && (
<div className="create-modal-overlay" onClick={() => setShowCreateModal(false)}>
<div className="create-modal" onClick={(e) => e.stopPropagation()}>
<h3>Save Version</h3>
<p>Create a snapshot of the current document state.</p>
<form onSubmit={handleCreateVersion}>
<label htmlFor="version-label">Version Label (optional)</label>
<input
id="version-label"
type="text"
value={versionLabel}
onChange={(e) => setVersionLabel(e.target.value)}
placeholder="e.g., Before major changes"
maxLength={100}
/>
<div className="modal-buttons">
<button
type="button"
onClick={() => setShowCreateModal(false)}
disabled={creating}
>
Cancel
</button>
<button
type="submit"
className="primary"
disabled={creating}
>
{creating ? 'Creating...' : 'Save Version'}
</button>
</div>
</form>
</div>
</div>
)}
</div>
</div>
);
}
export default VersionHistoryPanel;

View File

@@ -4,6 +4,7 @@ import Editor from "../components/Editor/Editor.tsx";
import Navbar from "../components/Navbar.tsx";
import UserList from "../components/Presence/UserList.tsx";
import ShareModal from "../components/Share/ShareModal.tsx";
import VersionHistoryPanel from "../components/VersionHistory/VersionHistoryPanel.tsx";
import { useYjsDocument } from "../hooks/useYjsDocument.ts";
const EditorPage = () => {
@@ -13,6 +14,7 @@ const EditorPage = () => {
const shareToken = searchParams.get('share') || undefined;
const { providers, synced, permission, role } = useYjsDocument(id!, shareToken);
const [showShareModal, setShowShareModal] = useState(false);
const [showVersionHistory, setShowVersionHistory] = useState(false);
if (!providers) {
return <div className="loading">Connecting...</div>;
@@ -38,6 +40,11 @@ const EditorPage = () => {
Share
</button>
)}
{!shareToken && (
<button className="history-btn" onClick={() => setShowVersionHistory(true)}>
History
</button>
)}
</div>
</div>
@@ -58,6 +65,15 @@ const EditorPage = () => {
currentRole={role || undefined}
/>
)}
{showVersionHistory && (
<VersionHistoryPanel
documentId={id!}
ydoc={providers.ydoc}
canEdit={permission === "edit"}
onClose={() => setShowVersionHistory(false)}
/>
)}
</div>
);
};

View File

@@ -0,0 +1,375 @@
/* Landing Page Styles */
.landing-page {
min-height: 100vh;
overflow-x: hidden;
}
/* ========================================
Hero Section
======================================== */
.landing-hero {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
overflow: hidden;
padding: 2rem;
/* Animated gradient background */
background: linear-gradient(
135deg,
var(--pixel-purple-deep) 0%,
var(--pixel-purple-bright) 40%,
var(--pixel-pink-vibrant) 100%
);
background-size: 200% 200%;
animation: gradient-shift 12s ease infinite;
}
@keyframes gradient-shift {
0%, 100% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
}
.hero-content {
text-align: center;
z-index: 10;
max-width: 800px;
}
.hero-logo {
display: flex;
align-items: center;
justify-content: center;
gap: 16px;
margin-bottom: 2rem;
}
.hero-brand {
font-size: 3rem;
font-weight: 800;
color: var(--pixel-white);
text-shadow:
4px 4px 0 var(--pixel-shadow-dark),
-1px -1px 0 var(--pixel-shadow-dark),
1px -1px 0 var(--pixel-shadow-dark),
-1px 1px 0 var(--pixel-shadow-dark);
margin: 0;
letter-spacing: -1px;
}
.hero-headline {
font-size: 2.5rem;
font-weight: 700;
color: var(--pixel-white);
margin: 0 0 1.5rem 0;
text-shadow: 2px 2px 0 var(--pixel-shadow-dark);
line-height: 1.2;
}
.hero-tagline {
font-size: 1.25rem;
color: var(--pixel-bg-light);
margin: 0 0 3rem 0;
line-height: 1.6;
opacity: 0.95;
}
.hero-login-buttons {
display: flex;
flex-direction: column;
gap: 1rem;
align-items: center;
}
.hero-scroll-hint {
position: absolute;
bottom: 2rem;
left: 50%;
transform: translateX(-50%);
color: var(--pixel-white);
opacity: 0.6;
animation: bounce-hint 2s ease-in-out infinite;
}
@keyframes bounce-hint {
0%, 100% {
transform: translateX(-50%) translateY(0);
}
50% {
transform: translateX(-50%) translateY(10px);
}
}
/* ========================================
Login Buttons
======================================== */
.landing-login-button {
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
padding: 1rem 2rem;
font-size: 1rem;
font-weight: 600;
border: 3px solid var(--pixel-outline);
cursor: pointer;
transition: transform 0.05s ease, box-shadow 0.05s ease;
min-width: 260px;
}
.landing-login-button.google {
background: var(--pixel-white);
color: var(--pixel-text-primary);
box-shadow: 4px 4px 0 var(--pixel-shadow-dark);
}
.landing-login-button.google:hover {
transform: translate(-2px, -2px);
box-shadow: 6px 6px 0 var(--pixel-shadow-dark);
background: var(--pixel-panel);
}
.landing-login-button.google:active {
transform: translate(2px, 2px);
box-shadow: 2px 2px 0 var(--pixel-shadow-dark);
}
.landing-login-button.github {
background: var(--pixel-bg-dark);
color: var(--pixel-white);
box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.5);
}
.landing-login-button.github:hover {
transform: translate(-2px, -2px);
box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.5);
background: var(--pixel-bg-medium);
}
.landing-login-button.github:active {
transform: translate(2px, 2px);
box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
}
.landing-login-button.large {
padding: 1.25rem 2.5rem;
font-size: 1.125rem;
min-width: 300px;
}
.oauth-icon {
flex-shrink: 0;
}
/* ========================================
Features Section
======================================== */
.landing-features {
padding: 6rem 2rem;
background: var(--pixel-bg-light);
position: relative;
}
.section-title {
text-align: center;
font-size: 2.5rem;
font-weight: 700;
color: var(--pixel-text-primary);
margin: 0 0 4rem 0;
text-shadow: 2px 2px 0 var(--pixel-white);
}
.features-grid {
display: grid;
grid-template-columns: 1fr;
gap: 2rem;
max-width: 1200px;
margin: 0 auto;
}
.feature-card {
background: var(--pixel-white);
padding: 2.5rem 2rem;
border: 3px solid var(--pixel-outline);
box-shadow:
0 0 0 3px var(--pixel-outline),
6px 6px 0 var(--pixel-shadow-dark),
6px 6px 0 3px var(--pixel-outline);
text-align: center;
transition: transform 0.1s ease, box-shadow 0.1s ease;
opacity: 0;
animation: fade-in-up 0.6s ease forwards;
}
.feature-card:nth-child(1) { animation-delay: 0.1s; }
.feature-card:nth-child(2) { animation-delay: 0.2s; }
.feature-card:nth-child(3) { animation-delay: 0.3s; }
.feature-card:nth-child(4) { animation-delay: 0.4s; }
@keyframes fade-in-up {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.feature-card:hover {
transform: translate(-3px, -3px);
box-shadow:
0 0 0 3px var(--pixel-outline),
9px 9px 0 var(--pixel-shadow-dark),
9px 9px 0 3px var(--pixel-outline);
}
.feature-icon {
margin-bottom: 1.5rem;
}
.feature-title {
font-size: 1.25rem;
font-weight: 700;
color: var(--pixel-text-primary);
margin: 0 0 0.75rem 0;
}
.feature-description {
font-size: 1rem;
color: var(--pixel-text-secondary);
margin: 0;
line-height: 1.5;
}
/* ========================================
Footer Section
======================================== */
.landing-footer {
padding: 6rem 2rem;
background: var(--pixel-bg-dark);
position: relative;
overflow: hidden;
}
.footer-content {
text-align: center;
max-width: 600px;
margin: 0 auto;
position: relative;
z-index: 10;
}
.footer-headline {
font-size: 2rem;
font-weight: 700;
color: var(--pixel-white);
margin: 0 0 1rem 0;
text-shadow: 2px 2px 0 var(--pixel-shadow-dark);
}
.footer-tagline {
font-size: 1.125rem;
color: var(--pixel-bg-light);
margin: 0 0 2.5rem 0;
opacity: 0.9;
}
.footer-login-buttons {
display: flex;
justify-content: center;
margin-bottom: 3rem;
}
.footer-tech {
font-size: 0.875rem;
color: var(--pixel-text-muted);
margin: 0;
}
/* ========================================
Responsive Design
======================================== */
/* Tablet (768px+) */
@media (min-width: 768px) {
.hero-brand {
font-size: 4rem;
}
.hero-headline {
font-size: 3rem;
}
.hero-tagline {
font-size: 1.5rem;
}
.hero-login-buttons {
flex-direction: row;
gap: 1.5rem;
}
.features-grid {
grid-template-columns: repeat(2, 1fr);
}
.section-title {
font-size: 3rem;
}
}
/* Desktop (1024px+) */
@media (min-width: 1024px) {
.hero-brand {
font-size: 4.5rem;
}
.hero-headline {
font-size: 3.5rem;
}
.features-grid {
grid-template-columns: repeat(4, 1fr);
}
.feature-card {
padding: 2rem 1.5rem;
}
}
/* Large Desktop (1280px+) */
@media (min-width: 1280px) {
.hero-headline {
font-size: 4rem;
}
}
/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
.landing-hero {
animation: none;
}
.hero-scroll-hint {
animation: none;
}
.feature-card {
animation: none;
opacity: 1;
}
}

View File

@@ -0,0 +1,147 @@
import FloatingGem from '../components/PixelSprites/FloatingGem';
import PixelIcon from '../components/PixelIcon/PixelIcon';
import './LandingPage.css';
const API_BASE_URL = import.meta.env.VITE_API_URL || "https://docnest-backend-mingda.fly.dev/api";
function LandingPage() {
const handleGoogleLogin = () => {
window.location.href = `${API_BASE_URL}/auth/google`;
};
const handleGitHubLogin = () => {
window.location.href = `${API_BASE_URL}/auth/github`;
};
return (
<div className="landing-page">
{/* Hero Section */}
<section className="landing-hero">
<FloatingGem position={{ top: '10%', left: '8%' }} delay={0} size={44} />
<FloatingGem position={{ top: '15%', right: '12%' }} delay={1.5} size={36} />
<FloatingGem position={{ top: '45%', left: '5%' }} delay={2.5} size={28} />
<FloatingGem position={{ bottom: '25%', right: '8%' }} delay={3.5} size={40} />
<FloatingGem position={{ bottom: '15%', left: '15%' }} delay={4} size={32} />
<FloatingGem position={{ top: '60%', right: '20%' }} delay={1} size={24} />
<div className="hero-content">
<div className="hero-logo">
<PixelIcon name="gem" size={56} color="var(--pixel-yellow-gold)" />
<h1 className="hero-brand">DocNest</h1>
</div>
<h2 className="hero-headline">Create Together. In Real-Time.</h2>
<p className="hero-tagline">
Collaborative documents and Kanban boards that sync instantly.
<br />
Work with your team from anywhere, even offline.
</p>
<div className="hero-login-buttons">
<button className="landing-login-button google" onClick={handleGoogleLogin}>
<GoogleIcon />
<span>Sign in with Google</span>
</button>
<button className="landing-login-button github" onClick={handleGitHubLogin}>
<GitHubIcon />
<span>Sign in with GitHub</span>
</button>
</div>
</div>
<div className="hero-scroll-hint">
<PixelIcon name="back-arrow" size={24} style={{ transform: 'rotate(-90deg)' }} />
</div>
</section>
{/* Features Section */}
<section className="landing-features">
<h2 className="section-title">Why DocNest?</h2>
<div className="features-grid">
<FeatureCard
icon="sync-arrows"
title="Real-Time Collaboration"
description="See changes as they happen. Multiple cursors show who's working where."
color="var(--pixel-cyan-bright)"
/>
<FeatureCard
icon="document"
title="Rich Documents"
description="Create formatted documents with headings, lists, and more."
color="var(--pixel-purple-bright)"
/>
<FeatureCard
icon="kanban"
title="Kanban Boards"
description="Drag-and-drop task management with real-time updates."
color="var(--pixel-orange-warm)"
/>
<FeatureCard
icon="shield"
title="Offline Support"
description="Your work syncs automatically when you're back online."
color="var(--pixel-green-lime)"
/>
</div>
</section>
{/* Footer CTA */}
<footer className="landing-footer">
<FloatingGem position={{ top: '20%', left: '10%' }} delay={0.5} size={28} />
<FloatingGem position={{ bottom: '30%', right: '12%' }} delay={2} size={32} />
<div className="footer-content">
<h3 className="footer-headline">Ready to collaborate?</h3>
<p className="footer-tagline">Join thousands of teams creating together.</p>
<div className="footer-login-buttons">
<button className="landing-login-button google large" onClick={handleGoogleLogin}>
<GoogleIcon />
<span>Get Started Free</span>
</button>
</div>
<p className="footer-tech">Built with Yjs, React, and Go</p>
</div>
</footer>
</div>
);
}
function FeatureCard({ icon, title, description, color }: {
icon: string;
title: string;
description: string;
color: string;
}) {
return (
<div className="feature-card">
<div className="feature-icon" style={{ color }}>
<PixelIcon name={icon} size={48} color={color} />
</div>
<h3 className="feature-title">{title}</h3>
<p className="feature-description">{description}</p>
</div>
);
}
function GoogleIcon() {
return (
<svg className="oauth-icon" width="20" height="20" viewBox="0 0 24 24">
<path fill="#4285f4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" />
<path fill="#34a853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" />
<path fill="#fbbc05" d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" />
<path fill="#ea4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" />
</svg>
);
}
function GitHubIcon() {
return (
<svg className="oauth-icon" width="20" height="20" viewBox="0 0 24 24">
<path fill="currentColor" d="M12 2A10 10 0 0 0 2 12c0 4.42 2.87 8.17 6.84 9.5.5.08.66-.23.66-.5v-1.69c-2.77.6-3.36-1.34-3.36-1.34-.46-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.6.07-.6 1 .07 1.53 1.03 1.53 1.03.87 1.52 2.34 1.07 2.91.83.09-.65.35-1.09.63-1.34-2.22-.25-4.55-1.11-4.55-4.92 0-1.11.38-2 1.03-2.71-.1-.25-.45-1.29.1-2.64 0 0 .84-.27 2.75 1.02.79-.22 1.65-.33 2.5-.33.85 0 1.71.11 2.5.33 1.91-1.29 2.75-1.02 2.75-1.02.55 1.35.2 2.39.1 2.64.65.71 1.03 1.6 1.03 2.71 0 3.82-2.34 4.66-4.57 4.91.36.31.69.92.69 1.85V21c0 .27.16.59.67.5C19.14 20.16 22 16.42 22 12A10 10 0 0 0 12 2z" />
</svg>
);
}
export default LandingPage;