diff --git a/config/config.php b/config/config.php index 6042a97..3d6bd57 100755 --- a/config/config.php +++ b/config/config.php @@ -15,6 +15,13 @@ */ 'endpoint' => env('MAILTHIEF_ENDPOINT', 'emails'), + /** + * The theme which to use + * + * Supported: tailwind, bootstrap + */ + 'theme' => env('MAILTHIEF_THEME', 'tailwind'), + /** * Middleware classes to protect the inbox. */ diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index d1adf71..938fd1f 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -5,25 +5,11 @@ MailThief Inbox - @livewireStyles() - -
-
-
- -

- MailThief Inbox -

-
-
-
- @livewire('mailthief::inbox') -
-
-
- + + @livewireScripts() + diff --git a/resources/views/livewire/bootstrap.blade.php b/resources/views/livewire/bootstrap.blade.php new file mode 100644 index 0000000..f6b4252 --- /dev/null +++ b/resources/views/livewire/bootstrap.blade.php @@ -0,0 +1,180 @@ +
+ + + +
+
+ +

+ MailThief Inbox +

+
+
+
+
+
+
+ + +
+ +
+ {{ $emails->links() }} +
+ +
    + @foreach ($emails as $singleEmail) +
  • !empty($email) && $email->id == $singleEmail->id, + ]) + role="button" + wire:click="selectEmail({{ $singleEmail->id }})" + wire:key="email-{{ $singleEmail->id }}" + > +
    +
    + {{ $singleEmail->subject }}
    + + {{ collect($singleEmail->to)->pluck('email')->join(', ') }} +
    + + @if($singleEmail->created_at < now()->subDay()) + {{ $singleEmail->created_at->toDateTimeLocalString() }} + @else + {{ $singleEmail->created_at->diffForHumans() }} + @endif + +
    +
    + #{{ $singleEmail->id }} + @if($singleEmail->attachments) + + + + @endif +
    +
    +
  • + @endforeach +
+
+
+ @if($email) + + + + + + + + + + + + @if($email->cc) + + + + + @endif + + @if($email->bcc) + + + + + @endif + + + + + + + + + + +
From: + @foreach($email->from as $from) + {{ data_get($from, 'name') }} {{ data_get($from, 'email') }}
+ @endforeach +
To: + @foreach($email->to as $recipient) + {{ data_get($recipient, 'name') }} {{ data_get($recipient, 'email') }}
+ @endforeach +
Cc: + @foreach($email->cc as $cc) + {{ data_get($cc, 'name') }} {{ data_get($cc, 'email') }}
+ @endforeach +
Bcc: + @foreach($email->bcc as $bcc) + {{ data_get($bcc, 'name') }}<{{ data_get($bcc, 'email') }}>
+ @endforeach +
Subject:{{ $email->subject }}
Date:{{ $email->created_at->toDateTimeLocalString() }}
+ + +
+
+
+ +
+
+
+
+ +
{{ $email->html }}
+
+
+
+
+
+ {!! nl2br($email->text) !!} +
+
+ @if($email->attachments) +
+
+
    + @foreach($email->attachments as $attachment) + {{ $attachment }}
    + @endforeach +
+
+
+ @endif +
+ @else +
+
+
No email selected
+
Please select an email from the list.
+
+
+ @endif +
+
+
+
+
+ diff --git a/resources/views/livewire/inbox.blade.php b/resources/views/livewire/inbox.blade.php deleted file mode 100644 index f3c507b..0000000 --- a/resources/views/livewire/inbox.blade.php +++ /dev/null @@ -1,157 +0,0 @@ -
-
-
- - -
- -
- {{ $emails->links() }} -
- -
    - @foreach ($emails as $singleEmail) -
  • !empty($email) && $email->id == $singleEmail->id, - ]) - role="button" - wire:click="selectEmail({{ $singleEmail->id }})" - wire:key="email-{{ $singleEmail->id }}" - > -
    -
    - {{ $singleEmail->subject }}
    - - {{ collect($singleEmail->to)->pluck('email')->join(', ') }} -
    - - @if($singleEmail->created_at < now()->subDay()) - {{ $singleEmail->created_at->toDateTimeLocalString() }} - @else - {{ $singleEmail->created_at->diffForHumans() }} - @endif - -
    -
    - #{{ $singleEmail->id }} - @if($singleEmail->attachments) - - - - @endif -
    -
    -
  • - @endforeach -
-
-
- @if($email) - - - - - - - - - - @if($email->cc) - - - - - @endif - @if($email->bcc) - - - - - @endif - - - - - - - - -
From: - @foreach($email->from as $from) - {{ @$from['name'] }} {{ @$from['email'] }}
- @endforeach -
To: - @foreach($email->to as $recipient) - {{ @$recipient['name'] }} {{ @$recipient['email'] }}
- @endforeach -
Cc: - @foreach($email->cc as $cc) - {{ @$cc['name'] }} {{ @$cc['email'] }}
- @endforeach -
Bcc: - @foreach($email->bcc as $bcc) - {{ @$bcc['name'] }} <{{ @$bcc['email'] }}>
- @endforeach -
Subject:{{ $email->subject }}
Date:{{ $email->created_at->toDateTimeLocalString() }}
- -
-
-
- -
-
-
-
-
{{ $email->html }}
-
-
-
-
- {!! nl2br($email->text) !!} -
-
- @if($email->attachments) -
-
-
    - @foreach($email->attachments as $attachment) - {{ $attachment }}
    - @endforeach -
-
-
- @endif -
- @else -
-
-
No email selected
-
Please select an email from the list.
-
-
- @endif -
-
diff --git a/resources/views/livewire/pagination/tailwind.blade.php b/resources/views/livewire/pagination/tailwind.blade.php new file mode 100644 index 0000000..2359200 --- /dev/null +++ b/resources/views/livewire/pagination/tailwind.blade.php @@ -0,0 +1,116 @@ +
+ @if ($paginator->hasPages()) + @php(isset($this->numberOfPaginatorsRendered[$paginator->getPageName()]) ? $this->numberOfPaginatorsRendered[$paginator->getPageName()]++ : $this->numberOfPaginatorsRendered[$paginator->getPageName()] = 1) + + + @endif +
diff --git a/resources/views/livewire/tailwind.blade.php b/resources/views/livewire/tailwind.blade.php new file mode 100644 index 0000000..222c1e6 --- /dev/null +++ b/resources/views/livewire/tailwind.blade.php @@ -0,0 +1,168 @@ +
+ + +
+
+ +

+ MailThief Inbox +

+
+
+
+
+
+
+
+ + +
+ +
+ {{ $emails->links() }} +
+ +
    + @foreach ($emails as $singleEmail) +
  • +
    +
    + {{ $singleEmail->subject }}
    + + {{ collect($singleEmail->to)->pluck('email')->join(', ') }} +
    + + @if($singleEmail->created_at < now()->subDay()) + {{ $singleEmail->created_at->toDateTimeLocalString() }} + @else + {{ $singleEmail->created_at->diffForHumans() }} + @endif + +
    +
    + #{{ $singleEmail->id }} + @if($singleEmail->attachments) + + + + @endif +
    +
    +
  • + @endforeach +
+
+
+ @if($email) + + + + + + + + + + + @if($email->cc) + + + + + @endif + + @if($email->bcc) + + + + + @endif + + + + + + + + +
From: + @foreach($email->from as $from) + {{ data_get($from, 'name') }} {{ data_get($from, 'email') }}
+ @endforeach +
To: + @foreach($email->to as $recipient) + {{ data_get($recipient, 'name') }} {{ data_get($recipient, 'email') }}
+ @endforeach +
Cc: + @foreach($email->cc as $cc) + {{ data_get($cc, 'name') }} {{ data_get($cc, 'email') }}
+ @endforeach +
Bcc: + @foreach($email->bcc as $bcc) + {{ data_get($bcc, 'name') }}<{{ data_get($bcc, 'email') }}>
+ @endforeach +
Subject:{{ $email->subject }}
Date:{{ $email->created_at->toDateTimeLocalString() }}
+
+ + +
+
+ +
+
+
+
{{ $email->html }}
+
+
+
+
+ {!! nl2br($email->text) !!} +
+
+ + @if($email->attachments) + + @endif +
+
+ @else +
+
No email selected
+

Please select an email from the list.

+
+ @endif +
+
+
+
+
+ +
diff --git a/src/Http/Livewire/Inbox.php b/src/Http/Livewire/Inbox.php index 8cc6353..5174d7a 100644 --- a/src/Http/Livewire/Inbox.php +++ b/src/Http/Livewire/Inbox.php @@ -13,16 +13,28 @@ class Inbox extends Component private const EMAILS_PAGE_LIMIT = 10; public $email = null; + public $email_id = null; public $search = ''; + protected $queryString = [ + 'email_id', + ]; + public function mount() { - $this->email = MailThief::latest()->first()?->refresh(); + if(!config('mailthief.theme') || !in_array(config('mailthief.theme'), ['tailwind', 'bootstrap'])) { + throw new \Exception('Please set MAILTHIEF_THEME in your .env. Available options: tailwind (default), bootstrap'); + } + + $this->selectEmail($this->email_id ?: MailThief::latest()->first()?->id); } - public function selectEmail($id) + public function selectEmail($id = null) { - $this->email = MailThief::find($id); + $this->email_id = $id; + $this->email = $id + ? MailThief::find($id) + : null; } public function updatedSearch() @@ -44,13 +56,14 @@ public function render() ->paginate(self::EMAILS_PAGE_LIMIT) ->onEachSide(1); - return view('mailthief::livewire.inbox', [ + + return view('mailthief::livewire.' . config('mailthief.theme'), [ 'emails' => $emails, ]); } public function paginationView() { - return 'mailthief::livewire.pagination.bootstrap'; + return 'mailthief::livewire.pagination.' . config('mailthief.theme'); } }