Add buffer page before loading the real index page

Trying to improve user perception of SLOW!
This commit is contained in:
Afiq Hamzah
2024-09-13 18:11:25 +08:00
parent 4bb788f919
commit 71f4168956
4 changed files with 251 additions and 2 deletions
+32 -1
View File
@@ -20,6 +20,37 @@ class HomeController extends Controller
$this->pembiayaanService = $pembiayaanService;
$this->middleware(['auth', 'verified']);
}
/**
* Show the application buffer page.
*
* @return \Illuminate\View\View
*/
public function buffer(Request $request)
{
$homeUrl = route('home');
$authUser = Auth::user();
$customerInfo = Http::withOptions(['verify' => config('app.api_verify')])
->get(config('api.url') . '/portal/customer/info', ['ic' => $authUser['icno']])
->json();
['gadai' => $customer_gadai, 'lelong' => $customer_lelong] = $customerInfo;
// only get lelong that is harga jualan that is not null or 0
$customer_lelong = array_filter($customer_lelong, fn($x) => $x['hargajualan'] != null && $x['hargajualan'] != 0);
$formatMoney = fn($x) => number_format($x, 2);
$getTotal = fn($x) => array_reduce($x, fn($accumulator, $current_item) => $accumulator + $current_item['bakipjm'], 0);
$total = $formatMoney($getTotal($customer_gadai));
$sixMonths = sizeOf(array_filter($customer_gadai, fn($x) => $x['tempoh'] >= 6));
$bilanganLelong = sizeOf($customer_lelong);
$bilangan = sizeof($customer_gadai) + sizeOf($customer_lelong);
return view('includes.buffer', compact('bilangan', 'sixMonths', 'total', 'bilanganLelong', 'homeUrl'));
}
/**
* Show the application dashboard.
@@ -49,7 +80,7 @@ class HomeController extends Controller
$bilanganLelong = sizeOf($customer_lelong);
$bilangan = sizeof($customer_gadai) + sizeOf($customer_lelong);
return view('includes.home', compact('bilangan', 'sixMonths', 'total', 'bilanganLelong', 'pembiayaan'));
}
}