Added copy button and relevant logic
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 18s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 18s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 16s
Laravel Pint / pint (pull_request) Successful in 3m7s
Laravel Larastan / larastan (pull_request) Failing after 5m27s

This commit is contained in:
dhanabalan
2026-11-25 12:18:14 +05:30
parent 7b236460c1
commit 05b34cbb90
2 changed files with 45 additions and 13 deletions

View File

@@ -57,15 +57,9 @@ class SharedEditor extends Page
} }
} }
public function clearContent(): void public function copyContent(): void
{ {
SharedClipBoard::where('id', 1)->update([ $this->dispatch('copy-to-clipboard', content: $this->content);
'content' => '',
]);
$this->content = '';
$this->lastSyncedContent = '';
} }
public static function canAccess(): bool public static function canAccess(): bool

View File

@@ -58,12 +58,11 @@
{{-- Clear Button --}} {{-- Clear Button --}}
<x-filament::button <x-filament::button
color="danger" color="info"
icon="heroicon-o-trash" icon="heroicon-o-clipboard"
wire:click="clearContent" wire:click="copyContent"
wire:confirm="Are you sure you want to clear the shared clipboard?"
> >
Clear Content Copy To ClipBoard
</x-filament::button> </x-filament::button>
</div> </div>
@@ -99,4 +98,43 @@
</div> </div>
@script
<script>
$wire.on('copy-to-clipboard', (event) => {
const content = event.content;
const textarea = document.createElement('textarea');
textarea.value = content;
textarea.style.position = 'fixed';
textarea.style.left = '-9999px';
textarea.style.top = '0';
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
try {
const successful = document.execCommand('copy');
if (successful) {
new FilamentNotification()
.title('Content copied successfully!')
.success()
.send();
} else {
throw new Error('Copy command failed');
}
} catch (error) {
console.error('Clipboard copy failed:', error);
}
document.body.removeChild(textarea);
});
</script>
@endscript
</x-filament-panels::page> </x-filament-panels::page>