Newer
Older
import { AudioOutlined } from "@ant-design/icons";
import { SearchOutlined } from "@ant-design/icons";
Form,
Input,
List,
Row,
Select,
Slider,
Space,
Table,
Typography,
} from "antd";
import React, { useEffect, useState } from "react";
import axiosConfig from "../axios-config";
import { cardsDataExample, CategoryIO, DirectorIO, MovieIO } from "./Preview";
//TODO replace with result of input search and API call
const resultsExample: MovieIO[] = [
{
id: "789",
name: "Saw",
originalName: "Saw",
intro: "Jigsaw is the bad guy and this is the game",
picture:
"https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse3.mm.bing.net%2Fth%3Fid%3DOIP.Jo6M-3oyAlMsB4-F__Z9bwHaHa%26pid%3DApi&f=1",
publishedAt: "1.6.2000",
runTimeMinutes: 120,
director: {
id: "123456789",
name: "Karel",
},
},
{
id: "999",
name: "Saw 2",
originalName: "Saw 2",
intro: "The sequel to the first one",
picture:
"https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fimages01.kaleidescape.com%2Ftransformed%2Fcovers%2F1134x1624s%2F189%2F18976008.jpg&f=1&nofb=1",
publishedAt: "1.1.2002",
runTimeMinutes: 150,
director: {
id: "123456789",
name: "Karel",
surname: "Vomacka",
const directorsList: DirectorIO[] = [
{
name: "Karel1",
surname: "Vomacka",
id: "1561",
},
{
name: "Karel2",
surname: "Vomacka",
id: "1562",
},
{
name: "Karel3",
surname: "Vomacka",
id: "1563",
},
{
name: "Karel4",
surname: "Vomacka",
id: "1564",
},
{
name: "Karel5",
surname: "Vomacka",
id: "1565",
},
{
name: "Karel6",
surname: "Vomacka",
const runtimeMarks = {
0: "0",
30: "30",
60: "60",
90: "90",
120: "120",
150: "150",
180: "180",
210: "210",
240: "240",
270: "270",
300: "300",
};
const yearMarks = {
1920: "1920",
1940: "1940",
1960: "1960",
1980: "1980",
2000: "2000",
2020: "2020",
};
//for searching movies
export const SearchPage = () => {
const [pressed, setPressed] = useState(true); //may modify or delete in future
const [form] = Form.useForm();
const [categories, setCategories] = useState<CategoryIO[]>([]);
useEffect(() => {
const fetchData = async () => {
try {
const response = await axiosConfig.get<CategoryIO[]>('/categories');
setCategories([ ...response.data ]);
} catch {
}
};
void fetchData();
}, []);
// here will be API call for search on BE, everything needed is in values
const onSubmit = (values: any) => {
alert(JSON.stringify(values));
};
//function that happens when search button is pressed
console.log(searchValue); // just debug tool
}; // API request search goes here - request search with value inside variable "searchValue"
const onReset = () => {
form.resetFields();
};
const columns = [
{
title: "Name",
dataIndex: "name",
sorter: (a: MovieIO, b: MovieIO) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
render: (text: string, record: MovieIO) => (
<Link to={`/movie/${record.id}`}>
<a>{record.name}</a>
</Link>
),
},
{
title: "Original name",
className: "original-name",
dataIndex: "originalName",
sorter: (a: MovieIO, b: MovieIO) => {
if (a.originalName < b.originalName) {
return -1;
}
if (a.originalName > b.originalName) {
return 1;
}
},
{
title: "Release Date",
dataIndex: "published",
const first = a.publishedAt.split(".").reverse();
const second = b.publishedAt.split(".").reverse();
if (first[0] > second[0]) {
return 1;
}
if (first[0] < second[0]) {
return -1;
}
if (first[1] > second[1]) {
return 1;
}
if (first[1] < second[1]) {
return -1;
}
if (first[2] > second[2]) {
return 1;
}
if (first[2] < second[2]) {
return -1;
}
sorter: (a: MovieIO, b: MovieIO) => a.runTimeMinutes - b.runTimeMinutes,
if (a.director.surname < b.director.surname) {
return -1;
}
if (a.director.surname > b.director.surname) {
return 1;
}
if (a.director.name < b.director.name) {
return -1;
}
if (a.director.name > b.director.name) {
return 1;
}
return 0;
},
render: (text: string, record: MovieIO) => (
<Link to={`/director/${record.director.id}`}>
<a>
{record.director.name} {record.director.surname}
</a>
<Space
direction="vertical"
style={{ display: "flex", padding: 24, textAlign: "center" }}
>
<Form form={form} onFinish={onSubmit}>
<Row gutter={20}>
<Form.Item name="name" label="Name">
<Input></Input>
</Form.Item>
<Form.Item name="originalName" label="Original name">
<Input></Input>
</Form.Item>
</Col>
</Row>
<Row gutter={20}>
<Col span={12}>
<Form.Item name="runtime" label="Runtime minutes">
<Slider
marks={runtimeMarks}
range={{ draggableTrack: true }}
step={10}
max={300}
defaultValue={[60, 120]}
></Slider>
</Form.Item>
<Form.Item name="published" label="Year published">
<Slider
marks={yearMarks}
range={{ draggableTrack: true }}
min={1920}
max={2022}
defaultValue={[2000, 2010]}
></Slider>
<Form.Item name="category" label="Category">
<Select
showSearch
style={{ width: "100%" }}
placeholder="Search to Select"
optionFilterProp="children"
filterOption={(input, option) =>
(option!.children as unknown as string).includes(input)
}
filterSort={(optionA, optionB) =>
(optionA!.children as unknown as string)
.toLowerCase()
.localeCompare(
(optionB!.children as unknown as string).toLowerCase()
)
}
>
{categories.map((category: CategoryIO) => {
return <Option value={category.id}>{category.name}</Option>;
<Form.Item name="director" label="Director">
<Select
showSearch
style={{ width: "100%" }}
placeholder="Search to Select"
optionFilterProp="children"
filterOption={(input, option) =>
(option!.children as unknown as string).includes(input)
}
filterSort={(optionA, optionB) =>
(optionA!.children as unknown as string)
.toLowerCase()
.localeCompare(
(optionB!.children as unknown as string).toLowerCase()
)
}
>
{directorsList.map((dir: DirectorIO) => {
return (
<Option value={dir.id}>
{dir.name + " " + dir.surname}
</Option>
);
})}
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<Divider></Divider>
</Col>
</Row>
<Row gutter={20}>
<Col span={6}>
<Form.Item name="searchbutton">
<Button
htmlType="submit"
style={{ width: "100%" }}
type="primary"
icon={<SearchOutlined />}
size="large"
>
Search
</Button>
</Form.Item>
</Col>
<Col span={6}>
<Form.Item name="reset">
<Button
size="large"
type="default"
style={{ width: "100%" }}
onClick={onReset}
>
Reset
</Button>
</Form.Item>
</Space>
{pressed && (
<Space
direction="vertical"
style={{ display: "flex", padding: 24, textAlign: "left" }}
>
<Table
onRow={(record, rowIndex) => {
return {
onClick: (event) => {
console.log(record.id); //remove later
},
}; //here change to view movie
}}
columns={columns}
dataSource={resultsExample}
bordered
title={() => "Results"}
/>
</Space>
)}