mirror of
https://github.com/aljazceru/landscape-template.git
synced 2026-01-16 04:44:29 +01:00
feat: add excerpt column to db, add preveiw© story to text editor
This commit is contained in:
@@ -4,3 +4,4 @@ export * from "./usePressHolder";
|
||||
export * from "./useInfiniteQuery";
|
||||
export * from "./useReachedBottom";
|
||||
export * from "./useAutoResizableTextArea";
|
||||
export * from "./useCopyToClipboard";
|
||||
|
||||
26
src/utils/hooks/useCopyToClipboard.ts
Normal file
26
src/utils/hooks/useCopyToClipboard.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
type CopiedValue = string | null
|
||||
type CopyFn = (text: string) => Promise<boolean> // Return success
|
||||
|
||||
function useCopyToClipboard(): CopyFn {
|
||||
|
||||
const copy: CopyFn = async text => {
|
||||
if (!navigator?.clipboard) {
|
||||
console.warn('Clipboard not supported')
|
||||
return false
|
||||
}
|
||||
|
||||
// Try to save to clipboard then save it in the state if worked
|
||||
try {
|
||||
await navigator.clipboard.writeText(text)
|
||||
return true
|
||||
} catch (error) {
|
||||
console.warn('Copy failed', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return copy
|
||||
}
|
||||
|
||||
export default useCopyToClipboard
|
||||
Reference in New Issue
Block a user