Просмотр исходного кода

Add pagination to notifications

Daniel Supernault 7 лет назад
Родитель
Сommit
b63b8353ad
3 измененных файлов с 19 добавлено и 4 удалено
  1. 1 1
      app/Mention.php
  2. 17 3
      resources/views/account/activity.blade.php
  3. 1 0
      webpack.mix.js

+ 1 - 1
app/Mention.php

@@ -14,7 +14,7 @@ class Mention extends Model
 
     public function status()
     {
-      return $this->belongsTo(Status::class);
+      return $this->belongsTo(Status::class, 'status_id', 'id');
     }
 
     public function toText()

+ 17 - 3
resources/views/account/activity.blade.php

@@ -19,7 +19,7 @@
             <span class="text-muted notification-timestamp pl-1">{{$notification->created_at->diffForHumans(null, true, true, true)}}</span>
           </span>
           <span class="float-right notification-action">
-            @if($notification->item_id)
+            @if($notification->item_id && $notification->item_type == 'App\Status')
               <a href="{{$notification->status->url()}}"><img src="{{$notification->status->thumb()}}" width="32px" height="32px"></a>
             @endif
           </span>
@@ -70,10 +70,16 @@
             <span class="text-muted notification-timestamp pl-1">{{$notification->created_at->diffForHumans(null, true, true, true)}}</span>
           </span>
           <span class="float-right notification-action">
-            @if($notification->item_id)
+            @if($notification->item_id && $notification->item_type === 'App\Status')
+              @if(is_null($notification->status->in_reply_to_id))
               <a href="{{$notification->status->url()}}">
                 <div class="notification-image" style="background-image: url('{{$notification->status->thumb()}}')"></div>
               </a>
+              @else
+              <a href="{{$notification->status->parent()->url()}}">
+                <div class="notification-image" style="background-image: url('{{$notification->status->parent()->thumb()}}')"></div>
+              </a>
+              @endif
             @endif
           </span>
         @break
@@ -81,12 +87,20 @@
         @endswitch
       </li>
       @endforeach
+    </ul>
+
+      <div class="d-flex justify-content-center my-4">
+        {{$notifications->links()}}
+      </div>
     @else
       <div class="mt-4">
         <div class="alert alert-info font-weight-bold">No unread notifications found.</div>
       </div>
     @endif
-    </ul>
   </div>
 </div>
 @endsection
+
+@push('scripts')
+<script type="text/javascript" src="{{mix('js/activity.js')}}"></script>
+@endpush

+ 1 - 0
webpack.mix.js

@@ -12,6 +12,7 @@ let mix = require('laravel-mix');
  */
 
 mix.js('resources/assets/js/app.js', 'public/js')
+   .js('resources/assets/js/activity.js', 'public/js')
    .js('resources/assets/js/timeline.js', 'public/js')
    .sass('resources/assets/sass/app.scss', 'public/css')
    .version();