Created
December 5, 2019 14:56
-
-
Save assertchris/746ae1cbac85aafeecfb834fa3230e76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
@if ($share) | |
<h1 class="flex w-full text-3xl font-serif mb-1 py-2 border-b-2 border-gray-200">Questions for {{ $share->owner->name }}</h1> | |
@endif | |
@foreach ($sections as $sectionKey => $subsections) | |
<div class="flex flex-col w-full"> | |
<h2 class="flex w-full text-2xl font-serif mb-1"> | |
{{ __("grow.{$sectionKey}-title") }} | |
</h2> | |
@if (__("grow.{$sectionKey}-description")) | |
<div class="flex w-full mb-1"> | |
{{ __("grow.{$sectionKey}-description") }} | |
</div> | |
@endif | |
@foreach ($subsections as $i => $subsectionKey) | |
<h3 class="flex w-full text-xl font-serif mb-1"> | |
{{ __("grow.{$sectionKey}-{$subsectionKey}-title") }} | |
</h3> | |
@if (__("grow.{$sectionKey}-{$subsectionKey}-description")) | |
<div class="flex w-full mb-1"> | |
{{ __("grow.{$sectionKey}-{$subsectionKey}-description") }} | |
</div> | |
@endif | |
@foreach ($notes["{$sectionKey}-{$subsectionKey}"] as $note) | |
<div | |
class="flex w-full mb-1 py-2 border-b-2 border-gray-200" | |
wire:key="{{ $note->id }}" | |
> | |
<div | |
class=" | |
group | |
flex flex-row w-full items-center justify-start | |
@if ($note->deleted_at) | |
opacity-25 | |
@endif | |
" | |
> | |
<span | |
class=" | |
flex flex-grow flex-col | |
@if ($note->completed_at) | |
line-through | |
text-gray-500 | |
@endif | |
" | |
> | |
<span class="flex w-full">{{ $note->content }}</span> | |
<span class="flex w-full text-sm text-gray-500">{{ $note->created_at->diffForHumans() }}</span> | |
</span> | |
@if ($note->completed_at) | |
<button wire:click="uncomplete({{ $note->id }})" class="bg-blue-600 text-white py-1 px-2 rounded-sm mr-2 opacity-0 group-hover:opacity-100">wait a second!</button> | |
@else | |
<button wire:click="complete({{ $note->id }})" class="bg-blue-600 text-white py-1 px-2 rounded-sm mr-2 opacity-0 group-hover:opacity-100">complete</button> | |
@endif | |
@if ($note->deleted_at) | |
<button wire:click="undelete({{ $note->id }})" class="bg-blue-600 text-white py-1 px-2 rounded-sm opacity-0 group-hover:opacity-100">oh dear...</button> | |
@else | |
<button wire:click="delete({{ $note->id }})" class="bg-blue-600 text-white py-1 px-2 rounded-sm opacity-0 group-hover:opacity-100">delete</button> | |
@endif | |
</div> | |
</div> | |
@endforeach | |
@foreach (range(0, 2) as $i) | |
<div | |
wire:key="{{ $sectionKey . '-' . $subsectionKey . '-' . date('y-m-d-h-i-s-') . $i }}" | |
class=" | |
@if ($loop->last) | |
mb-12 | |
@endif | |
" | |
> | |
<span class="flex flex-grow"> | |
<input wire:keydown.enter="save('{{ $sectionKey }}-{{ $subsectionKey }}', $event.target.value)" class="w-full outline-none border-b-2 border-gray-200 active:border-blue-700 mb-1 py-2" /> | |
</span> | |
</div> | |
@endforeach | |
@endforeach | |
</div> | |
@endforeach | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Livewire; | |
use App\Models\Note; | |
use App\Models\User; | |
use Livewire\Component; | |
class Survey extends Component | |
{ | |
protected $owner; | |
protected $share; | |
protected $sections; | |
protected $notes; | |
public function mount($owner, $share = null) | |
{ | |
$this->owner = $owner; | |
$this->share = $share; | |
$this->sections = config("grow.sections"); | |
$this->reset(); | |
} | |
public function reset() | |
{ | |
$this->notes = []; | |
foreach ($this->sections as $sectionKey => $subsections) { | |
foreach ($subsections as $subsectionKey) { | |
$this->notes["{$sectionKey}-{$subsectionKey}"] = []; | |
} | |
} | |
$user = User::findOrFail($this->owner); | |
if ($this->share) { | |
foreach ( | |
$user | |
->notes() | |
->where("created_at", ">=", $this->share["share_after"]) | |
->get() | |
as $note | |
) { | |
$this->notes[$note->section][] = $note; | |
} | |
} else { | |
foreach ($user->notes as $note) { | |
$this->notes[$note->section][] = $note; | |
} | |
} | |
} | |
public function save($section, $value) | |
{ | |
Note::create([ | |
"section" => $section, | |
"content" => $value, | |
"owner_id" => $this->owner, | |
"author_id" => auth()->user()->id | |
]); | |
$this->reset(); | |
} | |
public function complete($note) | |
{ | |
Note::find($note)->update(["completed_at" => now()]); | |
$this->reset(); | |
} | |
public function uncomplete($note) | |
{ | |
Note::find($note)->update(["completed_at" => null]); | |
$this->reset(); | |
} | |
public function delete($note) | |
{ | |
Note::find($note)->update(["deleted_at" => now()]); | |
$this->reset(); | |
} | |
public function undelete($note) | |
{ | |
Note::find($note)->update(["deleted_at" => null]); | |
$this->reset(); | |
} | |
public function render() | |
{ | |
$sections = $this->sections; | |
$notes = $this->notes; | |
$share = $this->share; | |
return view("livewire.survey", compact("sections", "notes", "share")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment