add meetup event landing page

This commit is contained in:
HolgerHatGarKeineNode
2023-02-06 18:49:38 +01:00
parent a24618e074
commit 62a18bac28
24 changed files with 781 additions and 256 deletions

View File

@@ -0,0 +1,152 @@
<?php
namespace App\Http\Livewire\Meetup;
use App\Models\Country;
use App\Models\Meetup;
use App\Models\MeetupEvent;
use App\Rules\UniqueAttendeeName;
use Livewire\Component;
class LandingPageEvent extends Component
{
public MeetupEvent $meetupEvent;
public Country $country;
public ?Meetup $meetup = null;
public bool $willShowUp = false;
public bool $perhapsShowUp = false;
public string $name = '';
public function rules()
{
return [
'name' => [
'required',
new UniqueAttendeeName($this->meetupEvent)
],
];
}
public function mount()
{
$this->meetupEvent->load('meetup.users:id');
$this->meetup = $this->meetupEvent->meetup;
$this->checkShowUp();
}
public function checkShowUp()
{
$attendees = collect($this->meetupEvent->attendees);
$mightAttendees = collect($this->meetupEvent->might_attendees);
if (auth()->check() && $attendees->contains(fn($value) => str($value)->contains('id_'.auth()->id()))) {
$this->name = str($attendees->filter(fn($value) => str($value)->contains('id_'.auth()->id()))
->first())
->after('|')
->toString();
$this->willShowUp = true;
}
if (!auth()->check() && $attendees->contains(fn($value) => str($value)->contains('anon_'.session()->getId()))) {
$this->name = str($attendees->filter(fn($value) => str($value)->contains('anon_'.session()->getId()))
->first())
->after('|')
->toString();
$this->willShowUp = true;
}
if (auth()->check() && $mightAttendees->contains(fn($value) => str($value)->contains('id_'.auth()->id()))) {
$this->name = str($mightAttendees->filter(fn($value) => str($value)->contains('id_'.auth()->id()))
->first())
->after('|')
->toString();
$this->perhapsShowUp = true;
}
if (!auth()->check() && $mightAttendees->contains(fn($value
) => str($value)->contains('anon_'.session()->getId()))) {
$this->name = str($mightAttendees->filter(fn($value) => str($value)->contains('anon_'.session()->getId()))
->first())
->after('|')
->toString();
$this->perhapsShowUp = true;
}
}
public function cannotCome()
{
$attendees = collect($this->meetupEvent->attendees);
$mightAttendees = collect($this->meetupEvent->might_attendees);
if (auth()->check() && $attendees->contains(fn($value) => str($value)->contains('id_'.auth()->id()))) {
$attendees = $attendees->filter(fn($value) => !str($value)->contains('id_'.auth()->id()));
$this->willShowUp = false;
}
if (!auth()->check() && $attendees->contains(fn($value) => str($value)->contains('anon_'.session()->getId()))) {
$attendees = $attendees->filter(fn($value) => !str($value)->contains('anon_'.session()->getId()));
$this->willShowUp = false;
}
if (auth()->check() && $mightAttendees->contains(fn($value) => str($value)->contains('id_'.auth()->id()))) {
$mightAttendees = $mightAttendees->filter(fn($value) => !str($value)->contains('id_'.auth()->id()));
$this->perhapsShowUp = false;
}
if (!auth()->check() && $mightAttendees->contains(fn($value
) => str($value)->contains('anon_'.session()->getId()))) {
$mightAttendees = $mightAttendees->filter(fn($value) => !str($value)->contains('anon_'.session()->getId()));
$this->perhapsShowUp = false;
}
$this->meetupEvent->update([
'attendees' => $attendees->toArray(),
'might_attendees' => $mightAttendees->toArray(),
]);
}
public function attend()
{
$this->validate();
$attendees = collect($this->meetupEvent->attendees);
if (auth()->check() && !$attendees->contains('id_'.auth()->id().'|'.$this->name)) {
$attendees->push('id_'.auth()->id().'|'.$this->name);
$this->willShowUp = true;
}
if (!auth()->check() && !$attendees->contains('anon_'.session()->getId().'|'.$this->name)) {
$attendees->push('anon_'.session()->getId().'|'.$this->name);
$this->willShowUp = true;
}
$this->meetupEvent->update([
'attendees' => $attendees->toArray(),
]);
}
public function mightAttend()
{
$this->validate();
$mightAttendees = collect($this->meetupEvent->might_attendees);
if (auth()->check() && !$mightAttendees->contains('id_'.auth()->id().'|'.$this->name)) {
$mightAttendees->push('id_'.auth()->id().'|'.$this->name);
$this->perhapsShowUp = true;
}
if (!auth()->check() && !$mightAttendees->contains('anon_'.session()->getId().'|'.$this->name)) {
$mightAttendees->push('anon_'.session()->getId().'|'.$this->name);
$this->perhapsShowUp = true;
}
$this->meetupEvent->update([
'might_attendees' => $mightAttendees->toArray(),
]);
}
public function render()
{
return view('livewire.meetup.landing-page-event');
}
}

View File

@@ -17,9 +17,8 @@ class MeetupEventTable extends DataTableComponent
public function configure(): void
{
$this->setPrimaryKey('id')
->setAdditionalSelects(['id'])
->setAdditionalSelects(['meetup_events.id','meetup_events.meetup_id'])
->setDefaultSort('start', 'asc')
->setAdditionalSelects(['meetup_events.meetup_id'])
->setThAttributes(function (Column $column) {
return [
'class' => 'px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider dark:bg-gray-800 dark:text-gray-400',

View File

@@ -21,9 +21,11 @@ class MeetupEvent extends Model
* @var array
*/
protected $casts = [
'id' => 'integer',
'meetup_id' => 'integer',
'start' => 'datetime',
'id' => 'integer',
'meetup_id' => 'integer',
'start' => 'datetime',
'attendees' => 'array',
'might_attendees' => 'array',
];
protected static function booted()

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Rules;
use App\Models\MeetupEvent;
use Illuminate\Contracts\Validation\InvokableRule;
class UniqueAttendeeName implements InvokableRule
{
/**
* Create a new rule instance.
* @return void
*/
public function __construct(public MeetupEvent $meetupEvent)
{
//
}
public function __invoke($attribute, $value, $fail)
{
$this->meetupEvent->refresh();
$attendees = collect($this->meetupEvent->attendees);
$mightAttendees = collect($this->meetupEvent->might_attendees);
$isInAttendees = $attendees
->contains(fn($v) => str($v)
->after('|')
->lower()
->toString() === str($value)
->lower()
->toString());
$isInMightAttendees = $mightAttendees
->contains(fn($v) => str($v)
->after('|')
->lower()
->toString() === str($value)
->lower()
->toString());
if ($isInAttendees) {
$fail('The name is already taken.');
}
if ($isInMightAttendees) {
$fail('The name is already taken.');
}
}
}