()
| 649 | * Setup global action handlers for download and share buttons |
| 650 | */ |
| 651 | export function setupActionHandlers(): void { |
| 652 | if (actionHandlersReady) return; |
| 653 | actionHandlersReady = true; |
| 654 | |
| 655 | document.addEventListener( |
| 656 | "click", |
| 657 | async (e) => { |
| 658 | const target = (e.target as HTMLElement).closest( |
| 659 | ".action-download, .action-share" |
| 660 | ) as HTMLElement | null; |
| 661 | if (!target) return; |
| 662 | |
| 663 | e.preventDefault(); |
| 664 | e.stopPropagation(); |
| 665 | |
| 666 | const path = target.dataset.path; |
| 667 | if (!path) return; |
| 668 | |
| 669 | if (target.classList.contains("action-download")) { |
| 670 | const success = await downloadFile(path); |
| 671 | showToast( |
| 672 | success ? "Download started!" : "Download failed", |
| 673 | success ? "success" : "error" |
| 674 | ); |
| 675 | return; |
| 676 | } |
| 677 | |
| 678 | const success = await shareFile(path); |
| 679 | showToast( |
| 680 | success ? "Link copied!" : "Failed to copy link", |
| 681 | success ? "success" : "error" |
| 682 | ); |
| 683 | }, |
| 684 | true |
| 685 | ); |
| 686 | } |
| 687 | |
| 688 | let dropdownHandlersReady = false; |
| 689 | let actionHandlersReady = false; |
no test coverage detected