Skip to content

Search #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Spatie\SiteSearch\Commands\CrawlCommand;

class Kernel extends ConsoleKernel
{
Expand All @@ -29,6 +30,7 @@ protected function schedule(Schedule $schedule)
$schedule->command('lcm:post-article-to-twitter')->twiceDaily(12, 16);
$schedule->command('lcm:post-article-to-telegram')->twiceDaily(13, 17);
$schedule->command('sitemap:generate')->daily();
$schedule->command(CrawlCommand::class)->everyThreeHours();
}

/**
Expand Down
41 changes: 41 additions & 0 deletions app/Http/Livewire/Modals/DeleteArticle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Http\Livewire\Modals;

use App\Models\Article;
use App\Policies\ArticlePolicy;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use LivewireUI\Modal\ModalComponent;

class DeleteArticle extends ModalComponent
{
use AuthorizesRequests;

public ?Article $article = null;

public function mount(int $id)
{
$this->article = Article::find($id);
}

public static function modalMaxWidth(): string
{
return 'xl';
}

public function delete()
{
$this->authorize(ArticlePolicy::DELETE, $this->article);

$this->article->delete();

session()->flash('status', 'La discussion a été supprimé avec tous ses commentaires.');

$this->redirectRoute('articles');
}

public function render()
{
return view('livewire.modals.delete-article');
}
}
46 changes: 46 additions & 0 deletions app/Spotlight/Article.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Spotlight;

use App\Models\Article as ArticleModel;
use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;
use LivewireUI\Spotlight\SpotlightCommandDependencies;
use LivewireUI\Spotlight\SpotlightCommandDependency;
use LivewireUI\Spotlight\SpotlightSearchResult;

class Article extends SpotlightCommand
{
protected string $name = 'Article';

protected string $description = 'rechercher un article spécifique';

protected array $synonyms = [];

public function dependencies(): ?SpotlightCommandDependencies
{
return SpotlightCommandDependencies::collection()
->add(
SpotlightCommandDependency::make('article')
->setPlaceholder('Rechercher un article spécifique')
);
}

public function searchArticle($query)
{
return ArticleModel::published()->where('title', 'like', "%$query%")
->get()
->map(function (ArticleModel $article) {
return new SpotlightSearchResult(
$article->slug(),
$article->title,
sprintf('par @%s', $article->author->username)
);
});
}

public function execute(Spotlight $spotlight, ArticleModel $article)
{
$spotlight->redirectRoute('articles.show', $article);
}
}
26 changes: 26 additions & 0 deletions app/Spotlight/Articles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Spotlight;

use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;

class Articles extends SpotlightCommand
{
protected string $name = 'Articles';

protected string $description = 'aller à la page des articles';

protected array $synonyms = [
'articles',
'article',
'post',
'blog',
'news',
];

public function execute(Spotlight $spotlight)
{
$spotlight->redirectRoute('articles');
}
}
46 changes: 46 additions & 0 deletions app/Spotlight/Discussion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Spotlight;

use App\Models\Discussion as DiscussionModel;
use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;
use LivewireUI\Spotlight\SpotlightCommandDependencies;
use LivewireUI\Spotlight\SpotlightCommandDependency;
use LivewireUI\Spotlight\SpotlightSearchResult;

class Discussion extends SpotlightCommand
{
protected string $name = 'Discussion';

protected string $description = 'rechercher une discussion spécifique';

protected array $synonyms = [];

public function dependencies(): ?SpotlightCommandDependencies
{
return SpotlightCommandDependencies::collection()
->add(
SpotlightCommandDependency::make('discussion')
->setPlaceholder('Rechercher une discussion spécifique')
);
}

public function searchDiscussion($query)
{
return DiscussionModel::where('title', 'like', "%$query%")
->get()
->map(function (DiscussionModel $discussion) {
return new SpotlightSearchResult(
$discussion->slug(),
$discussion->title,
sprintf('par @%s', $discussion->author->username)
);
});
}

public function execute(Spotlight $spotlight, DiscussionModel $discussion)
{
$spotlight->redirectRoute('discussions.show', $discussion);
}
}
23 changes: 23 additions & 0 deletions app/Spotlight/Discussions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Spotlight;

use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;

class Discussions extends SpotlightCommand
{
protected string $name = 'Discussions';

protected string $description = 'aller à la page des discussions';

protected array $synonyms = [
'débat',
'conversation',
];

public function execute(Spotlight $spotlight)
{
$spotlight->redirectRoute('discussions.index');
}
}
28 changes: 28 additions & 0 deletions app/Spotlight/FAQs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Spotlight;

use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;

class FAQs extends SpotlightCommand
{
protected string $name = 'FAQs';

protected string $description = 'aller à la page des questions';

protected array $synonyms = [
'faq',
'question',
'foire',
];

/**
* When all dependencies have been resolved the execute method is called.
* You can type-hint all resolved dependency you defined earlier.
*/
public function execute(Spotlight $spotlight)
{
$spotlight->redirectRoute('faq');
}
}
26 changes: 26 additions & 0 deletions app/Spotlight/Forum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Spotlight;

use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;

class Forum extends SpotlightCommand
{
protected string $name = 'Forum';

protected string $description = 'aller sur le forum';

protected array $synonyms = [
'question',
'thread',
'sujet',
'problème',
'issue',
];

public function execute(Spotlight $spotlight)
{
$spotlight->redirectRoute('forum.index');
}
}
25 changes: 25 additions & 0 deletions app/Spotlight/Guides.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Spotlight;

use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;

class Guides extends SpotlightCommand
{
protected string $name = 'Guides';

protected string $description = 'aller à la page du code de conduite';

protected array $synonyms = [
'code',
'conduite',
'règles',
'comportement',
];

public function execute(Spotlight $spotlight)
{
$spotlight->redirectRoute('rules');
}
}
26 changes: 26 additions & 0 deletions app/Spotlight/Slack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Spotlight;

use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;

class Slack extends SpotlightCommand
{
protected string $name = 'Slack';

protected string $description = 'rejoindre le Slack de Laravel Cameroun';

protected array $synonyms = [
'community',
'join',
'telegram',
'whatsapp',
'social',
];

public function execute(Spotlight $spotlight)
{
$spotlight->redirectRoute('slack');
}
}
52 changes: 52 additions & 0 deletions app/Spotlight/Sujet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Spotlight;

use App\Models\Thread;
use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;
use LivewireUI\Spotlight\SpotlightCommandDependencies;
use LivewireUI\Spotlight\SpotlightCommandDependency;
use LivewireUI\Spotlight\SpotlightSearchResult;

class Sujet extends SpotlightCommand
{
protected string $name = 'Sujet';

protected string $description = 'Rechercher un sujet dans le forum';

protected array $synonyms = [
'topic',
'sujet',
'forum',
'thread',
];

public function dependencies(): ?SpotlightCommandDependencies
{
return SpotlightCommandDependencies::collection()
->add(
SpotlightCommandDependency::make('thread')
->setPlaceholder('Rechercher un sujet dans le forum')
);
}

public function searchThread($query)
{
return Thread::where('title', 'like', "%$query%")
->get()
->map(function (Thread $thread) {
// You must map your search result into SpotlightSearchResult objects
return new SpotlightSearchResult(
$thread->slug(),
$thread->name,
sprintf('par @%s', $thread->author->username)
);
});
}

public function execute(Spotlight $spotlight, Thread $thread)
{
$spotlight->redirectRoute('forum.show', $thread);
}
}
33 changes: 33 additions & 0 deletions app/Spotlight/Telegram.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Spotlight;

use LivewireUI\Spotlight\Spotlight;
use LivewireUI\Spotlight\SpotlightCommand;

class Telegram extends SpotlightCommand
{
protected string $name = 'Telegram';

/**
* This is the description of your command which will be shown besides the command name.
*/
protected string $description = 'rejoindre le groupe sur Telegram';

/**
* You can define any number of additional search terms (also known as synonyms)
* to be used when searching for this command.
*/
protected array $synonyms = [
'channels',
'social',
'slack',
'whatsapp',
'community',
];

public function execute(Spotlight $spotlight)
{
$spotlight->redirectRoute('telegram');
}
}
Loading