You've already forked AstralRinth
forked from didirus/AstralRinth
Add search to GUI and minor changes to Theseus.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -106,3 +106,4 @@ fabric.properties
|
|||||||
|
|
||||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use std::collections::LinkedList;
|
|||||||
|
|
||||||
const METADATA_URL: &str = "https://meta.modrinth.com/gamedata";
|
const METADATA_URL: &str = "https://meta.modrinth.com/gamedata";
|
||||||
const METADATA_DB_FIELD: &[u8] = b"metadata";
|
const METADATA_DB_FIELD: &[u8] = b"metadata";
|
||||||
|
const RETRY_ATTEMPTS: i32 = 3;
|
||||||
|
|
||||||
// TODO: store as subtree in database
|
// TODO: store as subtree in database
|
||||||
#[derive(Encode, Decode, Debug)]
|
#[derive(Encode, Decode, Debug)]
|
||||||
@@ -49,6 +50,7 @@ impl Metadata {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attempt to fetch metadata and store in sled DB
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn init(db: &sled::Db) -> crate::Result<Self> {
|
pub async fn init(db: &sled::Db) -> crate::Result<Self> {
|
||||||
let mut metadata = None;
|
let mut metadata = None;
|
||||||
@@ -66,7 +68,7 @@ impl Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut fetch_futures = LinkedList::new();
|
let mut fetch_futures = LinkedList::new();
|
||||||
for _ in 0..3 {
|
for _ in 0..RETRY_ATTEMPTS {
|
||||||
fetch_futures.push_back(Self::fetch().boxed());
|
fetch_futures.push_back(Self::fetch().boxed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ pub const SUPPORTED_ICON_FORMATS: &[&'static str] = &[
|
|||||||
"mp4",
|
"mp4",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Represent a Minecraft instance.
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct Profile {
|
pub struct Profile {
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
|
|||||||
@@ -24,12 +24,26 @@
|
|||||||
import ProjectCard from '$components/ProjectCard.svelte';
|
import ProjectCard from '$components/ProjectCard.svelte';
|
||||||
|
|
||||||
export let projects;
|
export let projects;
|
||||||
|
export let searchQuery = "";
|
||||||
|
|
||||||
|
export const searchProjects = async (query) => {
|
||||||
|
const encodedQuery = encodeURI(query);
|
||||||
|
const response = await fetch(
|
||||||
|
`https://api.modrinth.com/v2/search?query=${encodedQuery}&limit=10&offset=0&index=relevance`
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.ok && (await response.json()).hits;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function search(event) {
|
||||||
|
projects = await searchProjects(searchQuery);
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<div class="controls__row">
|
<div class="controls__row">
|
||||||
<TextInput placeholder="Search..." icon={IconSearch} />
|
<TextInput placeholder="Search..." icon={IconSearch} bind:value={searchQuery}/>
|
||||||
<Button color="tertiary"><IconSortDescending />Sort by relevance</Button>
|
<Button on:click={search} color="tertiary"><IconSortDescending />Search</Button>
|
||||||
</div>
|
</div>
|
||||||
<div class="controls__row controls__row--overflow">
|
<div class="controls__row controls__row--overflow">
|
||||||
<Button color="secondary"><IconBox />Minecraft versions</Button>
|
<Button color="secondary"><IconBox />Minecraft versions</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user