Skip to content

Commit

Permalink
Fixed search, again
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Feb 12, 2024
1 parent 402372d commit ad03c10
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
6 changes: 0 additions & 6 deletions src/SplashingImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ public function init(): void
function(RegisterUrlRulesEvent $event) {
$event->rules['splashing-images'] = 'splashing-images/default/index';
$event->rules['splashing-images/<page:\d+>'] = 'splashing-images/default/index';
$event->rules['splashing-images/curated'] = 'splashing-images/default/curated';
$event->rules['splashing-images/curated/<page:\d+>'] = 'splashing-images/default/curated';
$event->rules['splashing-images/likes'] = 'splashing-images/default/likes';
$event->rules['splashing-images/likes/<page:\d+>'] = 'splashing-images/default/likes';
$event->rules['splashing-images/collections'] = 'splashing-images/default/collections';
$event->rules['splashing-images/collections/<collection:\d+>'] = 'splashing-images/default/collection';
$event->rules['splashing-images/find'] = 'splashing-images/default/find';
$event->rules['splashing-images/search'] = 'splashing-images/default/search';
$event->rules['splashing-images/search/<page:\d+>'] = 'splashing-images/default/search';
Expand Down
12 changes: 5 additions & 7 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public function actionIndex($page = 1): Response
* Redirect search form submit to correct results url
* @throws \yii\web\BadRequestHttpException
*/
public function actionFind(): Response
public function actionFind()
{
$query = Craft::$app->request->getRequiredBodyParam('query');
return $this->redirect(UrlHelper::cpUrl('splashing-images/search' . '/' . $query . '/1'));
return $this->redirect(UrlHelper::cpUrl('splashing-images/search/1', ['search' => $query]));
}

/**
Expand All @@ -66,15 +66,13 @@ public function actionFind(): Response
* @param $page int
* @return bool|Response
*/
public function actionSearch(string $query, int $page): bool|Response
public function actionSearch(int $page)
{
$query = $this->request->getRequiredQueryParam('search');
if (!$query) {
return false;
}
$data = $this->unsplash->search($query, $page);
return $this->renderTemplate('splashing-images/_index', [
'query' => $query,
'data' => $data,
]);
return $this->renderTemplate('splashing-images/_search',['data' => $data]);
}
}
23 changes: 23 additions & 0 deletions src/templates/_search.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{# @var craft \craft\web\twig\variables\CraftVariable #}
{% extends "_layouts/cp" %}

{% do view.registerAssetBundle("studioespresso\\splashingimages\\assetbundles\\SplashingImages\\SplashingImagesAsset") %}

{% set plugin = craft.app.plugins.getPlugin('splashing-images') %}
{% set title = plugin.settings.pluginLabel ?? "Splashing Images" %}

{% block tabs %}
{% include 'splashing-images/_includes/_tabs' with { search: true, selectedTab: 'search'} %}
{% endblock %}

{% block actionButton %}
{% include "splashing-images/_includes/_search" %}
{% endblock %}

{% block content %}
{% include "splashing-images/_includes/_images" %}
<script type="text/javascript">
window.csrfTokenName = "{{ craft.app.config.general.csrfTokenName }}";
window.csrfTokenValue = "{{ craft.app.request.csrfToken }}";
</script>
{% endblock %}

0 comments on commit ad03c10

Please sign in to comment.