Fix: Add brief timeout before copy after share link creation for Safari, only show if succeeded

This commit is contained in:
shamoon 2023-12-07 09:40:38 -08:00
parent 9418ca10d5
commit 26901ac280
2 changed files with 15 additions and 8 deletions

View File

@ -89,7 +89,7 @@ describe('ShareLinksDropdownComponent', () => {
.mockReturnValueOnce(throwError(() => new Error('Unable to get links')))
component.documentId = 99
component.refresh()
component.ngOnInit()
fixture.detectChanges()
expect(toastSpy).toHaveBeenCalled()
})
@ -104,6 +104,7 @@ describe('ShareLinksDropdownComponent', () => {
expiration.setDate(expiration.getDate() + 7)
const copySpy = jest.spyOn(clipboard, 'copy')
copySpy.mockReturnValue(true)
const refreshSpy = jest.spyOn(component, 'refresh')
component.createLink()
@ -118,8 +119,10 @@ describe('ShareLinksDropdownComponent', () => {
fixture.detectChanges()
tick(3000)
expect(copySpy).toHaveBeenCalled()
expect(refreshSpy).toHaveBeenCalled()
expect(copySpy).toHaveBeenCalled()
expect(component.copied).toEqual(1)
tick(100) // copy timeout
}))
it('should show error on link creation if needed', () => {

View File

@ -98,12 +98,14 @@ export class ShareLinksDropdownComponent implements OnInit {
}
copy(link: PaperlessShareLink) {
this.clipboard.copy(this.getShareUrl(link))
const success = this.clipboard.copy(this.getShareUrl(link))
if (success) {
this.copied = link.id
setTimeout(() => {
this.copied = null
}, 3000)
}
}
canShare(link: PaperlessShareLink): boolean {
return (
@ -144,7 +146,9 @@ export class ShareLinksDropdownComponent implements OnInit {
.subscribe({
next: (result) => {
this.loading = false
setTimeout(() => {
this.copy(result)
}, 10)
this.refresh()
},
error: (e) => {