Skip to content

Commit ad80a33

Browse files
authored
Merge pull request #3 from lara-zeus/improvements
Improvements
2 parents f0caccd + 192b0ec commit ad80a33

File tree

16 files changed

+200
-77
lines changed

16 files changed

+200
-77
lines changed

config/zeus-delia.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
'bookmark_toggle_icon' => TablesRenderHook::TOOLBAR_TOGGLE_COLUMN_TRIGGER_AFTER,
1313
],
1414

15+
'dropdown' => [
16+
'title' => 'Bookmarks',
17+
'icon' => 'heroicon-m-bookmark-square',
18+
],
19+
1520
/**
1621
* set the database tables prefix
1722
*/

database/migrations/create_bookmarks_table.php.stub

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ return new class extends Migration
1515
{
1616
Schema::create(config('zeus-delia.table-prefix').'bookmarks', function (Blueprint $table) {
1717
$table->bigIncrements('id');
18-
19-
$table->string('bookmarkable_resource');
20-
$table->string('bookmarkable_page')->nullable();
21-
$table->integer('bookmarkable_id')->nullable();
22-
18+
$table->text('url');
19+
$table->text('title');
20+
$table->string('icon');
2321
$table->integer('user_id');
2422

2523
$table->timestamps();

docs/getting-started/usage.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Usage
3+
weight: 3
4+
---
5+
6+
## Use the bookmark as a header action
7+
8+
to add the bookmark action to any filament page:
9+
10+
```php
11+
protected function getHeaderActions(): array
12+
{
13+
return [
14+
BookmarkHeaderAction::make()
15+
];
16+
}
17+
```

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ parameters:
1212
ignoreErrors:
1313
-
1414
identifier: missingType.iterableValue
15+
-
16+
identifier: missingType.generics

resources/lang/en/bookmark.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
'model_label' => 'Bookmark',
55
'plural_model_label' => 'Bookmarks',
66
'navigation_label' => 'Bookmarks',
7-
'bookmarkable_type' => 'Resource',
8-
'bookmarkable_id' => 'ID',
7+
'title' => 'Page',
8+
'created_at' => 'Added at',
99
'add' => 'Bookmark This Page',
1010
'added' => 'Bookmark Saved Successfully',
1111
'remove' => 'Remove This Bookmark',

resources/views/components/bookmark.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<div>
22
{{ ($this->bookmarkAction)([
3-
'resource' => $resource
3+
'url' => $url,
4+
'title' => $title,
5+
'icon' => $icon,
46
]) }}
57

68
<x-filament-actions::modals />
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
<div>
2-
@if(!is_bool(\Livewire\Livewire::current()) && method_exists(\Livewire\Livewire::current(),'getResource'))
3-
<livewire:delia-bookmarks
4-
:resource="\Livewire\Livewire::current()->getResource()"
5-
/>
2+
@if(!is_bool(\Livewire\Livewire::current()))
3+
@if(method_exists(\Livewire\Livewire::current(),'getResource'))
4+
@php
5+
$class = \Livewire\Livewire::current()->getResource();
6+
@endphp
7+
@else
8+
@php
9+
$class = \Livewire\Livewire::current();
10+
@endphp
11+
@endif
612
@endif
13+
14+
<livewire:delia-bookmarks
15+
:url="request()->fullUrl()"
16+
:title="$class::getNavigationLabel()"
17+
:icon="$class::getNavigationIcon()"
18+
/>
719
</div>

resources/views/filament/hooks/topbar.blade.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,28 @@
77
<x-filament::dropdown>
88
<x-slot name="trigger">
99
<x-filament::icon-button size="lg"
10-
icon="heroicon-m-bookmark-square"
10+
:icon="config('zeus-delia.dropdown.icon')"
1111
>
12-
More actions
12+
{{ config('zeus-delia.dropdown.title') }}
1313
</x-filament::icon-button>
1414
</x-slot>
1515

16-
<x-filament::dropdown.list>
17-
@foreach($bookmarks as $bookmark)
18-
@if(class_exists($bookmark->bookmarkable_resource))
19-
@php
20-
$resourceClass = app($bookmark->bookmarkable_resource);
21-
@endphp
16+
@if($bookmarks->isEmpty())
17+
<x-filament::dropdown.header icon="tabler-bookmark-off">
18+
No Bookmarks found
19+
</x-filament::dropdown.header>
20+
@else
21+
<x-filament::dropdown.list>
22+
@foreach($bookmarks as $bookmark)
2223
<x-filament::dropdown.list.item
23-
tag="a"
24-
:icon="$resourceClass->getNavigationIcon()"
25-
:href="$resourceClass->getUrl()"
24+
tag="a"
25+
:icon="$bookmark->icon"
26+
:href="$bookmark->url"
2627
>
27-
{{ $resourceClass->getNavigationLabel() }}
28+
{{ $bookmark->title }}
2829
</x-filament::dropdown.list.item>
29-
@endif
30-
@endforeach
31-
</x-filament::dropdown.list>
30+
@endforeach
31+
</x-filament::dropdown.list>
32+
@endif
3233
</x-filament::dropdown>
3334
</div>

src/Delia.php

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,48 @@
66

77
class Delia
88
{
9-
public static function exist(string $class): bool
9+
public static function exist(string $url): bool
1010
{
1111
return config('zeus-delia.models.Bookmark')::query()
12-
->where('bookmarkable_resource', $class)
12+
->where('url', $url)
1313
->where('user_id', auth()->user()->id)
1414
->exists();
1515
}
1616

17-
public static function toggle(string $class): void
17+
public static function toggle(string $url, string $title, string $icon): void
1818
{
19-
if (static::exist($class)) {
20-
config('zeus-delia.models.Bookmark')::query()
21-
->where('bookmarkable_resource', $class)
22-
->where('user_id', auth()->user()->id)
23-
->delete();
24-
25-
Notification::make()
26-
->title(__('zeus-delia::bookmark.removed'))
27-
->info()
28-
->send();
19+
if (static::exist($url)) {
20+
static::remove($url);
2921
} else {
30-
config('zeus-delia.models.Bookmark')::create([
31-
'bookmarkable_resource' => $class,
32-
'user_id' => auth()->user()->id,
33-
]);
34-
35-
Notification::make()
36-
->title(__('zeus-delia::bookmark.added'))
37-
->success()
38-
->send();
22+
static::add($url, $title, $icon);
3923
}
4024
}
25+
26+
public static function add(string $url, string $title, string $icon): void
27+
{
28+
config('zeus-delia.models.Bookmark')::create([
29+
'url' => $url,
30+
'title' => $title,
31+
'icon' => $icon,
32+
'user_id' => auth()->user()->id,
33+
]);
34+
35+
Notification::make()
36+
->title(__('zeus-delia::bookmark.added'))
37+
->success()
38+
->send();
39+
}
40+
41+
public static function remove(string $url): void
42+
{
43+
config('zeus-delia.models.Bookmark')::query()
44+
->where('url', $url)
45+
->where('user_id', auth()->user()->id)
46+
->delete();
47+
48+
Notification::make()
49+
->title(__('zeus-delia::bookmark.removed'))
50+
->info()
51+
->send();
52+
}
4153
}

src/Filament/Actions/BookmarkAction.php

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

0 commit comments

Comments
 (0)