feat: add excerpt column to db, add preveiw&copy story to text editor

This commit is contained in:
MTG2000
2022-05-20 16:51:02 +03:00
parent 4e307e071e
commit 32374b97d0
6 changed files with 85 additions and 21 deletions

View File

@@ -4,3 +4,4 @@ export * from "./usePressHolder";
export * from "./useInfiniteQuery";
export * from "./useReachedBottom";
export * from "./useAutoResizableTextArea";
export * from "./useCopyToClipboard";

View 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