Skip to content

Commit 2d02f64

Browse files
committed
feat: featured gallery
1 parent 6634e06 commit 2d02f64

File tree

6 files changed

+66
-24
lines changed

6 files changed

+66
-24
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function includes<T, TArray extends T>(list: { includes: (arg0: TArray) => boole
1313

1414
export function PackageGrid({ items, provider }: { items: Array<SearchResult>; provider: Provider }) {
1515
return (
16-
<div className="grid grid-cols-2 xl:grid-cols-3 gap-2">
16+
<div className="grid grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-2">
1717
{items.map(item => (
1818
<PackageItem key={item.project_id} {...item} provider={provider} />
1919
))}
@@ -45,11 +45,11 @@ export function PackageItem({ provider, ...item }: SearchResult & { provider: Pr
4545
<img alt={`Icon for ${item.title}`} className="absolute z-0 max-w-none w-7/6 opacity-50 blur-xl" src={item.icon_url} />
4646
<img
4747
alt={`Icon for ${item.title}`}
48-
className="relative z-1 aspect-ratio-square rounded-md image-render-auto w-2/5"
48+
className="relative z-1 aspect-ratio-square rounded-lg image-render-auto h-5/6"
4949
src={item.icon_url}
5050
/>
5151
</Show>
52-
<Tooltip text={loaders.map(upperFirst).join(', ')}>
52+
<Tooltip className="bg-component-bg-disabled" text={loaders.map(upperFirst).join(', ')}>
5353
<Focusable>
5454
<div className="flex flex-col rounded-full bg-component-bg/70 border-component-border/70 border p-1 absolute top-0 right-0 m-2">
5555
{loaders.toSpliced(loaders.length > 3 ? 2 : 3).map(loader => <LoaderIcon className="w-5 m-1" key={loader} loader={loader} />)}

apps/onelauncher/frontend/src/routes/app/browser/index.tsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@ function RouteComponent() {
2727

2828
function Featured() {
2929
// const context = useBrowserContext();
30-
const [provider, slug] = useMemo<[Provider, string]>(() => ['Modrinth', 'sodium'], []);
30+
const [provider, slug] = useMemo<[Provider, string]>(() => ['Modrinth', 'iris'], []);
3131
const featuredPackage = usePackageData(provider, slug, {}, 'getFeatured');
3232
const navigate = useNavigate();
33-
33+
const featuredImageIndex = useMemo(() => featuredPackage.data?.gallery.findIndex(image => image.featured), [featuredPackage.data]);
34+
const [selectedImage, setSelectedImage] = useState(featuredImageIndex ?? 0);
3435
return (
3536
<Show when={featuredPackage.isSuccess}>
3637
<div className="flex flex-col gap-y-1">
37-
<h5 className="ml-2">Featured</h5>
38-
<div className="w-full flex flex-row overflow-hidden rounded-lg bg-page-elevated">
38+
<h5 className="ml-2 uppercase opacity-60">Featured</h5>
39+
<div className="w-full flex flex-col lg:flex-row overflow-hidden rounded-lg bg-page-elevated">
3940
<div className="w-full p-1">
40-
<img alt="thumbnail" className="aspect-ratio-video h-full rounded-md object-cover object-center" src={featuredPackage.data?.icon_url ?? ''} />
41+
<img alt="thumbnail" className="aspect-video h-full w-full rounded-md object-cover object-center" src={featuredPackage.data?.gallery[selectedImage].url} />
4142
</div>
42-
<div className="max-w-84 min-w-52 flex flex-col gap-y-1 p-4">
43+
<div className="max-w-64 min-w-52 flex flex-col gap-y-1 p-4">
4344
<h2>{featuredPackage.data?.name}</h2>
4445

4546
<Show when={false}>
@@ -49,7 +50,20 @@ function Featured() {
4950
</div>
5051
</Show>
5152

52-
<p className="mt-1 flex-1 leading-normal">{featuredPackage.data?.short_desc}</p>
53+
<p className="my-1 flex-1 leading-normal">{featuredPackage.data?.short_desc}</p>
54+
55+
<div className="grid grid-cols-3 gap-2 h-full">
56+
{featuredPackage.data?.gallery.map(
57+
(image, index) => (
58+
<img
59+
className="aspect-video object-center object-cover rounded-md"
60+
key={image.url}
61+
onClick={() => setSelectedImage(index)}
62+
src={image.url}
63+
/>
64+
),
65+
)}
66+
</div>
5367

5468
<div className="flex flex-row justify-end">
5569
<Button color="ghost" onClick={() => navigate({ to: '/app/browser/package/$provider/$slug', params: { provider, slug } })}>
@@ -77,15 +91,15 @@ function Lists() {
7791
function List({ provider }: { provider: Provider }) {
7892
const search = useBrowserSearch(provider, {
7993
filters: null,
80-
limit: 18 as unknown as bigint,
94+
limit: 24 as unknown as bigint,
8195
offset: null,
8296
query: null,
8397
sort: null,
8498
});
8599
const [expanded, setExpanded] = useState(false);
86100
return (
87101
<div>
88-
<h5 className="uppercase p-3 opacity-60">{provider}</h5>
102+
<h5 className="uppercase m-2 opacity-60">{provider}</h5>
89103
<div className={`relative overflow-hidden ${expanded ? '' : 'h-128'}`}>
90104
{search.isSuccess
91105
? <PackageGrid items={search.data.items} provider={provider} />

apps/onelauncher/frontend/src/routes/app/browser/route.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ function RouteComponent() {
3030
export function BrowserLayout(props: any) {
3131
return (
3232
<div className="relative h-full flex flex-1 flex-col items-center gap-2">
33-
<div className="h-full w-full max-w-screen-xl flex flex-1 flex-col items-center gap-y-2">
33+
<div className="h-full w-full max-w-screen-2xl flex flex-1 flex-col items-center gap-y-2">
3434
<div className="grid grid-cols-[220px_auto_220px] w-full gap-x-6">
3535
<div />
3636
<BrowserToolbar />
3737
<div />
3838
</div>
3939

40-
<div className="grid grid-cols-[220px_auto_220px] w-full max-w-screen-xl gap-x-6 pb-8">
40+
<div className="grid grid-cols-[220px_auto_220px] w-full gap-x-6 pb-8">
4141
<BrowserCategories />
4242

4343
<div className="h-full flex flex-col gap-y-4">

packages/core/src/api/packages/data.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub struct ManagedPackage {
9797
pub links: PackageLinks,
9898
pub status: PackageStatus,
9999
pub downloads: usize,
100+
pub gallery: Vec<PackageGallery>
100101
}
101102

102103
#[onelauncher_macro::specta]
@@ -205,6 +206,16 @@ pub struct PackageDonationUrl {
205206
pub url: String,
206207
}
207208

209+
#[onelauncher_macro::specta]
210+
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
211+
pub struct PackageGallery {
212+
pub url: String,
213+
pub thumbnail_url: String,
214+
pub title: Option<String>,
215+
pub description: Option<String>,
216+
pub featured: Option<bool>
217+
}
218+
208219
/// https://api.modrinth.com/v2/tag/donation_platform
209220
#[onelauncher_macro::specta]
210221
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]

packages/core/src/api/packages/provider/modrinth.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::ProviderExt;
22
use crate::api::packages::data::{
3-
ManagedPackage, ManagedUser, ManagedVersion, ManagedVersionDependency, ManagedVersionFile, PackageAuthor, PackageDependencyType, PackageDonationUrl, PackageLicense, PackageLinks, PackageReleaseType, PackageSide, PackageStatus, SearchQuery, SearchResult, DEFAULT_LIMIT
3+
ManagedPackage, ManagedUser, ManagedVersion, ManagedVersionDependency, ManagedVersionFile, PackageAuthor, PackageDependencyType, PackageDonationUrl, PackageGallery, PackageLicense, PackageLinks, PackageReleaseType, PackageSide, PackageStatus, SearchQuery, SearchResult, DEFAULT_LIMIT
44
};
55
use crate::error::LauncherResult;
66
use crate::utils::http;
@@ -363,7 +363,7 @@ struct ModrinthPackage {
363363
#[serde(default)]
364364
pub license: Option<PackageLicense>,
365365
// #[serde(default)]
366-
// pub gallery: Vec<Gallery>,
366+
pub gallery: Vec<ModrinthGallery>,
367367
#[serde(default)]
368368
pub status: PackageStatus,
369369
}
@@ -405,6 +405,7 @@ impl From<ModrinthPackage> for ManagedPackage {
405405
},
406406
status: value.status,
407407
downloads: value.downloads,
408+
gallery: value.gallery.into_iter().map(Into::into).collect()
408409
}
409410
}
410411
}
@@ -532,6 +533,29 @@ impl From<ModrinthUser> for ManagedUser {
532533
}
533534
}
534535

536+
#[derive(Deserialize)]
537+
pub struct ModrinthGallery {
538+
#[serde(rename = "raw_url")]
539+
pub url: String,
540+
#[serde(rename = "url")]
541+
pub thumbnail_url: String,
542+
pub title: Option<String>,
543+
pub description: Option<String>,
544+
pub featured: Option<bool>
545+
}
546+
547+
impl From<ModrinthGallery> for PackageGallery {
548+
fn from(value: ModrinthGallery) -> Self {
549+
Self {
550+
url: value.url,
551+
thumbnail_url: value.thumbnail_url,
552+
title: value.title,
553+
description: value.description,
554+
featured: value.featured
555+
}
556+
}
557+
}
558+
535559
#[allow(dead_code)]
536560
enum FacetOperation {
537561
NotEq,

packages/web_common/src/theme.css

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,6 @@ body {
110110
display: none;
111111
}
112112

113-
h1 { @apply text-[2rem] font-semibold; line-height: 1.5 !important; }
114-
h2 { @apply text-[1.5rem] font-semibold; line-height: 1.25 !important; }
115-
h3 { @apply text-[1.25rem] font-medium; }
116-
h4 { @apply text-[1rem] font-medium; }
117-
h5 { @apply text-[0.875rem] text-fg-secondary font-bold uppercase; }
118-
h6 { @apply text-[0.75rem] text-fg-secondary font-medium uppercase; }
119-
120113
code {
121114
@apply rounded-md p-2 text-left;
122-
}
115+
}

0 commit comments

Comments
 (0)