-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added ability to copy raw content from comment or goal description
- Loading branch information
1 parent
55f0da0
commit d8fdd7c
Showing
10 changed files
with
195 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"Edit": "Edit", | ||
"Delete": "Delete", | ||
"Save": "Save" | ||
"Save": "Save", | ||
"Copy raw": "Copy raw" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"Edit": "Изменить", | ||
"Delete": "Удалить", | ||
"Save": "Сохранить" | ||
"Save": "Сохранить", | ||
"Copy raw": "Скопировать" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/components/GoalContentHeader/GoalContentHeader.i18n/en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"No description provided": "No description provided" | ||
"No description provided": "No description provided", | ||
"Copy raw": "Copy raw" | ||
} |
3 changes: 2 additions & 1 deletion
3
src/components/GoalContentHeader/GoalContentHeader.i18n/ru.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"No description provided": "Описание отсутствует" | ||
"No description provided": "Описание отсутствует", | ||
"Copy raw": "Скопировать" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
type CopiedValue = string | null; | ||
type CopyFn = (text: string) => Promise<boolean>; | ||
|
||
export const useCopyToClipboard = (ms = 500): [CopiedValue, CopyFn, boolean] => { | ||
const [copiedText, setCopiedText] = useState<CopiedValue>(null); | ||
const [success, setSuccess] = useState(false); | ||
|
||
useEffect(() => { | ||
let timer: NodeJS.Timer; | ||
if (success) { | ||
timer = setTimeout(() => { | ||
setSuccess(false); | ||
}, ms); | ||
} | ||
|
||
return () => { | ||
window.clearTimeout(timer); | ||
}; | ||
}, [success, ms]); | ||
|
||
const copy = useCallback(async (text: string) => { | ||
try { | ||
await navigator.clipboard.writeText(text); | ||
setCopiedText(text); | ||
setSuccess(true); | ||
return true; | ||
} catch (error) { | ||
setCopiedText(null); | ||
setSuccess(false); | ||
|
||
const copyFailedError = new Error('Copy failed'); | ||
Sentry.captureException(copyFailedError); | ||
return Promise.reject(copyFailedError); | ||
} | ||
}, []); | ||
|
||
return [copiedText, copy, success]; | ||
}; |