Skip to content

Commit ed62ec2

Browse files
committed
Clean up database (we will not need it) and start with Livewire component
1 parent dfb2a20 commit ed62ec2

File tree

7 files changed

+57
-51
lines changed

7 files changed

+57
-51
lines changed

README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# A Filament plugin to add a preview screen to your pages. The screen will render your website with the data from Filament, without saving it.
1+
# Filament Live Preview
22

3-
##
4-
5-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
3+
A Filament plugin to add a preview screen to your pages. The screen will render your website with the data from Filament, without saving it.
64

75
## Installation
86

@@ -12,13 +10,6 @@ You can install the package via composer:
1210
composer require wotz/filament-live-preview
1311
```
1412

15-
You can publish and run the migrations with:
16-
17-
```bash
18-
php artisan vendor:publish --tag="filament-live-preview-migrations"
19-
php artisan migrate
20-
```
21-
2213
You can publish the config file with:
2314

2415
```bash
@@ -41,8 +32,6 @@ php artisan vendor:publish --tag="filament-live-preview-views"
4132
## Usage
4233

4334
```php
44-
$filamentLivePreview = new Wotz\FilamentLivePreview();
45-
echo $filamentLivePreview->echoPhrase('Hello, Wotz!');
4635
```
4736

4837
## Documentation

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"require": {
1212
"php": "^8.2",
1313
"illuminate/contracts": "^10.0 || ^11.0",
14+
"livewire/livewire": "^3.6",
15+
"pboivin/filament-peek": "3.0.0-beta1",
1416
"spatie/laravel-package-tools": "^1.12"
1517
},
1618
"require-dev": {

database/factories/ModelFactory.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

database/migrations/2021_04_06_000000_create_package_table.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# A Filament plugin to add a preview screen to your pages. The screen will render your website with the data from Filament, without saving it.
1+
# Filament Live Preview
22

33
## Introduction
44

5+
A Filament plugin to add a preview screen to your pages. The screen will render your website with the data from Filament, without saving it.
6+
57
## Installation

src/Livewire/LivePreviewScreen.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Wotz\FilamentLivePreview\Livewire;
4+
5+
use Livewire\Attributes\Layout;
6+
use Livewire\Attributes\On;
7+
use Livewire\Component;
8+
use Pboivin\FilamentPeek\CachedPreview;
9+
10+
class LivePreviewScreen extends Component
11+
{
12+
public string $token;
13+
public string $view;
14+
public array $data = [];
15+
16+
public function mount()
17+
{
18+
abort_unless($this->token = request()->query('token'), 404);
19+
20+
$this->refreshPreview();
21+
}
22+
23+
#[Layout('layouts.app', [
24+
'titleForLayout' => 'Live Preview',
25+
'hasBgPattern' => false,
26+
'bgColor' => 'bg-gradient-to-light',
27+
])]
28+
public function render()
29+
{
30+
return view($this->view)
31+
->with($this->data);
32+
}
33+
34+
#[On('echo:live-preview,.refresh-live-preview')]
35+
public function listenForMessage()
36+
{
37+
$this->refreshPreview();
38+
}
39+
40+
private function refreshPreview()
41+
{
42+
abort_unless((bool) $preview = CachedPreview::get($this->token), 404);
43+
44+
$this->view = $preview->view;
45+
$this->data = $preview->data;
46+
47+
\Illuminate\Support\Facades\Log::info('Live preview refreshed', [$this->view, $this->data]);
48+
}
49+
}

src/Providers/FilamentLivePreviewServiceProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public function configurePackage(Package $package): void
1212
$package
1313
->name('filament-live-preview')
1414
->setBasePath(__DIR__ . '/../')
15-
->hasConfigFile()
16-
->hasMigration('create_package_table');
15+
->hasConfigFile();
1716
}
1817
}

0 commit comments

Comments
 (0)