2021-07-13 22:31:37 +00:00
|
|
|
import React from 'react';
|
2021-08-02 12:15:18 +00:00
|
|
|
import { useHistory } from 'react-router-dom';
|
2021-07-13 22:31:37 +00:00
|
|
|
import { useMovie } from '../hooks/useMovie'
|
|
|
|
import { Arrow } from '../components/Arrow'
|
|
|
|
import './Title.css'
|
|
|
|
|
|
|
|
// size: "big" | "medium" | "small" | null
|
|
|
|
// accent: string | null
|
|
|
|
// accentLink: string | null
|
|
|
|
export function Title(props) {
|
2021-08-02 12:15:18 +00:00
|
|
|
const { streamData, resetStreamData } = useMovie();
|
|
|
|
const history = useHistory();
|
2021-07-13 22:31:37 +00:00
|
|
|
const size = props.size || "big";
|
|
|
|
|
|
|
|
const accentLink = props.accentLink || "";
|
|
|
|
const accent = props.accent || "";
|
2022-01-03 12:30:41 +00:00
|
|
|
|
|
|
|
function handleAccentClick(){
|
|
|
|
if (accentLink.length > 0) {
|
|
|
|
history.push(`/${streamData.type}`);
|
|
|
|
resetStreamData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleKeyPress(event){
|
|
|
|
if (event.code === 'Enter' || event.code === 'Space'){
|
|
|
|
handleAccentClick();
|
|
|
|
}
|
|
|
|
}
|
2021-08-07 18:42:56 +00:00
|
|
|
|
2021-07-13 22:31:37 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{accent.length > 0 ? (
|
2022-01-03 12:30:41 +00:00
|
|
|
<p onClick={handleAccentClick} className={`title-accent ${accentLink.length > 0 ? 'title-accent-link' : ''}`} tabIndex={accentLink.length > 0 ? 0 : undefined} onKeyPress={handleKeyPress}>
|
2021-07-13 22:31:37 +00:00
|
|
|
{accentLink.length > 0 ? (<Arrow left/>) : null}{accent}
|
|
|
|
</p>
|
|
|
|
) : null}
|
2021-08-07 18:42:56 +00:00
|
|
|
<h1 className={"title " + ( size ? `title-size-${size}` : '' )}>{props.children}</h1>
|
2021-07-13 22:31:37 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|