Working search

This commit is contained in:
Fishandchips321 2026-02-22 21:58:23 +00:00
parent 271cf1f407
commit 2a572e8bc4
15 changed files with 217 additions and 39 deletions

View file

@ -15,6 +15,8 @@ const ServerSearch = ({ searchTerm, server }: ServerSearchProps) => {
useEffect(() => {
search(searchTerm, server.id).then(results => {
setSearchResults(results);
}).catch(err => {
alert(err);
})
}, [searchTerm]);
@ -22,7 +24,7 @@ const ServerSearch = ({ searchTerm, server }: ServerSearchProps) => {
<Table striped bordered >
<thead>
<tr>
<th>{server.name}</th>
<th>{server.owner}'s server</th>
</tr>
</thead>
<tbody>

View file

@ -12,7 +12,7 @@ const ServerSearchResult = ({ searchResult, server }: ServerSearchResultProps) =
return (
<Link to={resultUrl} target="_blank" rel="noopener noreferrer">
<h3>{searchResult.name}</h3>
<h3>{searchResult.name} - {searchResult.productionYear}</h3>
</Link>
)
}

View file

@ -1,30 +1,21 @@
import axios from "axios";
import type { Server } from "./Servers";
import { apiUrl } from "./api";
export interface SearchResult {
name: string;
id: string;
serverId: string;
type: SearchResultType;
episodes: number;
productionYear: string;
}
export type SearchResultType = "movie" | "tv show" | "music";
export const search = async (searchTerm: string, serverId: string): Promise<Array<SearchResult>> => {
return [{
name: "Test Result",
episodes: 0,
id: "awawa",
serverId: serverId,
type: "movie"
},
{
name: "Test result 2",
episodes: 0,
id: "awawa 2",
serverId: serverId,
type: "movie"
}];
const response = await axios.get<Array<SearchResult>>(`${apiUrl}/search?searchTerm=${searchTerm}&serverId=${serverId}`);
return response.data;
}
export const getUrlForSearchResult = (result: SearchResult, server: Server): string => {