Add search to GUI and minor changes to Theseus.

This commit is contained in:
Matthew Reid
2023-01-02 00:41:09 -07:00
parent 548139ff8a
commit 67742cb238
4 changed files with 22 additions and 4 deletions

3
.gitignore vendored
View File

@@ -105,4 +105,5 @@ fabric.properties
**/*.rs.bk **/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information # MSVC Windows builds of rustc generate these, which store debugging information
*.pdb *.pdb

View File

@@ -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());
} }

View File

@@ -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)]

View File

@@ -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>