feat: publish HoloLake model-native living system source
This commit is contained in:
parent
6ad10edde1
commit
c395dd3a99
2467 changed files with 615073 additions and 0 deletions
31
product-source/hololake-platform/src/hooks/useSaveNote.ts
Normal file
31
product-source/hololake-platform/src/hooks/useSaveNote.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { useCallback } from 'react'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { isTauri, mockInvoke, updateMockContent } from '../mock-tauri'
|
||||
import { cacheNoteContent } from './useTabManagement'
|
||||
|
||||
export async function persistContent(path: string, content: string): Promise<void> {
|
||||
if (isTauri()) {
|
||||
await invoke('save_note_content', { path, content })
|
||||
} else {
|
||||
await mockInvoke('save_note_content', { path, content })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook that provides an explicit save function for note content.
|
||||
* Called on Cmd+S — no debounce, no auto-save.
|
||||
*
|
||||
* @param updateContent - callback to also update in-memory state after save
|
||||
*/
|
||||
export function useSaveNote(updateContent: (path: string, content: string) => void) {
|
||||
const saveNote = useCallback(async (path: string, content: string) => {
|
||||
await persistContent(path, content)
|
||||
cacheNoteContent(path, content)
|
||||
if (!isTauri()) {
|
||||
updateMockContent(path, content)
|
||||
}
|
||||
updateContent(path, content)
|
||||
}, [updateContent])
|
||||
|
||||
return { saveNote }
|
||||
}
|
||||
Loading…
Reference in a new issue