Skip to content

Commit eb81d24

Browse files
committed
feat: packageitem loader icons (WIP)
1 parent 52a8382 commit eb81d24

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

apps/onelauncher/frontend/src/components/content/PackageItem.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import type { Provider, SearchResult } from '@/bindings.gen';
2-
import { abbreviateNumber } from '@/utils';
2+
import { abbreviateNumber, LOADERS } from '@/utils';
33
import { Show } from '@onelauncher/common/components';
44
import { useNavigate } from '@tanstack/react-router';
55
import { Download01Icon } from '@untitled-theme/icons-react';
6+
import LoaderIcon from '../launcher/LoaderIcon';
7+
8+
function includes<T, TArray extends T>(list: { includes: (arg0: TArray) => boolean }, element: T): element is TArray {
9+
return list.includes(element as unknown as TArray);
10+
}
611

712
export function PackageGrid({ items, provider }: { items: Array<SearchResult>; provider: Provider }) {
813
return (
@@ -44,6 +49,9 @@ export function PackageItem({ provider, ...item }: SearchResult & { provider: Pr
4449
src={item.icon_url}
4550
/>
4651
</Show>
52+
<div className="flex flex-col rounded-full bg-component-bg/70 border-component-border/70 border gap-2 p-2 absolute top-0 right-0 m-2">
53+
{item.categories.filter(cat => includes(LOADERS, cat)).map(loader => <LoaderIcon className="w-5" key={loader} loader={loader} />)}
54+
</div>
4755
</div>
4856
<div className="flex flex-1 flex-col gap-2 p-3">
4957
<div className="flex flex-col gap-2">
Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import type { Paginated, SearchResult } from '@/bindings.gen';
2+
import type { PaginationOptions } from '@/hooks/usePagination';
13
import { PackageGrid } from '@/components/content/PackageItem';
24
import { useBrowserContext, useBrowserSearch } from '@/hooks/useBrowser';
5+
import usePagination from '@/hooks/usePagination';
36
import { Show } from '@onelauncher/common/components';
47
import { createFileRoute } from '@tanstack/react-router';
58
import { useEffect, useMemo, useState } from 'react';
69
import { BrowserLayout } from './route';
7-
import type { Paginated, SearchResult } from '@/bindings.gen';
8-
import type { PaginationOptions } from '@/hooks/usePagination';
9-
import usePagination from '@/hooks/usePagination';
1010

1111
export const Route = createFileRoute('/app/browser/search')({
1212
component: RouteComponent,
@@ -33,40 +33,39 @@ function Search() {
3333
return (
3434
<>
3535
{
36-
search.data
37-
? <Results results={search.data}/>
38-
: <h1>Loading</h1>
36+
search.data
37+
? <Results results={search.data} />
38+
: <h1>Loading</h1>
3939
}
4040
</>
4141
);
4242
}
4343

44-
function Results({results}:{results:Paginated<SearchResult>}){
44+
function Results({ results }: { results: Paginated<SearchResult> }) {
4545
const context = useBrowserContext();
46-
const [oldTotal, setOldTotal] = useState(results.total)
46+
const [oldTotal, setOldTotal] = useState(results.total);
4747
const pagination = usePagination({
4848
itemsCount: results.total as unknown as number,
49-
itemsPerPage: context.query.limit as unknown as number
50-
})
51-
useEffect(()=>{
52-
context.setQuery({...context.query, offset: pagination.offset as unknown as bigint})
53-
},[pagination.page])
54-
useEffect(()=>{
55-
if(oldTotal === results.total) return;
56-
pagination.reset()
57-
console.log("pagination reset", results.total)
58-
setOldTotal(results.total)
59-
},[results.total])
49+
itemsPerPage: context.query.limit as unknown as number,
50+
});
51+
useEffect(() => {
52+
context.setQuery({ ...context.query, offset: pagination.offset as unknown as bigint });
53+
}, [pagination.page]);
54+
useEffect(() => {
55+
if (oldTotal === results.total)
56+
return;
57+
pagination.reset();
58+
setOldTotal(results.total);
59+
}, [results.total]);
6060
return (
6161
<div>
62-
<div className='w-full flex justify-end my-2'>
63-
<pagination.Navigation/>
62+
<div className="w-full flex justify-end my-2">
63+
<pagination.Navigation />
6464
</div>
65-
{results.items.length == 0
66-
? <h2 className='text-center text-lg font-light italic opacity-60'>No results</h2>
67-
: <PackageGrid items={results.items} provider={context.provider}/>
68-
}
65+
{results.items.length === 0
66+
? <h4 className="text-center text-lg font-light opacity-60">No results</h4>
67+
: <PackageGrid items={results.items} provider={context.provider} />}
6968

7069
</div>
71-
)
70+
);
7271
}

0 commit comments

Comments
 (0)