Newer
Older
import { AudioOutlined } from "@ant-design/icons";
import { SearchOutlined } from '@ant-design/icons';
import {
Button,
Card,
Col,
Form,
Input,
List,
Row,
Select,
Slider,
Space,
Table,
Typography,
} from "antd";
import React, { useState } from "react";
import { Link } from "react-router-dom";
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",
published: "1.6.2000",
runtimeMinutes: 120,
director: {
id: "123456789",
name: "Karel",
birthdate: "20.2.1987",
},
},
{
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",
published: "1.1.2002",
director: {
id: "123456789",
name: "Karel",
surname: "Vomacka",
birthdate: "20.2.1987",
},
},
];
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//replace with api call only once
const categoriesList: CategoryIO[] = [
{
id: "123",
name: "Horror",
movies: [],
},
{
id: "1231",
name: "Comedy",
movies: [],
},
{
id: "1232",
name: "Drama",
movies: [],
},
{
id: "1234",
name: "Romcom",
movies: [],
},
{
id: "1235",
name: "Western",
movies: [],
},
{
id: "1236",
name: "Documentary",
movies: [],
},
{
id: "1237",
name: "Adam Sandler",
movies: [],
},
{
id: "1238",
name: "Czech",
movies: [],
},
];
//replace with api call only once
const directorsList: DirectorIO[] = [{
name: "Karel1",
surname: "Vomacka",
birthdate: "17.5.1979",
id: "1561",
},{
name: "Karel2",
surname: "Vomacka",
birthdate: "17.5.1979",
id: "1562",
},{
name: "Karel3",
surname: "Vomacka",
birthdate: "17.5.1979",
id: "1563",
},{
name: "Karel4",
surname: "Vomacka",
birthdate: "17.5.1979",
id: "1564",
},{
name: "Karel5",
surname: "Vomacka",
birthdate: "17.5.1979",
id: "1565",
},{
name: "Karel6",
surname: "Vomacka",
birthdate: "17.5.1979",
id: "1566",
},
]
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 delte in future
const [searchValue, setSearch] = useState("");
//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 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",
sorter: (a: MovieIO, b: MovieIO) => {
const first = a.published.split(".").reverse();
const second = b.published.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" }}
>
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<Form>
<Row>
<Col span={6}>
<div>Name</div> <Input></Input>
</Col>
<Col span={6}>
<div>Original name</div>
<Input></Input>
</Col>
</Row>
<Col span={12}>
<div>Runtime</div>
<Slider
marks={runtimeMarks}
range={{ draggableTrack: true }}
step={10}
max={300}
defaultValue={[60, 120]}
></Slider>
</Col>
<Row>
<Col span={12}>
<div>Year published</div>
<Slider
marks={yearMarks}
range={{ draggableTrack: true }}
min={1920}
max={2022}
defaultValue={[2000, 2010]}
></Slider>
</Col>
<Col></Col>
</Row>
<Row>
<Col span={6}>
<div>Category</div>
<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()
)
}
>
{categoriesList.map((cat: CategoryIO) => {
return <Option value={cat.id}>{cat.name}</Option>;
})}
</Select>
</Col>
<Col span={6}>
<div>Directors</div>
<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>)
})}
</Select>
</Col>
</Row>
<Row>
<Col span={12}>
<Button style={{width: "100%"}} type="primary" icon={<SearchOutlined />} size="large">
Search
</Button>
</Col>
</Row>
</Form>
</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>
)}