diff --git a/resources/scripts/components/server/modrinth/ModrinthContainer.tsx b/resources/scripts/components/server/modrinth/ModrinthContainer.tsx index e0a639968..ea1d82634 100644 --- a/resources/scripts/components/server/modrinth/ModrinthContainer.tsx +++ b/resources/scripts/components/server/modrinth/ModrinthContainer.tsx @@ -1,15 +1,19 @@ +import debounce from 'debounce'; import { useEffect, useState } from 'react'; import { toast } from 'sonner'; +import Can from '@/components/elements/Can'; import ContentBox from '@/components/elements/ContentBox'; import { ModBox } from '@/components/elements/ModBox'; import PageContentBlock from '@/components/elements/PageContentBlock'; +import { ServerContext } from '@/state/server'; + import ProjectSelector from './DisplayMods'; import EnvironmentSelector from './EnvironmentSelector'; import GameVersionSelector from './GameVersionSelector'; import LoaderSelector from './LoaderSelector'; -import { fetchNewProjects } from './config'; +import { settings } from './config'; export default () => { const [appVersion, setAppVersion] = useState(null); @@ -18,6 +22,18 @@ export default () => { versions: [], environments: [], }); + const [searchQuery, setSearchQuery] = useState(''); + + const [searchTerm, setSearchTerm] = useState(''); + + const updateSearchTerms = () => { + // settings.searchTerms = setSearchTerm; + // settings.searchTerms = setSearchTerm; + settings.searchTerms = searchTerm; + console.log(settings.searchTerms); + return debounce(setSearchTerm, 50); + }; + const debouncedSearchTerm = updateSearchTerms(); const environment = ['Client', 'Server']; const url = 'https://api.modrinth.com/v2'; @@ -37,9 +53,14 @@ export default () => { getAppVersion(); }, []); - // Ensure components only render once appVersion is available + // console.log(settings.searchTerms); + + useEffect(() => { + setSearchTerm(''); + }, [location]); + if (!appVersion) { - return
Loading...
; // Wait until appVersion is fetched + return
Loading...
; } // Function to update settings @@ -47,39 +68,42 @@ export default () => { setSettings((prevSettings) => ({ ...prevSettings, [key]: value })); }; + const handleSearch = () => { + toast.success(`Searching for: ${searchQuery}`); + console.log(searchQuery); + }; + return ( -
- - Search Bar - -
- - - updateSettings('loaders', selectedLoaders)} - /> - - - - - - updateSettings('versions', selectedVersions)} - /> - - - - + + + + updateSettings('loaders', selectedLoaders)} + /> + + + + + + + updateSettings('versions', selectedVersions)} + /> + + + + {/* TODO: Add this field that lets you choose between client and server side mods */} + {/* { } /> - + */} + debouncedSearchTerm(event.target.value)} + // onChange={(event) => console.log(event.target.value)} + /> +
diff --git a/resources/scripts/components/server/modrinth/config.ts b/resources/scripts/components/server/modrinth/config.ts index 23e282a02..fd8a36fb3 100644 --- a/resources/scripts/components/server/modrinth/config.ts +++ b/resources/scripts/components/server/modrinth/config.ts @@ -1,3 +1,10 @@ +interface Settings { + loaders: any[]; + versions: any[]; + environments: any[]; + searchTerms: string; +} + export const gameLoaders = []; export const gamerVersions = []; @@ -9,10 +16,11 @@ export const apiEndpoints = { versions: `/tag/game_version`, }; -export const settings = { +export const settings: Settings = { loaders: [], versions: [], environments: [], + searchTerms: '', }; export const fetchHeaders = (appVersion) => ({