feat: Implement Share Modal for document sharing functionality

- Added ShareModal component to manage user and link sharing for documents.
- Created AuthContext to handle user authentication state and token management.
- Updated useYjsDocument hook to support sharing via tokens.
- Enhanced Yjs document creation to include user information and authentication tokens.
- Introduced AuthCallback page to handle authentication redirects and token processing.
- Modified EditorPage and KanbanPage to include share functionality.
- Created LoginPage with Google and GitHub authentication options.
- Added styles for LoginPage.
- Defined types for authentication and sharing in respective TypeScript files.
This commit is contained in:
M1ngdaXie
2026-01-06 22:03:07 -08:00
parent 8ae7fd96e8
commit 0a5e6661f1
30 changed files with 1923 additions and 118 deletions

View File

@@ -1,4 +1,4 @@
const API_BASE_URL = import.meta.env.VITE_API_URL || "http://localhost:8080/api";
import { authFetch, API_BASE_URL } from './client';
export type DocumentType = {
id: string;
@@ -16,23 +16,22 @@ export type CreateDocumentRequest = {
export const documentsApi = {
// List all documents
list: async (): Promise<{ documents: DocumentType[]; total: number }> => {
const response = await fetch(`${API_BASE_URL}/documents`);
const response = await authFetch(`${API_BASE_URL}/documents`);
if (!response.ok) throw new Error("Failed to fetch documents");
return response.json();
},
// Get a single document
get: async (id: string): Promise<DocumentType> => {
const response = await fetch(`${API_BASE_URL}/documents/${id}`);
const response = await authFetch(`${API_BASE_URL}/documents/${id}`);
if (!response.ok) throw new Error("Failed to fetch document");
return response.json();
},
// Create a new document
create: async (data: CreateDocumentRequest): Promise<DocumentType> => {
const response = await fetch(`${API_BASE_URL}/documents`, {
const response = await authFetch(`${API_BASE_URL}/documents`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (!response.ok) throw new Error("Failed to create document");
@@ -41,7 +40,7 @@ export const documentsApi = {
// Delete a document
delete: async (id: string): Promise<void> => {
const response = await fetch(`${API_BASE_URL}/documents/${id}`, {
const response = await authFetch(`${API_BASE_URL}/documents/${id}`, {
method: "DELETE",
});
if (!response.ok) throw new Error("Failed to delete document");
@@ -49,7 +48,7 @@ export const documentsApi = {
// Get document Yjs state
getState: async (id: string): Promise<Uint8Array> => {
const response = await fetch(`${API_BASE_URL}/documents/${id}/state`);
const response = await authFetch(`${API_BASE_URL}/documents/${id}/state`);
if (!response.ok) throw new Error("Failed to fetch document state");
const arrayBuffer = await response.arrayBuffer();
return new Uint8Array(arrayBuffer);
@@ -61,7 +60,7 @@ export const documentsApi = {
const buffer = new ArrayBuffer(state.byteLength);
new Uint8Array(buffer).set(state);
const response = await fetch(`${API_BASE_URL}/documents/${id}/state`, {
const response = await authFetch(`${API_BASE_URL}/documents/${id}/state`, {
method: "PUT",
headers: { "Content-Type": "application/octet-stream" },
body: buffer,