Add search to GUI and minor changes to Theseus.
This commit is contained in:
parent
548139ff8a
commit
67742cb238
3
.gitignore
vendored
3
.gitignore
vendored
@ -105,4 +105,5 @@ fabric.properties
|
||||
**/*.rs.bk
|
||||
|
||||
# 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_DB_FIELD: &[u8] = b"metadata";
|
||||
const RETRY_ATTEMPTS: i32 = 3;
|
||||
|
||||
// TODO: store as subtree in database
|
||||
#[derive(Encode, Decode, Debug)]
|
||||
@ -49,6 +50,7 @@ impl Metadata {
|
||||
})
|
||||
}
|
||||
|
||||
// Attempt to fetch metadata and store in sled DB
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn init(db: &sled::Db) -> crate::Result<Self> {
|
||||
let mut metadata = None;
|
||||
@ -66,7 +68,7 @@ impl Metadata {
|
||||
}
|
||||
|
||||
let mut fetch_futures = LinkedList::new();
|
||||
for _ in 0..3 {
|
||||
for _ in 0..RETRY_ATTEMPTS {
|
||||
fetch_futures.push_back(Self::fetch().boxed());
|
||||
}
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ pub const SUPPORTED_ICON_FORMATS: &[&'static str] = &[
|
||||
"mp4",
|
||||
];
|
||||
|
||||
// Represent a Minecraft instance.
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Profile {
|
||||
#[serde(skip)]
|
||||
|
||||
@ -24,12 +24,26 @@
|
||||
import ProjectCard from '$components/ProjectCard.svelte';
|
||||
|
||||
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>
|
||||
|
||||
<div class="controls">
|
||||
<div class="controls__row">
|
||||
<TextInput placeholder="Search..." icon={IconSearch} />
|
||||
<Button color="tertiary"><IconSortDescending />Sort by relevance</Button>
|
||||
<TextInput placeholder="Search..." icon={IconSearch} bind:value={searchQuery}/>
|
||||
<Button on:click={search} color="tertiary"><IconSortDescending />Search</Button>
|
||||
</div>
|
||||
<div class="controls__row controls__row--overflow">
|
||||
<Button color="secondary"><IconBox />Minecraft versions</Button>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user