about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2021-02-12 00:44:51 +0000
committerZach DeCook <zachdecook@librem.one>2021-02-12 00:44:51 +0000
commitd99588ac37284194202a677ea9cc2a2ccb5846a1 (patch)
tree3d86bfd0a47ec2353597152d535f9c9e7e7ccbeb
parentb1859f40277da1d9ba53b8416f1d681f52f68cc2 (diff)
downloadprosongsa-d99588ac37284194202a677ea9cc2a2ccb5846a1.tar.gz
homepage: add server-side sorting
-rwxr-xr-xlaravel/public/index.gmi11
-rw-r--r--laravel/resources/views/welcome.blade.php12
2 files changed, 20 insertions, 3 deletions
diff --git a/laravel/public/index.gmi b/laravel/public/index.gmi
index 89db27b..492ed92 100755
--- a/laravel/public/index.gmi
+++ b/laravel/public/index.gmi
@@ -9,8 +9,15 @@ $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
 use App\Song;
 printf("20 text/gemini\r\n");
 ?>
-<?php foreach(Song::all()->pluck('title','id') as $id => $title): ?>
-=> /song.gmi.php/<?= $id ?> <?= $title ?>
+# Prosongsa Songs
+
+<?php foreach(['title','author'] as $key): ?>
+=> /?<?=$key?> Sort by <?=$key?>
+
+<?php endforeach; ?>
+
+<?php foreach(Song::all()->sortBy(getenv('QUERY_STRING')??'title')->pluck('title','id') as $id => $title): ?>
+=> /song.gmi.php/<?=$id?> <?= $title ?>
 
 <?php endforeach; ?>
 
diff --git a/laravel/resources/views/welcome.blade.php b/laravel/resources/views/welcome.blade.php
index cc0e5d3..27167fe 100644
--- a/laravel/resources/views/welcome.blade.php
+++ b/laravel/resources/views/welcome.blade.php
@@ -8,8 +8,18 @@
                 <form>
                     <input id='toc-filter' placeholder='filter songs'>
                 </form>
+                Sort by:
+                @foreach(['id','title','author'] as $key)
+                <a href='/?sort={{$key}}'>
+                    @if(($_GET['sort'] ??'title') ==$key)
+                        <i>{{$key}}</i>
+                    @else
+                        <b>{{$key}}</b>
+                    @endif
+                </a>
+                @endforeach
                 <ul id='toc'>
-                    @foreach( App\Song::all() as $song )
+                    @foreach( App\Song::orderBy($_GET['sort']??'title')->get() as $song )
                         <li>
                             <a href='{{ route('song.show', ['song' => $song]) }}'>
                                 {{ $song->name }}