Skip to content

Commit

Permalink
feat: SkyClient Part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
LynithDev committed Dec 7, 2024
1 parent 2554d23 commit f49dc71
Show file tree
Hide file tree
Showing 15 changed files with 410 additions and 85 deletions.
Binary file added apps/frontend/src/assets/logos/skyclient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions apps/frontend/src/ui/components/content/ProviderIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ManagedPackage, Providers } from '@onelauncher/client/bindings';
import CurseforgeIcon from '~assets/logos/curseforge.svg?component-solid';
import ModrinthImage from '~assets/logos/modrinth.svg?component-solid';
import SkyClientImage from '~assets/logos/skyclient.png';
import { type Component, type JSX, Match, Show, splitProps, Switch } from 'solid-js';

export function getProviderLogoElement(provider: ManagedPackage | Providers): string | Component {
Expand All @@ -10,6 +11,7 @@ export function getProviderLogoElement(provider: ManagedPackage | Providers): st
const mapping: Record<Lowercase<Providers>, string | Component> = {
modrinth: ModrinthImage,
curseforge: CurseforgeIcon,
skyclient: SkyClientImage,
};

return mapping[providerName];
Expand Down
18 changes: 10 additions & 8 deletions apps/frontend/src/ui/components/content/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,18 @@ function PackageItem(props: SearchResult & { provider: Providers; row?: boolean
<p class="max-h-22 flex-1 overflow-hidden text-sm text-fg-secondary line-height-snug">{props.description}</p>

<div class="flex flex-row gap-4 text-xs">
<div class="flex flex-row items-center gap-2">
<Download01Icon class="h-4 w-4" />
{abbreviateNumber(props.downloads)}
</div>

<Show when={props.follows > 0}>
<Show when={props.provider !== 'SkyClient'}>
<div class="flex flex-row items-center gap-2">
<HeartIcon class="h-4 w-4" />
{abbreviateNumber(props.follows)}
<Download01Icon class="h-4 w-4" />
{abbreviateNumber(props.downloads)}
</div>

<Show when={props.follows > 0}>
<div class="flex flex-row items-center gap-2">
<HeartIcon class="h-4 w-4" />
{abbreviateNumber(props.follows)}
</div>
</Show>
</Show>
</div>
</div>
Expand Down
62 changes: 34 additions & 28 deletions apps/frontend/src/ui/pages/browser/BrowserPackage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export default BrowserPackage;

function BrowserSidebar(props: { package: ManagedPackage }) {
const [authors] = useCommand(() => props.package, () => bridge.commands.getProviderAuthors(props.package.provider, props.package.author));
const createdAt = () => new Date(props.package.created);
const updatedAt = () => new Date(props.package.updated);
const createdAt = createMemo(() => props.package.created ? new Date(props.package.created) : null);
const updatedAt = createMemo(() => props.package.updated ? new Date(props.package.updated) : null);
const promptOpen = usePromptOpener();

return (
Expand Down Expand Up @@ -166,16 +166,18 @@ function BrowserSidebar(props: { package: ManagedPackage }) {
<p class="max-h-22 flex-1 overflow-hidden text-sm text-fg-secondary line-height-snug">{props.package.description}</p>

<div class="flex flex-row gap-4 text-xs">
<div class="flex flex-row items-center gap-2">
<Download01Icon class="h-4 w-4" />
{abbreviateNumber(props.package.downloads)}
</div>

<Show when={props.package.followers > 0}>
<Show when={props.package.provider !== 'SkyClient'}>
<div class="flex flex-row items-center gap-2">
<HeartIcon class="h-4 w-4" />
{abbreviateNumber(props.package.followers)}
<Download01Icon class="h-4 w-4" />
{abbreviateNumber(props.package.downloads)}
</div>

<Show when={props.package.followers > 0}>
<div class="flex flex-row items-center gap-2">
<HeartIcon class="h-4 w-4" />
{abbreviateNumber(props.package.followers)}
</div>
</Show>
</Show>
</div>
</div>
Expand Down Expand Up @@ -235,25 +237,29 @@ function BrowserSidebar(props: { package: ManagedPackage }) {
</div>
</Show>

<Tooltip text={createdAt().toLocaleString()}>
<div class="flex flex-row items-center gap-x-1">
<CalendarIcon class="h-3 min-w-3 w-3" />
Created
<span class="text-fg-primary font-medium">
{formatAsRelative(createdAt().getTime(), 'en', 'long')}
</span>
</div>
</Tooltip>
<Show when={createdAt() !== null}>
<Tooltip text={createdAt()!.toLocaleString()}>
<div class="flex flex-row items-center gap-x-1">
<CalendarIcon class="h-3 min-w-3 w-3" />
Created
<span class="text-fg-primary font-medium">
{formatAsRelative(createdAt()!.getTime(), 'en', 'long')}
</span>
</div>
</Tooltip>
</Show>

<Tooltip text={updatedAt().toLocaleString()}>
<div class="flex flex-row items-center gap-x-1">
<ClockRewindIcon class="h-3 min-w-3 w-3" />
Last Updated
<span class="text-fg-primary font-medium">
{formatAsRelative(updatedAt().getTime(), 'en', 'long')}
</span>
</div>
</Tooltip>
<Show when={updatedAt() !== null}>
<Tooltip text={updatedAt()!.toLocaleString()}>
<div class="flex flex-row items-center gap-x-1">
<ClockRewindIcon class="h-3 min-w-3 w-3" />
Last Updated
<span class="text-fg-primary font-medium">
{formatAsRelative(updatedAt()!.getTime(), 'en', 'long')}
</span>
</div>
</Tooltip>
</Show>
</div>

</div>
Expand Down
34 changes: 20 additions & 14 deletions apps/frontend/src/ui/pages/browser/BrowserRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ProviderIcon from '~ui/components/content/ProviderIcon';
import useBrowser from '~ui/hooks/useBrowser';
import { PROVIDERS } from '~utils';
import { browserCategories } from '~utils/browser';
import { For, type JSX, type ParentProps } from 'solid-js';
import { createMemo, For, type JSX, type ParentProps, Show } from 'solid-js';
import BrowserMain from './BrowserMain';
import BrowserPackage from './BrowserPackage';
import BrowserSearch from './BrowserSearch';
Expand Down Expand Up @@ -87,23 +87,29 @@ function BrowserCategories() {
browser.search();
};

const categories = createMemo(() => {
return browserCategories.byPackageType(browser.packageType(), browser.searchQuery().provider);
});

return (
<div class="top-0 grid grid-cols-[1fr_auto] h-fit min-w-50 gap-y-6">
<div />
<div class="flex flex-col gap-y-6">
<div class="flex flex-col gap-y-2">
<h6 class="my-1">Categories</h6>
<For each={browserCategories.byPackageType(browser.packageType(), browser.searchQuery().provider)}>
{category => (
<p
class={`text-md capitalize text-fg-primary hover:text-fg-primary-hover line-height-snug ${isEnabled(category.id) ? 'text-opacity-100! hover:text-opacity-90!' : 'text-opacity-60! hover:text-opacity-70!'}`}
onClick={() => toggleCategory(category.id)}
>
{category.display}
</p>
)}
</For>
</div>
<Show when={categories().length > 0}>
<div class="flex flex-col gap-y-2">
<h6 class="my-1">Categories</h6>
<For each={categories()}>
{category => (
<p
class={`text-md capitalize text-fg-primary hover:text-fg-primary-hover line-height-snug ${isEnabled(category.id) ? 'text-opacity-100! hover:text-opacity-90!' : 'text-opacity-60! hover:text-opacity-70!'}`}
onClick={() => toggleCategory(category.id)}
>
{category.display}
</p>
)}
</For>
</div>
</Show>
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/utils/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ const modMapping: Record<Providers, CategoryItem[]> = {
{ display: 'Utility', id: 'utility' },
{ display: 'World Generation', id: 'worldgen' },
],
SkyClient: [],
};
3 changes: 2 additions & 1 deletion apps/frontend/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,14 @@ export function getPackageUrl(pkg: ManagedPackage): string {

return `https://www.curseforge.com/minecraft/${packageTypeMapping[pkg.package_type]}/${pkg.main}`;
},
SkyClient: () => 'TODO',
};

return mapping[pkg.provider]();
}

export const LOADERS: Loader[] = ['vanilla', 'fabric', 'forge', 'neoforge', 'quilt'] as const;
export const PROVIDERS: Providers[] = ['Modrinth', 'Curseforge'] as const;
export const PROVIDERS: Providers[] = ['Modrinth', 'Curseforge', 'SkyClient'] as const;
export const PACKAGE_TYPES: PackageType[] = ['mod', 'resourcepack', 'datapack', 'shaderpack'] as const;
export const LAUNCHER_IMPORT_TYPES: ImportType[] = [
'PrismLauncher',
Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/bindings.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions packages/core/src/api/package/content/curseforge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ impl From<CurseforgePackage> for ManagedPackage {
game_versions: vec![],
loaders: vec![],
icon_url: package.logo.and_then(|l| Some(l.url)),
created: package.date_created,
updated: package.date_modified,
created: Some(package.date_created),
updated: Some(package.date_modified),
client: crate::store::PackageSide::Unknown,
server: crate::store::PackageSide::Unknown,
downloads: package.download_count,
Expand Down Expand Up @@ -193,11 +193,10 @@ impl Into<SearchResult> for CurseforgePackage {
downloads: self.download_count,
icon_url: self.logo.map_or(String::new(), |l| l.url),
categories: vec![], // TODO
display_categories: vec![],
versions: vec![],
follows: self.thumbs_up_count,
date_created: self.date_created,
date_modified: self.date_modified,
date_created: Some(self.date_created),
date_modified: Some(self.date_modified),
}
}
}
Expand Down
49 changes: 32 additions & 17 deletions packages/core/src/api/package/content/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ use crate::{Result, State};

mod curseforge;
mod modrinth;
mod skyclient;

/// Providers for content packages
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
pub enum Providers {
Modrinth,
Curseforge,
SkyClient,
}

impl std::fmt::Display for Providers {
Expand All @@ -39,6 +41,7 @@ impl Providers {
match self {
Self::Modrinth => "Modrinth",
Self::Curseforge => "Curseforge",
Self::SkyClient => "SkyClient",
}
}

Expand All @@ -48,11 +51,12 @@ impl Providers {
match self {
Self::Modrinth => "https://modrinth.com",
Self::Curseforge => "https://curseforge.com",
Self::SkyClient => "https://skyclient.co",
}
}

pub const fn get_providers() -> &'static [Providers] {
&[Self::Modrinth, Self::Curseforge]
&[Self::Modrinth, Self::Curseforge, Self::SkyClient]
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -98,35 +102,37 @@ impl Providers {
)
.await
}
Self::SkyClient => {
skyclient::search(
query,
limit,
offset,
game_versions,
loaders
).await
},
}
}

pub async fn get(&self, slug_or_id: &str) -> Result<ManagedPackage> {
Ok(match self {
Self::Modrinth => modrinth::get(slug_or_id).await?.into(),
Self::Curseforge => curseforge::get(
slug_or_id
.parse::<u32>()
.map_err(|err| anyhow::anyhow!(err))?,
)
.await?
.into(),
Self::Curseforge => curseforge::get(slug_or_id.parse::<u32>().map_err(|err| anyhow::anyhow!(err))?).await?.into(),
Self::SkyClient => skyclient::get(slug_or_id).await?.into(),
})
}

pub async fn get_multiple(&self, slug_or_ids: &[String]) -> Result<Vec<ManagedPackage>> {
Ok(match self {
Self::Modrinth => {
if slug_or_ids.len() <= 0 {
return Ok(vec![]);
}
if slug_or_ids.len() <= 0 {
return Ok(vec![]);
}

modrinth::get_multiple(slug_or_ids)
Ok(match self {
Self::Modrinth => modrinth::get_multiple(slug_or_ids)
.await?
.into_iter()
.map(Into::into)
.collect()
},
.collect(),
Self::Curseforge => {
let parsed_ids = slug_or_ids
.iter()
Expand All @@ -145,6 +151,11 @@ impl Providers {
.map(Into::into)
.collect()
},
Self::SkyClient => skyclient::get_multiple(slug_or_ids)
.await?
.into_iter()
.map(Into::into)
.collect(),
})
}

Expand All @@ -166,6 +177,8 @@ impl Providers {
let data = curseforge::get_all_versions(project_id, game_versions, loaders, page, page_size).await?;
(data.0.into_iter().map(Into::into).collect(), data.1)
}

Self::SkyClient => todo!(),
})
}

Expand All @@ -181,6 +194,7 @@ impl Providers {
.into_iter()
.map(Into::into)
.collect(),
Self::SkyClient => todo!(),
})
}

Expand Down Expand Up @@ -215,7 +229,8 @@ impl Providers {
.await?
.into_iter()
.map(|(hash, version)| (hash, version.into()))
.collect()
.collect(),
Self::SkyClient => todo!(),
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/api/package/content/modrinth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ impl From<ModrinthPackage> for ManagedPackage {
game_versions: value.game_versions,
loaders: value.loaders,
icon_url: value.icon_url,
created: value.published,
updated: value.updated,
created: Some(value.published),
updated: Some(value.updated),
client: value.client_side,
server: value.server_side,
downloads: value.downloads as u64,
Expand Down
Loading

0 comments on commit f49dc71

Please sign in to comment.