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

View File

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