Skip to content

Commit cced6ad

Browse files
committed
Fix query page and switch stop worker search
1 parent a1326dc commit cced6ad

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

@client/src/components/Banner.tsx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
export const Banner = () => {
22
return (
3-
<div class="sm:px-2 py-6 space-y-6 max-w-3xl">
4-
<div class="space-y-2 sm:columns-2">
5-
<p>Find free to attend lectures from leading universities and institutions around London</p>
6-
<p>
7-
You can find the code on our{' '}
8-
<a class="btn" rel="noopener noreferrer" target="_blank" href={`https://github.com/Pingid/lectures.london`}>
9-
repository
3+
<div class="sm:px-2 pt-6 space-y-6">
4+
<div class="space-y-2 sm:columns-1">
5+
<p class="max-w-sm">Find free to attend lectures from leading universities and institutions around London</p>
6+
7+
<div class="w-full flex flex-wrap gap-3 pb-2">
8+
<a class="btn" rel="noopener noreferrer" target="_blank" href="https://twitter.com/lectures_london">
9+
twitter
1010
</a>
11-
, where we welcome contributions and feedback. This is a community lead project and if you spot any problems
12-
or mistakes on the site please file an{' '}
11+
<a class="btn" rel="noopener noreferrer" target="_blank" href="/calender.ics">
12+
calender
13+
</a>
14+
<label for="more" class="btn w-min cursor-pointer sm:hidden">
15+
issues
16+
</label>
17+
</div>
18+
<input id="more" type="checkbox" class="peer hidden" />
19+
<p class="invisible h-0 sm:h-auto sm:visible peer-checked:h-auto peer-checked:visible text-sm">
20+
If you spot any problems or mistakes on the site please file an{' '}
1321
<a
14-
class="btn"
22+
class="btn text-sm"
1523
rel="noopener noreferrer"
1624
target="_blank"
1725
href={`https://github.com/Pingid/lectures.london/issues`}
1826
>
1927
issue
2028
</a>
21-
. For those more technically minded a pull request with a fix is always appreciated.
29+
. Or get in contact through{' '}
30+
<a class="btn text-sm" rel="noopener noreferrer" target="_blank" href="https://twitter.com/lectures_london">
31+
twitter
32+
</a>
2233
</p>
2334
</div>
24-
<div class="w-full flex flex-wrap gap-3">
25-
<a class="btn" rel="noopener noreferrer" target="_blank" href="https://twitter.com/lectures_london">
26-
twitter
27-
</a>
28-
<a class="btn" rel="noopener noreferrer" target="_blank" href="/calender.ics">
29-
calender
30-
</a>
31-
{/* <a class="btn" rel="noopener noreferrer" target="_blank" href="/rss.xml">
32-
rss
33-
</a> */}
34-
</div>
3535
</div>
3636
)
3737
}

@client/src/data/useFuse.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FromWorker, ToWorker, cleanSearchResults } from '../worker/search'
55
export type { SearchResult } from '../worker/search'
66

77
export const useFuse = (onMessage: (ev: FromWorker) => any) => {
8-
if (typeof Worker !== 'undefined') {
8+
if (false && typeof Worker !== 'undefined') {
99
let worker: Worker | null = null
1010
const send = (data: ToWorker) => Promise.resolve(worker?.postMessage(data))
1111
createEffect(() => {
@@ -17,9 +17,11 @@ export const useFuse = (onMessage: (ev: FromWorker) => any) => {
1717
}
1818

1919
let fuse: Fuse<Lecture>
20+
let Fuse: any
21+
2022
const send = async (data: ToWorker) => {
23+
if (!Fuse) Fuse = (await import('fuse.js').then((x) => x.default)) as any
2124
if (data.type === 'ADD_LECTURES') {
22-
const Fuse = await import('fuse.js').then((x) => x.default)
2325
const index = Fuse.createIndex(data.payload.options.keys, data.payload.lectures)
2426
fuse = new Fuse(data.payload.lectures, data.payload.options, index)
2527
}

@client/src/data/userSearch.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ const sanitize = <T>(x: T): T => JSON.parse(JSON.stringify(x))
88

99
export const useSearch = () => {
1010
const [results, setresults] = createSignal<SearchResult[]>([])
11-
const [query] = router.query('query')
11+
const [query, setquery] = router.query('query')
1212
const [data] = useStore()
1313

1414
const active = () => query().length > 1
1515

1616
const fuse = useFuse((e) => (e.type === 'RESULTS' ? setresults(e.payload) : null))
17-
createEffect(() => fuse.send(sanitize({ type: 'ADD_LECTURES', payload: { lectures: data.lectures, options } })))
18-
createEffect(() => active() && fuse.send({ type: 'SEARCH', payload: query() }))
19-
17+
createEffect(() => {
18+
fuse.send(sanitize({ type: 'ADD_LECTURES', payload: { lectures: data.lectures, options } }))
19+
if (active()) fuse.send({ type: 'SEARCH', payload: query() })
20+
})
21+
createEffect(() => {
22+
const query = new URLSearchParams(window.location.search).get('query')
23+
if (query) setquery(query)
24+
})
2025
return { results, active }
2126
}
2227

0 commit comments

Comments
 (0)