Skip to content
Permalink
Browse files

Merge pull request #78 from spatie/livewire

Replace JS search field with Livewire component
  • Loading branch information
freekmurze committed Sep 18, 2019
2 parents 72772d3 + ce0bcc1 commit 2bff68d420c0486eed94bdbbfd45de0cfc933141
@@ -0,0 +1,29 @@
<?php
namespace App\Http\Livewire;
use App\Models\Post;
use Illuminate\Support\Collection;
use Livewire\Component;
class Search extends Component
{
/** @var string */
public $query = '';
public function render()
{
return view('livewire.search', [
'results' => $this->getResults()
]);
}
public function getResults(): Collection
{
if ($this->query === '') {
return collect();
}
return Post::search($this->query)->take(30)->get();
}
}
@@ -112,16 +112,7 @@ public function toSearchableArray(): array
return [];
}
return [
'title' => $this->title,
'url' => $this->url,
'publish_date' => optional($this->publish_date)->timestamp,
'formatted_publish_date' => optional($this->publish_date)->format('M jS Y'),
'type' => $this->getType(),
'formatted_type' => $this->formatted_type,
'text' => substr(strip_tags($this->text), 0, 5000),
'tags' => $this->tags->implode(',')
];
return $this->toArray();
}
public static function getFeedItems()
@@ -20,8 +20,11 @@
"require": {
"php": "^7.3",
"ext-json": "*",
"ext-simplexml": "*",
"abraham/twitteroauth": "^0.7.4",
"algolia/algoliasearch-client-php": "^2.2",
"beyondcode/laravel-dump-server": "^1.3",
"calebporzio/livewire": "^0.3.5",
"doctrine/dbal": "^2.8",
"facade/ignition": "^1.4",
"fideloper/proxy": "^4.0",
@@ -46,8 +49,7 @@
"spatie/nova-backup-tool": "^2.0",
"spatie/nova-tags-field": "^2.0",
"spatie/nova-tail-tool": "^2.0",
"stripe/stripe-php": "^6.8",
"ext-simplexml": "*"
"stripe/stripe-php": "^6.8"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.4",

Some generated files are not rendered by default. Learn more.

@@ -37,9 +37,3 @@ function loadTwitter() {

document.body.appendChild(script);
}

const searchApp = document.querySelector('#search-app');

if (searchApp) {
import('./search').then(search => search.mount(searchApp));
}

This file was deleted.

This file was deleted.

This file was deleted.

@@ -24,3 +24,6 @@
<link href="https://twitter.com/freekmurze" rel="me">
<link rel="webmention" href="https://webmention.io/freek.dev/webmention" />
<link rel="pingback" href="https://webmention.io/freek.dev/xmlrpc" />
@if($livewire ?? false)
@livewireAssets
@endif
@@ -2,19 +2,13 @@
'title' => 'Search',
])

@php($livewire = true)

@section('content')
<div class="markup mb-4">
<h1>Search</h1>
</div>
<div
id="search-app"
data-app-id="{{ config('scout.algolia.id') }}"
data-api-key="{{ config('scout.algolia.public_key') }}"
data-index-name="{{ config('scout.algolia.index') }}"
>
<input
type="search"
class="bg-gray-100 px-3 pb-2 pt-3 w-full focus:outline-none border-gray-200 focus:border-gray-300 border-y-4 border-t-transparent"
>
</div>

@livewire('search')

@endsection
@@ -0,0 +1,24 @@
<input wire:model="query"
type="text"
class="bg-gray-100 px-3 pb-2 pt-3 w-full focus:outline-none border-gray-200 focus:border-gray-300 border-y-4 border-t-transparent"
>

Dit is de query {{ $query ?? 'no query' }}

@if (count($results))
<ul>
@foreach($results as $post)
<li>
<strong className="text-lg">
<a href={{ $post->url }}>{{ $post->title }}</a>
</strong>
<br/>
<a href="{{ $post->url }}" className="text-sm text-gray-700">
{{ $post->formatted_type }}
</a>
</li>
@endforeach
</ul>
@else
<p class="mt-2 text-gray-700">Nothing here…</p>
@endif

0 comments on commit 2bff68d

Please sign in to comment.
You can’t perform that action at this time.