Skip to content

Commit

Permalink
Improved handling of zip URLs (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni authored Nov 2, 2024
1 parent 0ac5579 commit 88d2b17
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 10 additions & 2 deletions app/Livewire/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ public function downloadEnabled(): bool
return $this->entry->download;
}

#[Computed]
public function zipUrl(): string
public function downloadZip(): void
{
if (! $this->downloadEnabled) {
return;
}

$this->redirect($this->zipUrl());
}

protected function zipUrl(): string
{
$assets = empty($this->selection)
? $this->assets->all()
Expand Down
11 changes: 7 additions & 4 deletions resources/views/components/download-button.blade.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
@props([
'as' => 'a',
'label' => __('Download'),
'url',
])

<a
href="{{ $url }}"
<{{ $as }}
{{ $attributes->twMerge('inline-flex items-center justify-center gap-1.5 p-1 text-[13px] font-medium bg-white rounded text-black hover:bg-gray-100') }}
download
@if($as === 'a')
href="{{ $url }}"
download
@endif
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="size-4">
<path fill-rule="evenodd" d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14Zm.75-10.25a.75.75 0 0 0-1.5 0v4.69L6.03 8.22a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l2.5-2.5a.75.75 0 1 0-1.06-1.06L8.75 9.44V4.75Z" clip-rule="evenodd" />
</svg>
{{ $label }}
</a>
</{{ $as }}>
3 changes: 2 additions & 1 deletion resources/views/components/gallery-toolbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
@endif

<x-download-button
url="{{ $this->zipUrl }}"
as="button"
wire:click="downloadZip"
label="{{ trans_choice('Download :count file|Download :count files', $this->assetsCount, ['count' => $this->assetsCount]) }}"
class="w-full sm:w-auto text-white px-4 gap-1.5 py-1.5 text-sm {{ count($this->selection) ? 'bg-blue-600 hover:bg-blue-700' : 'bg-black hover:bg-gray-700' }}"
/>
Expand Down

0 comments on commit 88d2b17

Please sign in to comment.