renamed SearchResponse to ServiceItem in frontend
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
import { apiFetch } from "./client";
|
import { apiFetch } from "./client";
|
||||||
import type { PagedSearchResponse, SearchRequest, SearchResponse } from "../types/search";
|
import type {
|
||||||
|
PagedSearchResponse,
|
||||||
|
SearchRequest,
|
||||||
|
ServiceItem,
|
||||||
|
} from "../types/search";
|
||||||
|
|
||||||
export const search = (req: SearchRequest) =>
|
export const search = (req: SearchRequest) =>
|
||||||
apiFetch<PagedSearchResponse<SearchResponse>>("/search", {
|
apiFetch<PagedSearchResponse<ServiceItem>>("/search", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(req),
|
body: JSON.stringify(req),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useRef, useState, type SyntheticEvent } from 'react'
|
import { useEffect, useRef, useState, type SyntheticEvent } from 'react'
|
||||||
import '../ui/Modal.scss'
|
import '../ui/Modal.scss'
|
||||||
import { type PagedSearchResponse, type SearchResponse, type SearchRequest } from '../../types/search'
|
import { type PagedSearchResponse, type ServiceItem, type SearchRequest } from '../../types/search'
|
||||||
import { search } from '../../api/searches'
|
import { search } from '../../api/searches'
|
||||||
import type { ServiceType } from '../../types/connection'
|
import type { ServiceType } from '../../types/connection'
|
||||||
|
|
||||||
@@ -14,11 +14,13 @@ interface Props {
|
|||||||
|
|
||||||
export function SearchModal({ serviceType, label, appUrl, username, onClose }: Readonly<Props>) {
|
export function SearchModal({ serviceType, label, appUrl, username, onClose }: Readonly<Props>) {
|
||||||
const [query, setQuery] = useState('')
|
const [query, setQuery] = useState('')
|
||||||
const [results, setResults] = useState<PagedSearchResponse<SearchResponse> | null>(null)
|
const [results, setResults] = useState<PagedSearchResponse<ServiceItem> | null>(null)
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
//TODO: implement aiSearch
|
||||||
|
const [aiSearch, setAiSearch] = useState(false);
|
||||||
const firstInputRef = useRef<HTMLInputElement>(null)
|
const firstInputRef = useRef<HTMLInputElement>(null)
|
||||||
|
|
||||||
const dialogRef = useRef<HTMLDialogElement>(null)
|
const dialogRef = useRef<HTMLDialogElement>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -41,7 +43,7 @@ export function SearchModal({ serviceType, label, appUrl, username, onClose }: R
|
|||||||
setError(null)
|
setError(null)
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
const req: SearchRequest = { appUrl, serviceType, username, query}
|
const req: SearchRequest = { appUrl, serviceType, username, query, aiSearch}
|
||||||
const res = await search(req)
|
const res = await search(req)
|
||||||
console.log(req)
|
console.log(req)
|
||||||
setResults(res)
|
setResults(res)
|
||||||
|
|||||||
@@ -1,25 +1,26 @@
|
|||||||
import type { ServiceType } from "./connection";
|
import type { ServiceType } from "./connection";
|
||||||
|
|
||||||
export interface SearchRequest {
|
export interface SearchRequest {
|
||||||
appUrl: string
|
appUrl: string;
|
||||||
serviceType: ServiceType
|
serviceType: ServiceType;
|
||||||
username: string
|
username: string;
|
||||||
query: string | null
|
query: string | null;
|
||||||
|
aiSearch: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SearchResponse {
|
export interface ServiceItem {
|
||||||
id: string
|
id: string;
|
||||||
title: string
|
title: string;
|
||||||
description: string | null
|
description: string | null;
|
||||||
extraData: Record<string, unknown>
|
extraData: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PagedSearchResponse<T> {
|
export interface PagedSearchResponse<T> {
|
||||||
content: T[]
|
content: T[];
|
||||||
page: number
|
page: number;
|
||||||
pageSize: number
|
pageSize: number;
|
||||||
totalElements: number
|
totalElements: number;
|
||||||
first: boolean
|
first: boolean;
|
||||||
last: boolean
|
last: boolean;
|
||||||
sort: string
|
sort: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user