-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove some stuff better search
- Loading branch information
Showing
8 changed files
with
92 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,73 @@ | ||
import { $lang } from "@/stores"; | ||
|
||
import { | ||
component$, | ||
useComputed$, | ||
useSignal, | ||
useVisibleTask$, | ||
} from "@builder.io/qwik"; | ||
import { component$, useSignal, useTask$ } from "@builder.io/qwik"; | ||
import type { SidebarEntry, SidebarProps } from "./Sidebar.astro"; | ||
import { SidebarFolder } from "./SidebarFolder"; | ||
import { SidebarLink } from "./SidebarLink"; | ||
|
||
type SidebarListProps = { | ||
type Props = { | ||
sidebarEntries: SidebarEntry[]; | ||
} & SidebarProps; | ||
|
||
export const SidebarList = component$( | ||
({ sidebarMode, sidebarEntries }: SidebarListProps) => { | ||
let renderList = useSignal<SidebarEntry[]>(sidebarEntries ?? []); | ||
let filter = useSignal(""); | ||
let filteredList = useComputed$(() => { | ||
return renderList.value.filter(({ linkList }) => | ||
linkList.some( | ||
({ title }) => | ||
(title ?? "").toLowerCase().includes( | ||
filter.value.toLowerCase(), | ||
), | ||
) | ||
); | ||
}); | ||
export const SidebarList = component$((props: Props) => { | ||
let sidebarEntries = useSignal<SidebarEntry[]>(props.sidebarEntries ?? []); | ||
let filter = useSignal(""); | ||
|
||
const searchInputRef = useSignal<HTMLInputElement>(); | ||
|
||
const searchInputRef = useSignal<HTMLInputElement>(); | ||
const allOpen = sidebarMode === "guides"; | ||
useTask$(({ track }) => { | ||
track(filter); | ||
|
||
useVisibleTask$(() => { | ||
if (!searchInputRef.value) return; | ||
const defaultValue = new URLSearchParams(location.search).get( | ||
"search", | ||
) ?? ""; | ||
if (filter.value === "") return; | ||
|
||
searchInputRef.value.defaultValue = defaultValue; | ||
filter.value = defaultValue; | ||
const newSidebarEntries = props.sidebarEntries.map((entry) => { | ||
const linkList = entry.linkList.filter((l) => | ||
(`${l.title ?? ""} ${l.description ?? ""}`).toLowerCase() | ||
.includes(filter.value.toLowerCase()) | ||
); | ||
|
||
return { | ||
...entry, | ||
linkList, | ||
}; | ||
}); | ||
|
||
return ( | ||
<> | ||
<input | ||
class="input input-primary w-full my-2" | ||
placeholder={sidebarMode === "reference" | ||
? "Search for API..." | ||
: "Search for Guides..."} | ||
bind:value={filter} | ||
ref={searchInputRef} | ||
onKeyPress$={(e) => { | ||
if (e.key === "Enter") { | ||
const search = searchInputRef.value?.value; | ||
const url = new URL(location.href); | ||
history.pushState({}, "", url.toString()); | ||
sidebarEntries.value = newSidebarEntries; | ||
|
||
if (search) filter.value = search; | ||
} | ||
}} | ||
/> | ||
console.log( | ||
newSidebarEntries.map((e) => e.linkList.map((l) => l.title)).flat(), | ||
); | ||
}); | ||
|
||
{filteredList.value.map(({ linkList, folder }) => { | ||
const filteredList = linkList.filter(( | ||
{ title }, | ||
) => (title ?? "").toLowerCase().includes( | ||
filter.value.toLowerCase(), | ||
)); | ||
return ( | ||
<> | ||
<input | ||
class="input input-primary w-full my-2" | ||
placeholder={props.sidebarMode === "reference" | ||
? "Search for API..." | ||
: "Search for Guides..."} | ||
bind:value={filter} | ||
ref={searchInputRef} | ||
/> | ||
|
||
{sidebarEntries.value.filter(({ linkList }) => linkList.length > 0) | ||
.map(({ linkList, folder }, i) => { | ||
return ( | ||
<SidebarFolder | ||
title={folder} | ||
id={folder} | ||
isOpen={filteredList.length > 0 || allOpen} | ||
isOpen={linkList.length > 0} | ||
key={folder + i} | ||
> | ||
{filteredList.map(({ title, link }) => ( | ||
{linkList.map(({ title, link }, i) => ( | ||
<SidebarLink | ||
href={link} | ||
lang={$lang.get()} | ||
noTranslate={sidebarMode === "reference"} | ||
key={link} | ||
key={link + i} | ||
> | ||
{title} | ||
</SidebarLink> | ||
))} | ||
</SidebarFolder> | ||
); | ||
})} | ||
</> | ||
); | ||
}, | ||
); | ||
</> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters