This commit is contained in:
MuslemRahimi 2024-11-02 13:05:40 +01:00
parent 102d5a36e0
commit 8972c0ecc2
10 changed files with 46 additions and 65 deletions

View File

@ -113,7 +113,7 @@
<div class="flex flex-row items-center"> <div class="flex flex-row items-center">
<label <label
for="optionsNetFlowInfo" for="optionsNetFlowInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-xl sm:text-3xl font-bold" class="mr-1 cursor-pointer flex flex-row items-center text-white text-xl sm:text-2xl font-bold"
> >
Options Net Flow Options Net Flow
</label> </label>

View File

@ -10,7 +10,8 @@
let dataLoaded = false; // Flag to track data loading let dataLoaded = false; // Flag to track data loading
let assetType = ""; let assetType = "";
let focusedSuggestion = "";
let arrowMovement = false;
let showSuggestions = false; let showSuggestions = false;
let notFoundTicker = false; let notFoundTicker = false;
let searchQuery = ""; let searchQuery = "";
@ -164,14 +165,13 @@
const onKeyPress = (e) => { const onKeyPress = (e) => {
if (e?.charCode === 13) { if (e?.charCode === 13) {
focusedSuggestion = "";
const assetActions = { const assetActions = {
ETF: () => goto(`/etf/${searchQuery}`), ETF: () => goto(`/etf/${searchQuery}`),
Stock: () => goto(`/stocks/${searchQuery}`), Stock: () => goto(`/stocks/${searchQuery}`),
Crypto: () => goto(`/crypto/${searchQuery}`), Crypto: () => goto(`/crypto/${searchQuery}`),
}; };
console.log(arrowMovement);
if (searchResults?.length > 0) { if (!arrowMovement && searchResults?.length > 0) {
searchQuery = searchResults.at(0).symbol; searchQuery = searchResults.at(0).symbol;
assetType = searchResults.at(0).type; assetType = searchResults.at(0).type;
} }
@ -182,61 +182,42 @@
// Trigger search bar action // Trigger search bar action
searchBarTicker(searchQuery); searchBarTicker(searchQuery);
} }
console.log(focusedSuggestion);
}; };
let focusedSuggestion = null;
function handleKeyDown(event) { function handleKeyDown(event) {
const newList = searchHistory?.length > 0 ? searchHistory : popularList; if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
if (event.key === "ArrowDown" && showSuggestions) { event.preventDefault(); // Prevent scrolling
// Move down in the suggestions
event.preventDefault(); // Prevent scrolling const list = showSuggestions
const currentIndex = searchResults?.findIndex( ? searchResults
(item) => item?.symbol === searchQuery, : searchHistory?.length > 0
); ? searchHistory
if (currentIndex < searchResults?.length - 1) { : popularList;
searchQuery = searchResults[currentIndex + 1]?.symbol; if (!list?.length) return;
assetType = searchResults[currentIndex + 1]?.type;
focusedSuggestion = searchQuery; // Update the focused suggestion const currentIndex = list.findIndex((item) => item?.symbol === searchQuery);
} const isMovingDown = event.key === "ArrowDown";
} else if (event.key === "ArrowUp" && showSuggestions) {
// Move up in the suggestions // Check if movement is within bounds
event.preventDefault(); // Prevent scrolling const isValidMove = isMovingDown
const currentIndex = searchResults?.findIndex( ? currentIndex < list.length - 1
(item) => item?.symbol === searchQuery, : currentIndex > 0;
);
if (currentIndex > 0) { if (isValidMove) {
searchQuery = searchResults[currentIndex - 1]?.symbol; arrowMovement = true;
assetType = searchResults[currentIndex - 1]?.type; const newIndex = currentIndex + (isMovingDown ? 1 : -1);
focusedSuggestion = searchQuery; // Update the focused suggestion const selectedItem = list[newIndex];
}
} else if (event.key === "ArrowDown" && !showSuggestions) { // Update all related states at once
// Move down in the suggestions searchQuery = selectedItem?.symbol;
event.preventDefault(); // Prevent scrolling assetType = selectedItem?.type;
const currentIndex = newList?.findIndex( focusedSuggestion = selectedItem?.symbol;
(item) => item?.symbol === searchQuery,
);
if (currentIndex < newList?.length - 1) {
searchQuery = newList[currentIndex + 1]?.symbol;
assetType = newList[currentIndex + 1]?.type;
focusedSuggestion = searchQuery; // Update the focused suggestion
}
} else if (event.key === "ArrowUp" && !showSuggestions) {
// Move up in the suggestions
event.preventDefault(); // Prevent scrolling
const currentIndex = newList?.findIndex(
(item) => item?.symbol === searchQuery,
);
if (currentIndex > 0) {
searchQuery = newList[currentIndex - 1]?.symbol;
assetType = newList[currentIndex - 1]?.type;
focusedSuggestion = searchQuery; // Update the focused suggestion
}
} }
} }
const handleControlD = async (event) => {
const handleControlF = async (event) => {
if (event.ctrlKey && event.key === "k") { if (event.ctrlKey && event.key === "k") {
// Ctrl+F is pressed, open the modal // Ctrl+F is pressed, open the modal
const keyboardSearch = document.getElementById("searchBarModal"); const keyboardSearch = document.getElementById("searchBarModal");
@ -274,10 +255,10 @@
console.log(e); console.log(e);
} }
window.addEventListener("keydown", handleControlF); window.addEventListener("keydown", handleControlD);
window.addEventListener("keydown", handleEscape); window.addEventListener("keydown", handleEscape);
return () => { return () => {
window.removeEventListener("keydown", handleControlF); window.removeEventListener("keydown", handleControlD);
window.removeEventListener("keydown", handleEscape); window.removeEventListener("keydown", handleEscape);
}; };
}); });

View File

@ -89,7 +89,7 @@
// Reset to original data when 'none' and stop further sorting // Reset to original data when 'none' and stop further sorting
if (sortOrder === "none") { if (sortOrder === "none") {
stockList = [...originalData]; // Reset to original data (spread to avoid mutation) stockList = [...originalData]?.slice(0, 50); // Reset to original data (spread to avoid mutation)
return; return;
} }
@ -124,7 +124,7 @@
}; };
// Sort using the generic comparison function // Sort using the generic comparison function
stockList = [...originalData].sort(compareValues); stockList = [...originalData].sort(compareValues)?.slice(0, 50);
}; };
$: charNumber = $screenWidth < 640 ? 20 : 25; $: charNumber = $screenWidth < 640 ? 20 : 25;
</script> </script>

View File

@ -374,7 +374,7 @@
<main class="w-full"> <main class="w-full">
<div class="sm:p-7 m-auto mt-2 sm:mt-0"> <div class="sm:p-7 m-auto mt-2 sm:mt-0">
<div class="mb-3"> <div class="mb-3">
<h1 class="text-xl sm:text-2xl text-gray-200 font-bold"> <h1 class="text-xl sm:text-2xl text-white font-bold">
{#if $coolMode} {#if $coolMode}
{statementConfig?.find( {statementConfig?.find(
(item) => item?.propertyName === displayStatement, (item) => item?.propertyName === displayStatement,

View File

@ -459,7 +459,7 @@
<main class="w-full"> <main class="w-full">
<div class="sm:p-7 m-auto mt-2 sm:mt-0"> <div class="sm:p-7 m-auto mt-2 sm:mt-0">
<div class="mb-3"> <div class="mb-3">
<h1 class="text-xl sm:text-2xl text-gray-200 font-bold"> <h1 class="text-xl sm:text-2xl text-white font-bold">
{#if $coolMode} {#if $coolMode}
{statementConfig?.find( {statementConfig?.find(
(item) => item?.propertyName === displayStatement, (item) => item?.propertyName === displayStatement,

View File

@ -404,7 +404,7 @@
<main class="w-full"> <main class="w-full">
<div class="sm:p-7 m-auto mt-2 sm:mt-0 w-full"> <div class="sm:p-7 m-auto mt-2 sm:mt-0 w-full">
<div class="mb-3"> <div class="mb-3">
<h1 class="text-xl sm:text-2xl text-gray-200 font-bold"> <h1 class="text-xl sm:text-2xl text-white font-bold">
{#if $coolMode} {#if $coolMode}
{statementConfig?.find( {statementConfig?.find(
(item) => item?.propertyName === displayStatement, (item) => item?.propertyName === displayStatement,

View File

@ -368,7 +368,7 @@
<main class="w-full"> <main class="w-full">
<div class="sm:p-7 m-auto mt-2 sm:mt-0 w-full"> <div class="sm:p-7 m-auto mt-2 sm:mt-0 w-full">
<div class="mb-3"> <div class="mb-3">
<h1 class="text-xl sm:text-2xl text-gray-200 font-bold"> <h1 class="text-xl sm:text-2xl text-white font-bold">
{#if $coolMode} {#if $coolMode}
{statementConfig?.find( {statementConfig?.find(
(item) => item?.propertyName === displayStatement, (item) => item?.propertyName === displayStatement,

View File

@ -147,7 +147,7 @@
<div <div
class="mb-5 flex flex-col justify-between gap-y-2.5 sm:mb-2 sm:flex-row sm:items-end" class="mb-5 flex flex-col justify-between gap-y-2.5 sm:mb-2 sm:flex-row sm:items-end"
> >
<h1 class="mb-px text-xl font-bold bp:text-2xl sm:pl-1"> <h1 class="mb-px text-xl font-bold sm:text-2xl sm:pl-1">
{$displayCompanyName} Analyst Ratings {$displayCompanyName} Analyst Ratings
</h1> </h1>
<div> <div>

View File

@ -363,7 +363,7 @@
> >
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0"> <div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
<div class="mb-6"> <div class="mb-6">
<h2 class="text-xl sm:text-2xl text-gray-200 font-bold mb-4"> <h2 class="text-xl sm:text-2xl text-white font-bold mb-4">
{$stockTicker} Employees {$stockTicker} Employees
</h2> </h2>

View File

@ -396,7 +396,7 @@
<main class="w-full"> <main class="w-full">
<div class="sm:p-7 m-auto mt-2 sm:mt-0"> <div class="sm:p-7 m-auto mt-2 sm:mt-0">
<div class="mb-3"> <div class="mb-3">
<h1 class="text-xl sm:text-2xl text-gray-200 font-bold"> <h1 class="text-xl sm:text-2xl text-white font-bold">
Market Cap Market Cap
</h1> </h1>
</div> </div>