mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
feat(#129): add iCal response parser
This commit is contained in:
parent
838db288e7
commit
60f2a38169
12 changed files with 513 additions and 49 deletions
87
resources/views/recipes/holidays-ical.blade.php
Normal file
87
resources/views/recipes/holidays-ical.blade.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
@props(['size' => 'full'])
|
||||
@php
|
||||
use Carbon\Carbon;
|
||||
|
||||
$events = collect($data['ical'] ?? [])
|
||||
->map(function (array $event): array {
|
||||
$start = null;
|
||||
$end = null;
|
||||
|
||||
try {
|
||||
$start = isset($event['DTSTART']) ? Carbon::parse($event['DTSTART'])->setTimezone(config('app.timezone')) : null;
|
||||
} catch (Exception $e) {
|
||||
$start = null;
|
||||
}
|
||||
|
||||
try {
|
||||
$end = isset($event['DTEND']) ? Carbon::parse($event['DTEND'])->setTimezone(config('app.timezone')) : null;
|
||||
} catch (Exception $e) {
|
||||
$end = null;
|
||||
}
|
||||
|
||||
return [
|
||||
'summary' => $event['SUMMARY'] ?? 'Untitled event',
|
||||
'location' => $event['LOCATION'] ?? null,
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
];
|
||||
})
|
||||
->filter(fn ($event) => $event['start'])
|
||||
->sortBy('start')
|
||||
->take($size === 'quadrant' ? 5 : 8)
|
||||
->values();
|
||||
@endphp
|
||||
|
||||
<x-trmnl::view size="{{$size}}">
|
||||
<x-trmnl::layout class="layout--col gap--small">
|
||||
<x-trmnl::table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<x-trmnl::title>Date</x-trmnl::title>
|
||||
</th>
|
||||
<th>
|
||||
<x-trmnl::title>Time</x-trmnl::title>
|
||||
</th>
|
||||
<th>
|
||||
<x-trmnl::title>Event</x-trmnl::title>
|
||||
</th>
|
||||
<th>
|
||||
<x-trmnl::title>Location</x-trmnl::title>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse($events as $event)
|
||||
<tr>
|
||||
<td>
|
||||
<x-trmnl::label>{{ $event['start']?->format('D, M j') }}</x-trmnl::label>
|
||||
</td>
|
||||
<td>
|
||||
<x-trmnl::label>
|
||||
{{ $event['start']?->format('H:i') }}
|
||||
@if($event['end'])
|
||||
– {{ $event['end']->format('H:i') }}
|
||||
@endif
|
||||
</x-trmnl::label>
|
||||
</td>
|
||||
<td>
|
||||
<x-trmnl::label variant="primary">{{ $event['summary'] }}</x-trmnl::label>
|
||||
</td>
|
||||
<td>
|
||||
<x-trmnl::label variant="inverted">{{ $event['location'] ?? '—' }}</x-trmnl::label>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<x-trmnl::label>No events available</x-trmnl::label>
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</x-trmnl::table>
|
||||
</x-trmnl::layout>
|
||||
|
||||
<x-trmnl::title-bar title="Public Holidays" instance="updated: {{ now()->format('M j, H:i') }}"/>
|
||||
</x-trmnl::view>
|
||||
Loading…
Add table
Add a link
Reference in a new issue