diff --git a/app/Controllers/DirectoryController.php b/app/Controllers/DirectoryController.php index 81b9172..d08a16d 100644 --- a/app/Controllers/DirectoryController.php +++ b/app/Controllers/DirectoryController.php @@ -4,6 +4,7 @@ namespace App\Controllers; use DI\Container; use PHLAK\Config\Config; +use Slim\Psr7\Request; use Slim\Psr7\Response; use Slim\Views\Twig; use Symfony\Component\Finder\Exception\DirectoryNotFoundException; @@ -44,18 +45,29 @@ class DirectoryController * * @return \Psr\Http\Message\ResponseInterface */ - public function __invoke(Finder $files, Response $response, string $path = '.') - { + public function __invoke( + Finder $files, + Request $request, + Response $response, + string $path = '.' + ) { try { - $files = $files->in($path)->depth(0); + $files = $files->in($path); } catch (DirectoryNotFoundException $exception) { return $this->view->render($response->withStatus(404), '404.twig'); } + if ($search = $request->getQueryParams()['search'] ?? false) { + $files->name(sprintf('/(?:.*)%s(?:.*)/i', $search)); + } else { + $files->depth(0); + } + return $this->view->render($response, 'index.twig', [ 'breadcrumbs' => $this->breadcrumbs($path), 'files' => $files, 'is_root' => $this->isRoot($path), + 'search' => $search ?? null, ]); } diff --git a/app/resources/js/app.js b/app/resources/js/app.js index 3ebd53b..4e0f95a 100644 --- a/app/resources/js/app.js +++ b/app/resources/js/app.js @@ -4,10 +4,18 @@ Vue.component('file-info-modal', require('./components/file-info-modal.vue').def const app = new Vue({ el: "#app", + data: function() { + return { + search: '' + }; + }, methods: { showFileInfo(filePath) { this.$refs.fileInfoModal.show(filePath); } + }, + beforeMount: function() { + this.search = this.$el.querySelector('input[name="search"]').value; } }); diff --git a/app/resources/sass/dark-mode.scss b/app/resources/sass/dark-mode.scss index 25c1b97..0c22beb 100644 --- a/app/resources/sass/dark-mode.scss +++ b/app/resources/sass/dark-mode.scss @@ -3,6 +3,22 @@ header { @apply bg-purple-700; + + #search { + @apply bg-purple-800; + + i.fa-search { + @apply text-purple-900; + } + + a { + @apply text-purple-900; + + &:hover { + @apply text-white; + } + } + } } #content { diff --git a/app/resources/views/components/file.twig b/app/resources/views/components/file.twig index a6c8338..f70e465 100644 --- a/app/resources/views/components/file.twig +++ b/app/resources/views/components/file.twig @@ -14,7 +14,7 @@