Skip to content

Commit

Permalink
Fix: Quicklaunch duplicating services in the list
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Papec <denis.papec@gmail.com>
  • Loading branch information
denispapec committed Oct 5, 2023
1 parent 76cbb6e commit bd70589
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/quicklaunch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear
return <span>{parts.map((part, i) => part.toLowerCase() === searchString.toLowerCase() ? <span key={`${searchString}_${i}`} className="bg-theme-300/10">{part}</span> : part)}</span>;
}

function getRandomKeyId() {
// as these are dynamically generated elements, we can generate random keys
return Math.floor(Math.random() * 100000);
}

return (
<div className={classNames(
"relative z-40 ease-in-out duration-300 transition-opacity",
Expand All @@ -168,7 +173,7 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear
results.length === 0 && "rounded-md",
"w-full p-4 m-0 border-0 border-b border-slate-700 focus:border-slate-700 focus:outline-0 focus:ring-0 text-sm md:text-xl text-theme-700 dark:text-theme-200 bg-theme-60 dark:bg-theme-800"
)} type="text" autoCorrect="false" ref={searchField} value={searchString} onChange={handleSearchChange} onKeyDown={handleSearchKeyDown} />
{results.length > 0 && <ul className="max-h-[60vh] overflow-y-auto m-2">
{results.length > 0 && <ul className="max-h-[60vh] overflow-y-auto m-2" key={`results-${getRandomKeyId()}`}>
{results.map((r, i) => (
<li key={r.container ?? r.app ?? `${r.name}-${r.href}`}>
<button type="button" data-index={i} onMouseEnter={handleItemHover} onClick={handleItemClick} onKeyDown={handleItemKeyDown} className={classNames(
Expand Down

0 comments on commit bd70589

Please sign in to comment.