Added shared editor page
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 17s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 17s
This commit is contained in:
75
app/Filament/Pages/SharedEditor.php
Normal file
75
app/Filament/Pages/SharedEditor.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\SharedClipBoard;
|
||||
use Filament\Pages\Page;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class SharedEditor extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-s-clipboard-document';
|
||||
|
||||
protected static string $view = 'filament.pages.shared-editor';
|
||||
|
||||
protected static ?string $navigationLabel = 'Shared Clipboard';
|
||||
|
||||
protected static ?string $title = 'Shared Clipboard';
|
||||
|
||||
public string $content = '';
|
||||
|
||||
public string $lastSyncedContent = '';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$clipboard = SharedClipBoard::firstOrCreate(
|
||||
['id' => 1],
|
||||
['content' => '']
|
||||
);
|
||||
|
||||
$this->content = $clipboard->content ?? '';
|
||||
|
||||
$this->lastSyncedContent = $this->content;
|
||||
}
|
||||
|
||||
public function updatedContent(): void
|
||||
{
|
||||
SharedClipBoard::where('id', 1)->update([
|
||||
'content' => $this->content,
|
||||
]);
|
||||
|
||||
$this->lastSyncedContent = $this->content;
|
||||
}
|
||||
|
||||
public function refreshSharedContent(): void
|
||||
{
|
||||
$sharedContent = SharedClipBoard::find(1)?->content ?? '';
|
||||
|
||||
// Do not overwrite text that this user is editing.
|
||||
if (
|
||||
$this->content === $this->lastSyncedContent
|
||||
&& $sharedContent !== $this->lastSyncedContent
|
||||
) {
|
||||
$this->content = $sharedContent;
|
||||
|
||||
$this->lastSyncedContent = $sharedContent;
|
||||
}
|
||||
}
|
||||
|
||||
public function clearContent(): void
|
||||
{
|
||||
SharedClipBoard::where('id', 1)->update([
|
||||
'content' => '',
|
||||
]);
|
||||
|
||||
$this->content = '';
|
||||
|
||||
$this->lastSyncedContent = '';
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Auth::check() && Auth::user()->can('view shared clipboard page');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user