Browse Source
Nostr-Signature: bb9d5c56a291e48221df96868fb925e309cb560aa350c2cf5f9c4ddd5e5c4a6b 573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc 75662c916bf4d8bb3d70cdae4e4882382692c6f1ca67598a69abe3dc96069ef6f2bda5a1b8f91b724aa43b3cb3c6b8ad6cbce286b5d165377a34a881e7275d2amain
9 changed files with 589 additions and 1201 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
/** |
||||
* Shared callbacks object for repo operations |
||||
* Consolidates common callback patterns to reduce duplication |
||||
*/ |
||||
|
||||
import type { RepoState } from '../stores/repo-state.js'; |
||||
import { rewriteImagePaths as rewriteImagePathsUtil } from './file-processing.js'; |
||||
import { findReadmeFile as findReadmeFileUtil } from './file-helpers.js'; |
||||
|
||||
export interface FileCallbacks { |
||||
getUserEmail: () => Promise<string>; |
||||
getUserName: () => Promise<string>; |
||||
loadFiles: (path: string) => Promise<void>; |
||||
loadFile: (path: string) => Promise<void>; |
||||
renderFileAsHtml: (content: string, ext: string) => Promise<void>; |
||||
applySyntaxHighlighting: (content: string, ext: string) => Promise<void>; |
||||
findReadmeFile: (fileList: Array<{ name: string; path: string; type: 'file' | 'directory' }>) => { name: string; path: string; type: 'file' | 'directory' } | null; |
||||
rewriteImagePaths: (html: string, filePath: string | null) => string; |
||||
} |
||||
|
||||
export interface BranchCallbacks { |
||||
loadBranches: () => Promise<void>; |
||||
loadFiles: (path: string) => Promise<void>; |
||||
loadFile: (path: string) => Promise<void>; |
||||
loadReadme: () => Promise<void>; |
||||
loadCommitHistory: () => Promise<void>; |
||||
loadDocumentation: () => Promise<void>; |
||||
} |
||||
|
||||
/** |
||||
* Create file callbacks from state and functions |
||||
*/ |
||||
export function createFileCallbacks( |
||||
state: RepoState, |
||||
getUserEmail: () => Promise<string>, |
||||
getUserName: () => Promise<string>, |
||||
loadFiles: (path: string) => Promise<void>, |
||||
loadFile: (path: string) => Promise<void>, |
||||
renderFileAsHtml: (content: string, ext: string) => Promise<void>, |
||||
applySyntaxHighlighting: (content: string, ext: string) => Promise<void> |
||||
): FileCallbacks { |
||||
return { |
||||
getUserEmail, |
||||
getUserName, |
||||
loadFiles, |
||||
loadFile, |
||||
renderFileAsHtml, |
||||
applySyntaxHighlighting, |
||||
findReadmeFile: findReadmeFileUtil, |
||||
rewriteImagePaths: (html: string, filePath: string | null) => { |
||||
const branch = state.git.currentBranch || state.git.defaultBranch || null; |
||||
return rewriteImagePathsUtil(html, filePath, state.npub, state.repo, branch); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* Create branch callbacks from functions |
||||
*/ |
||||
export function createBranchCallbacks( |
||||
loadBranches: () => Promise<void>, |
||||
loadFiles: (path: string) => Promise<void>, |
||||
loadFile: (path: string) => Promise<void>, |
||||
loadReadme: () => Promise<void>, |
||||
loadCommitHistory: () => Promise<void>, |
||||
loadDocumentation: () => Promise<void> |
||||
): BranchCallbacks { |
||||
return { |
||||
loadBranches, |
||||
loadFiles, |
||||
loadFile, |
||||
loadReadme, |
||||
loadCommitHistory, |
||||
loadDocumentation |
||||
}; |
||||
} |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
/** |
||||
* Safe wrapper functions for SSR compatibility |
||||
* These functions check for window availability before executing |
||||
*/ |
||||
|
||||
/** |
||||
* Safely execute an async function, returning a resolved promise if window is undefined |
||||
*/ |
||||
export function safeAsync<T>( |
||||
fn: () => Promise<T> |
||||
): Promise<T | void> { |
||||
if (typeof window === 'undefined') return Promise.resolve(); |
||||
try { |
||||
return fn(); |
||||
} catch (err) { |
||||
console.warn('Error in safe async function:', err); |
||||
return Promise.resolve(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Safely execute a sync function, returning void if window is undefined |
||||
*/ |
||||
export function safeSync<T>( |
||||
fn: () => T |
||||
): T | void { |
||||
if (typeof window === 'undefined') return; |
||||
try { |
||||
return fn(); |
||||
} catch (err) { |
||||
console.warn('Error in safe sync function:', err); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue