1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-30 16:17:41 +01:00

begin show implementation

This commit is contained in:
James Hawkins 2021-07-14 16:15:25 +01:00
parent b94f2792b7
commit 19891569b7
4 changed files with 62 additions and 19 deletions

View file

@ -19,7 +19,6 @@
.inputTextBox { .inputTextBox {
border-width: 0; border-width: 0;
outline: none; outline: none;
background-color: #36363e; background-color: #36363e;
color: white; color: white;
padding: .7rem 1.5rem; padding: .7rem 1.5rem;
@ -35,10 +34,38 @@
padding: .5rem 2.1rem; padding: .5rem 2.1rem;
font-weight: bold; font-weight: bold;
cursor: pointer; cursor: pointer;
} }
.inputDropdown {
border-width: 0;
outline: none;
background-color: #36363e;
color: white;
padding: .7rem;
height: auto;
width: 20%;
color: white;
font-weight: bold;
cursor: pointer;
}
.inputOptionBox {
border-width: 0;
outline: none;
background-color: #36363e;
color: white;
/* padding: .7rem 1.5rem; */
height: auto;
width: 5%;
box-sizing: border-box;
}
.inputDropdown:hover {
background-color: #3C3D44;
}
.inputSearchButton:hover { .inputSearchButton:hover {
background-color: #9C3179; background-color: #9C3179;
} }
@ -85,9 +112,15 @@
.inputSearchButton { .inputSearchButton {
margin-top: .5rem; margin-top: .5rem;
align-self: center;
} }
.inputTextBox { .inputTextBox {
width: 100%; width: 100%;
} }
.inputDropdown {
width: 100%;
margin-bottom: .5rem;
}
} }

View file

@ -4,23 +4,33 @@ import './InputBox.css'
// props = { onSubmit: (str) => {}, placeholder: string} // props = { onSubmit: (str) => {}, placeholder: string}
export function InputBox({ onSubmit, placeholder }) { export function InputBox({ onSubmit, placeholder }) {
const [value, setValue] = React.useState(""); const [searchTerm, setSearchTerm] = React.useState("");
const [type, setType] = React.useState("movie");
const showContentType = type === "show" ? false : true;
return ( return (
<form className="inputBar" onSubmit={(e) => { <form className="inputBar" onSubmit={(e) => {
e.preventDefault(); e.preventDefault();
onSubmit(value) onSubmit(searchTerm, type)
return false; return false;
}}> }}>
<select name="type" id="type" className="inputDropdown" onChange={(e) => setType(e.target.value)} required>
<option value="movie">Movie</option>
<option value="show">TV Show</option>
</select>
<input <input
type='text' type='text'
className="inputTextBox" className="inputTextBox"
id="inputTextBox" id="inputTextBox"
placeholder={placeholder} placeholder={placeholder}
value={value} value={searchTerm}
onChange={(e) => setValue(e.target.value)} onChange={(e) => setSearchTerm(e.target.value)}
required
/> />
<button className="inputSearchButton"><span className="text">Search<span className="arrow"><Arrow/></span></span></button> <input type='text' className='inputOptionBox' id='inputOptionBoxSeason' placeholder='s' required={showContentType} hidden={showContentType}/>
<input type='text' className='inputOptionBox' id='inputOptionBoxEpisode' placeholder='e' required={showContentType} hidden={showContentType}/>
<button className="inputSearchButton"><span className="text">Search<span className="arrow"><Arrow /></span></span></button>
</form> </form>
) )
} }

View file

@ -63,7 +63,7 @@ async function getStreamUrl(slug, type) {
return { url: videoUrl } return { url: videoUrl }
} }
async function findMovie(searchTerm) { async function findContent(searchTerm, type) {
const searchUrl = getCorsUrl(`https://lookmovie.io/api/v1/movies/search/?q=${encodeURIComponent(searchTerm)}`); const searchUrl = getCorsUrl(`https://lookmovie.io/api/v1/movies/search/?q=${encodeURIComponent(searchTerm)}`);
const searchRes = await fetch(searchUrl).then((d) => d.json()); const searchRes = await fetch(searchUrl).then((d) => d.json());
let results = [...searchRes.result.map((v) => ({ ...v, type: "movie" }))]; let results = [...searchRes.result.map((v) => ({ ...v, type: "movie" }))];
@ -97,4 +97,4 @@ async function findMovie(searchTerm) {
} }
} }
export { findMovie, getStreamUrl }; export { findContent, getStreamUrl };

View file

@ -5,7 +5,7 @@ import { Card } from '../components/Card'
import { MovieRow } from '../components/MovieRow' import { MovieRow } from '../components/MovieRow'
import { Arrow } from '../components/Arrow' import { Arrow } from '../components/Arrow'
import { Progress } from '../components/Progress' import { Progress } from '../components/Progress'
import { findMovie, getStreamUrl } from '../lib/lookMovie' import { findContent, getStreamUrl } from '../lib/lookMovie'
import { useMovie } from '../hooks/useMovie'; import { useMovie } from '../hooks/useMovie';
import './Search.css' import './Search.css'
@ -45,20 +45,20 @@ export function SearchView() {
} }
} }
async function searchMovie(query) { async function searchMovie(query, contentType) {
setFailed(false); setFailed(false);
setText(`Searching for "${query}"`); setText(`Searching for ${contentType} "${query}"`);
setProgress(1) setProgress(1)
setShowingOptions(false) setShowingOptions(false)
try { try {
const { options } = await findMovie(query) const { options } = await findContent(query, contentType)
if (options.length === 0) { if (options.length === 0) {
return fail("Could not find that movie") return fail(`Could not find that ${contentType}`)
} else if (options.length > 1) { } else if (options.length > 1) {
setProgress(2); setProgress(2);
setText("Choose your movie"); setText(`Choose your ${contentType}`);
setOptions(options); setOptions(options);
setShowingOptions(true); setShowingOptions(true);
return; return;
@ -67,17 +67,17 @@ export function SearchView() {
const { title, slug, type } = options[0]; const { title, slug, type } = options[0];
getStream(title, slug, type); getStream(title, slug, type);
} catch (err) { } catch (err) {
fail("Failed to watch movie") fail(`Failed to watch ${contentType}`)
} }
} }
return ( return (
<div className="cardView"> <div className="cardView">
<Card> <Card>
<Title accent="Because watching movies legally is boring"> <Title accent="Because watching content legally is boring">
What movie do you wanna watch? What do you wanna watch?
</Title> </Title>
<InputBox placeholder="Hamilton" onSubmit={(str) => searchMovie(str)} /> <InputBox placeholder="Hamilton" onSubmit={(str, type) => searchMovie(str, type)} />
<Progress show={progress > 0} failed={failed} progress={progress} steps={maxSteps} text={text} /> <Progress show={progress > 0} failed={failed} progress={progress} steps={maxSteps} text={text} />
</Card> </Card>