diff --git a/app/Services/PostService.php b/app/Services/PostService.php new file mode 100644 index 0000000..1570842 --- /dev/null +++ b/app/Services/PostService.php @@ -0,0 +1,26 @@ +url(); +state(['token']); state([ 'participant' => null, @@ -11,41 +13,72 @@ state([ 'receiverPrompt' => null, 'receiverUserData' => null, 'prompt' => '', - 'isEditing' => false, + 'submissionUrl' => '', + 'isEditingPrompt' => false, + 'isEditingSubmission' => false, + 'submissionData' => null ]); - +#todo - check if the post is by them, if not - reject it rules([ 'prompt' => 'required|string|min:3', + 'submissionUrl' => [ + 'required', + 'regex:/^https:\/\/sketchersunited\.org\/posts\/\d+$/', + 'max:200', + ], ]); -mount(function () { +mount(function ($token) { + $this->token = $token; if ($this->token) { $this->participant = Participant::findByToken($this->token); if ($this->participant) { $this->userData = $this->participant->getUserData(); $this->prompt = $this->participant->prompt ?? ''; - if($this->participant->receiver) { + $this->submissionUrl = $this->participant->submission_url ?? ''; + if ($this->participant->receiver) { $this->receiverPrompt = $this->participant->receiver->prompt; $this->receiverUserData = $this->participant->receiver->getUserData(); + if ($this->participant->submission_url) { + $this->submissionData = PostService::getPostData($this->participant->submission_url); + if (!$this->submissionData) { + $this->submissionData = null; + } + } } } } }); -$save = function () { +$saveEditingPrompt = function () { if ($this->participant) { $this->validate(); $this->participant->prompt = $this->prompt; $this->participant->save(); - $this->isEditing = false; + $this->isEditingPrompt = false; } }; -$cancel = function () { +$cancelEditingPrompt = function () { $this->prompt = $this->participant->prompt ?? ''; - $this->isEditing = false; + $this->isEditingPrompt = false; +}; + +$saveEditingSubmission = function () { + if ($this->participant) { + $this->validate(); + + $this->participant->submission_url = $this->submissionUrl; + $this->participant->save(); + $this->isEditingSubmission = false; + } +}; + +$cancelEditingSubmission = function () { + $this->submissionUrl = $this->participant->submission_url ?? ''; + $this->isEditingSubmission = false; }; ?> @@ -55,13 +88,13 @@ $cancel = function () { You are... {{ $participant->id }} @if($userData) - +

{{ $userData['data']['username'] ?? 'Unknown' }}

@endif
- @if($isEditing) -
+ @if($isEditingPrompt) + @error('prompt') @@ -70,15 +103,15 @@ $cancel = function () { - +
@else

- Your prompt is: {{ $prompt ?: 'No prompt set yet.' }} + Your prompt is: {{ $prompt ?: 'No prompt set yet.' }}

-
@@ -89,10 +122,46 @@ $cancel = function () { @if($participant->giving_id) You are giving to

{{ $participant->giving_id }}

@if($receiverUserData) - +

{{ $receiverUserData['data']['username'] ?? 'Unknown' }}

@endif - {{ "Their prompt is... {$receiverPrompt}" ?: 'No prompt set yet.' }} + Their prompt is... {{$receiverPrompt}} + +

Are you done? Link to your post below

+ @if($isEditingSubmission) +
+ + + @error('submissionUrl') + {{ $message }} + @enderror + + + + +
+ @else +
+

+ Your submission URL is: {{ $submissionUrl ?: 'No submission sent yet.' }} +

+ + +
+ @endif +
+ @if($submissionData) +

Your submission:

+
+ +

{{$submissionData['post']['title']}}

+ +
+
+ @endif @elseif($participant->desperate)

You're in a bind!

@else diff --git a/resources/views/livewire/pages/table.blade.php b/resources/views/livewire/pages/table.blade.php index cb2226e..0452b0a 100644 --- a/resources/views/livewire/pages/table.blade.php +++ b/resources/views/livewire/pages/table.blade.php @@ -94,7 +94,7 @@ $runMatch = function () { - {{ Str::limit($participant->token, 15, '...') }} + {{ $participant->token }} @endforeach