add more hrefs for faster loading

This commit is contained in:
MuslemRahimi 2024-09-21 17:20:52 +02:00
parent 191d3f1d0c
commit e98252ad00
5 changed files with 26 additions and 52 deletions

View File

@ -1,21 +1,8 @@
<script lang="ts">
import { abbreviateNumber } from '$lib/utils';
import { goto } from '$app/navigation';
export let charNumber;
export let industryList
function formatFilename(industryName) {
// Replace spaces with hyphens
let formattedName = industryName?.replace(/ /g, '-');
// Replace "&" with "and"
formattedName = formattedName?.replace(/&/g, 'and');
// Remove any extra hyphens (e.g., from consecutive spaces)
formattedName = formattedName?.replace(/-{2,}/g, '-');
// Convert to lowercase for consistency
goto("/list/industry/"+formattedName?.toLowerCase())
}
</script>
@ -38,12 +25,13 @@ function formatFilename(industryName) {
<tbody>
{#each industryList as item}
<!-- row -->
<tr on:click={() => formatFilename(item?.industry)} class="cursor-pointer sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B]">
<td class="hover:sm:text-white text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]">
{item?.industry?.length > charNumber ? item?.industry?.slice(0,charNumber) + "..." : item?.industry}
<tr class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B]">
<td class="font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]">
<a href={`/list/industry/${item?.industry?.replace(/ /g, '-')?.replace(/&/g, 'and')?.replace(/-{2,}/g, '-')?.toLowerCase()}`} class="sm:hover:text-white text-blue-400">
{item?.industry?.length > charNumber ? item?.industry?.slice(0,charNumber) + "..." : item?.industry}
</a>
</td>
<td class="text-white text-end text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]">
{item?.numStocks}
</td>

View File

@ -58,16 +58,6 @@ const sectorNavigation = [
},
]
function sectorSelector(sector) {
const selectedSector = sectorNavigation?.find(item => item?.title === sector);
if (selectedSector) {
goto(selectedSector?.link);
} else {
// Handle the case when the sector is not found
console.error(`Sector not found: ${sector}`);
}
}
@ -93,11 +83,13 @@ $: charNumber = $screenWidth < 640 ? 20 : 30;
<!-- Content area -->
<div class="w-full">
{#each sectorList as sector}
<h2 on:click={() => sectorSelector(sector)} class="cursor-pointer text-white sm:hover:underline font-semibold text-lg sm:text-xl mt-5">
<div class="mt-4">
<a href={sectorNavigation?.find(item => item?.title === sector)?.link} class=" cursor-pointer text-white sm:hover:underline font-semibold text-lg sm:text-xl ">
Sector: {sector} <svg class="inline-block h-6 w-6 -mt-1" viewBox="0 0 20 20" fill="white" style="max-width:40px"><path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd"></path></svg>
</h2>
</a>
</div>
<div class="border-t border-gray-600 mt-5"/>
<div class="border-t border-gray-600 mt-5 "/>
<IndustryTable charNumber = {charNumber} industryList = {rawData[sector]} />
<div class="border-t border-gray-600 mt-5"/>

View File

@ -1,7 +1,6 @@
<script lang='ts'>
import { screenWidth } from '$lib/store';
import { abbreviateNumber } from '$lib/utils';
import { goto } from '$app/navigation';
export let data;
let rawData = data?.getIndustryOverview;
@ -14,7 +13,7 @@ function formatFilename(industryName) {
// Remove any extra hyphens (e.g., from consecutive spaces)
formattedName = formattedName?.replace(/-{2,}/g, '-');
// Convert to lowercase for consistency
goto("/list/industry/"+formattedName?.toLowerCase())
return "/list/industry/"+formattedName?.toLowerCase();
}
@ -52,9 +51,11 @@ $: charNumber = $screenWidth < 640 ? 20 : 30;
<tbody>
{#each rawData as item}
<!-- row -->
<tr on:click={() => formatFilename(item?.industry)} class="cursor-pointer sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B]">
<td class="hover:sm:text-white text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]">
{item?.industry?.length > charNumber ? item?.industry?.slice(0,charNumber) + "..." : item?.industry}
<tr class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B]">
<td class="font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]">
<a href={`/list/industry/${item?.industry?.replace(/ /g, '-')?.replace(/&/g, 'and')?.replace(/-{2,}/g, '-')?.toLowerCase()}`} class="sm:hover:text-white text-blue-400">
{item?.industry?.length > charNumber ? item?.industry?.slice(0,charNumber) + "..." : item?.industry}
</a>
</td>

View File

@ -57,17 +57,6 @@ const sectorNavigation = [
},
]
function sectorSelector(sector) {
const selectedSector = sectorNavigation?.find(item => item?.title === sector);
if (selectedSector) {
goto(selectedSector?.link);
} else {
// Handle the case when the sector is not found
console.error(`Sector not found: ${sector}`);
}
}
$: charNumber = $screenWidth < 640 ? 20 : 30;
@ -102,9 +91,11 @@ $: charNumber = $screenWidth < 640 ? 20 : 30;
<tbody>
{#each rawData as item}
<!-- row -->
<tr on:click={() => sectorSelector(item?.sector)} class="cursor-pointer sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B]">
<td class="hover:sm:text-white text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]">
{item?.sector?.length > charNumber ? item?.sector?.slice(0,charNumber) + "..." : item?.sector}
<tr class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B]">
<td class="font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]">
<a href={sectorNavigation?.find(listItem => listItem?.title === item?.sector)?.link} class="sm:hover:text-white text-blue-400">
{item?.sector?.length > charNumber ? item?.sector?.slice(0,charNumber) + "..." : item?.sector}
</a>
</td>

View File

@ -192,11 +192,13 @@ function getPlotOptions() {
<tbody>
{#each stockList as item}
<tr on:click={() => goto(`/stocks/${item?.symbol}`)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] cursor-pointer">
<tr class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A]">
<td class="text-sm sm:text-[1rem] whitespace-nowrap text-start text-blue-400">
{item?.symbol}
<td class="text-sm sm:text-[1rem] whitespace-nowrap text-start">
<a href={`/stocks/${item?.symbol}`} class="sm:hover:text-white text-blue-400">
{item?.symbol}
</a>
</td>
<td class="hidden sm:table-cell text-white text-sm sm:text-[1rem] whitespace-nowrap text-white text-start">