forms broke somehow
This commit is contained in:
parent
a930d0f972
commit
b9400287ad
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class PostService
|
||||
{
|
||||
public static function getPostData(string $url): mixed
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Accept: application/json'
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($response !== false && $httpCode === 200) {
|
||||
return json_decode($response, true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Participant;
|
||||
use App\Services\PostService;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use function Livewire\Volt\{state, mount, rules};
|
||||
|
||||
state(['token'])->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)
|
||||
<img src ="{{ $userData['data']['profile_image_url'] ?? '' }}">
|
||||
<img src="{{ $userData['data']['profile_image_url'] ?? '' }}">
|
||||
<h1> {{ $userData['data']['username'] ?? 'Unknown' }}</h1>
|
||||
@endif
|
||||
<hr>
|
||||
|
||||
@if($isEditing)
|
||||
<form wire:submit="save">
|
||||
@if($isEditingPrompt)
|
||||
<form wire:submit="saveEditingPrompt">
|
||||
<input type="text" id="prompt" wire:model="prompt">
|
||||
|
||||
@error('prompt')
|
||||
|
|
@ -70,15 +103,15 @@ $cancel = function () {
|
|||
|
||||
<button type="submit">Save</button>
|
||||
|
||||
<button type="button" wire:click="cancel">Cancel</button>
|
||||
<button type="button" wire:click="cancelEditingPrompt">Cancel</button>
|
||||
</form>
|
||||
@else
|
||||
<div class="prompt-display">
|
||||
<p>
|
||||
Your prompt is: {{ $prompt ?: 'No prompt set yet.' }}
|
||||
Your prompt is: {{ $prompt ?: 'No prompt set yet.' }}
|
||||
</p>
|
||||
|
||||
<button wire:click="$set('isEditing', true)">
|
||||
<button wire:click="$set('isEditingPrompt', true)">
|
||||
{{ $prompt ? 'Edit Prompt' : 'Add Prompt' }}
|
||||
</button>
|
||||
</div>
|
||||
|
|
@ -89,10 +122,46 @@ $cancel = function () {
|
|||
@if($participant->giving_id)
|
||||
You are giving to <p>{{ $participant->giving_id }}</p>
|
||||
@if($receiverUserData)
|
||||
<img src ="{{ $receiverUserData['data']['profile_image_url'] ?? '' }}">
|
||||
<img src="{{ $receiverUserData['data']['profile_image_url'] ?? '' }}">
|
||||
<h1> {{ $receiverUserData['data']['username'] ?? 'Unknown' }}</h1>
|
||||
@endif
|
||||
{{ "Their prompt is... {$receiverPrompt}" ?: 'No prompt set yet.' }}
|
||||
Their prompt is... {{$receiverPrompt}}
|
||||
|
||||
<p> Are you done? Link to your post below </p>
|
||||
@if($isEditingSubmission)
|
||||
<form wire:submit="saveEditingSubmission">
|
||||
<input type="text" id="submissionUrl" wire:model="submissionUrl">
|
||||
|
||||
@error('submissionUrl')
|
||||
<span class="error">{{ $message }}</span>
|
||||
@enderror
|
||||
|
||||
<button type="submit">Save</button>
|
||||
|
||||
<button type="button" wire:click="cancelEditingSubmission">Cancel</button>
|
||||
</form>
|
||||
@else
|
||||
<div class="submissionUrl-display">
|
||||
<p>
|
||||
Your submission URL is: <span
|
||||
id="submissionUrl">{{ $submissionUrl ?: 'No submission sent yet.' }}</span>
|
||||
</p>
|
||||
|
||||
<button wire:click="$set('isEditingSubmission', true)">
|
||||
{{ $submissionUrl ? 'Edit Submission URL' : 'Add Submission URL' }}
|
||||
</button>
|
||||
</div>
|
||||
@endif
|
||||
<hr>
|
||||
@if($submissionData)
|
||||
<h1>Your submission:</h1>
|
||||
<div id="postView">
|
||||
<a href="{{$submissionUrl}}">
|
||||
<h1>{{$submissionData['post']['title']}}</h1>
|
||||
<img src="{{$submissionData['post']['resource_url']}}">
|
||||
</a>
|
||||
</div>
|
||||
@endif
|
||||
@elseif($participant->desperate)
|
||||
<p>You're in a bind!</p>
|
||||
@else
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ $runMatch = function () {
|
|||
</td>
|
||||
|
||||
<td class="px-6 py-4 text-sm font-mono text-gray-500 truncate" title="{{ $participant->token }}">
|
||||
{{ Str::limit($participant->token, 15, '...') }}
|
||||
{{ $participant->token }}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
|
|
|||
Loading…
Reference in New Issue