Save workspace changes

This commit is contained in:
2026-04-18 17:02:56 +02:00
parent f02ea9a711
commit 87d60af5a9
4220 changed files with 1388603 additions and 1554 deletions

View File

@@ -0,0 +1,41 @@
import { useCallback, useMemo } from 'react'
/**
* useWebShare abstracts native Web Share API with a fallback callback.
*
* Usage:
* const { canNativeShare, share } = useWebShare({ onFallback })
* share({ title, text, url })
*
* If `navigator.share` is available the browser-native share sheet opens.
* Otherwise `onFallback({ title, text, url })` is called (e.g. open a modal).
*/
export default function useWebShare({ onFallback } = {}) {
const canNativeShare = useMemo(
() => typeof navigator !== 'undefined' && typeof navigator.share === 'function',
[],
)
const share = useCallback(
async ({ title, text, url }) => {
if (canNativeShare) {
try {
await navigator.share({ title, text, url })
return { shared: true, native: true }
} catch (err) {
// User cancelled the native share — don't fall through to modal
if (err?.name === 'AbortError') {
return { shared: false, native: true }
}
}
}
// Fallback — open modal
onFallback?.({ title, text, url })
return { shared: false, native: false }
},
[canNativeShare, onFallback],
)
return { canNativeShare, share }
}