mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
refactor(frontend): titlecard behavior changed to allow clicking anywhere to go through to title
mobile behavior remains mostly the same, except after the first click, a second click anywhere else will go through to the title.
This commit is contained in:
@@ -10,10 +10,11 @@ import Link from 'next/link';
|
|||||||
import { MediaStatus } from '../../../server/constants/media';
|
import { MediaStatus } from '../../../server/constants/media';
|
||||||
import RequestModal from '../RequestModal';
|
import RequestModal from '../RequestModal';
|
||||||
import { defineMessages, useIntl } from 'react-intl';
|
import { defineMessages, useIntl } from 'react-intl';
|
||||||
|
import { useIsTouch } from '../../hooks/useIsTouch';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
movie: 'MOVIE',
|
movie: 'Movie',
|
||||||
tvshow: 'SERIES',
|
tvshow: 'Series',
|
||||||
});
|
});
|
||||||
|
|
||||||
interface TitleCardProps {
|
interface TitleCardProps {
|
||||||
@@ -38,6 +39,7 @@ const TitleCard: React.FC<TitleCardProps> = ({
|
|||||||
mediaType,
|
mediaType,
|
||||||
canExpand = false,
|
canExpand = false,
|
||||||
}) => {
|
}) => {
|
||||||
|
const isTouch = useIsTouch();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [isUpdating, setIsUpdating] = useState(false);
|
const [isUpdating, setIsUpdating] = useState(false);
|
||||||
const [currentStatus, setCurrentStatus] = useState(status);
|
const [currentStatus, setCurrentStatus] = useState(status);
|
||||||
@@ -74,9 +76,13 @@ const TitleCard: React.FC<TitleCardProps> = ({
|
|||||||
<div
|
<div
|
||||||
className="titleCard outline-none cursor-default"
|
className="titleCard outline-none cursor-default"
|
||||||
style={{
|
style={{
|
||||||
backgroundImage: `url(//image.tmdb.org/t/p/w600_and_h900_bestv2${image})`,
|
backgroundImage: `url(//image.tmdb.org/t/p/w300_and_h450_face${image})`,
|
||||||
|
}}
|
||||||
|
onMouseEnter={() => {
|
||||||
|
if (!isTouch) {
|
||||||
|
setShowDetail(true);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
onMouseEnter={() => setShowDetail(true)}
|
|
||||||
onMouseLeave={() => setShowDetail(false)}
|
onMouseLeave={() => setShowDetail(false)}
|
||||||
onClick={() => setShowDetail(true)}
|
onClick={() => setShowDetail(true)}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
@@ -146,15 +152,16 @@ const TitleCard: React.FC<TitleCardProps> = ({
|
|||||||
|
|
||||||
<Transition
|
<Transition
|
||||||
show={!image || showDetail || showRequestModal}
|
show={!image || showDetail || showRequestModal}
|
||||||
enter="transition ease-in-out duration-300 transform opacity-0"
|
enter="transition transform opacity-0"
|
||||||
enterFrom="opacity-0"
|
enterFrom="opacity-0"
|
||||||
enterTo="opacity-100"
|
enterTo="opacity-100"
|
||||||
leave="transition ease-in-out duration-300 transform opacity-100"
|
leave="transition transform opacity-100"
|
||||||
leaveFrom="opacity-100"
|
leaveFrom="opacity-100"
|
||||||
leaveTo="opacity-0"
|
leaveTo="opacity-0"
|
||||||
>
|
>
|
||||||
<div
|
<Link href={mediaType === 'movie' ? `/movie/${id}` : `/tv/${id}`}>
|
||||||
className="absolute w-full text-left top-0 right-0 left-0 bottom-0 rounded-lg overflow-hidden"
|
<a
|
||||||
|
className="absolute w-full text-left top-0 right-0 left-0 bottom-0 rounded-lg overflow-hidden cursor-pointer"
|
||||||
style={{
|
style={{
|
||||||
background:
|
background:
|
||||||
'linear-gradient(180deg, rgba(45, 55, 72, 0.4) 0%, rgba(45, 55, 72, 0.9) 100%)',
|
'linear-gradient(180deg, rgba(45, 55, 72, 0.4) 0%, rgba(45, 55, 72, 0.9) 100%)',
|
||||||
@@ -182,9 +189,8 @@ const TitleCard: React.FC<TitleCardProps> = ({
|
|||||||
<div className="flex justify-between left-0 bottom-0 right-0 top-0 px-2 py-2">
|
<div className="flex justify-between left-0 bottom-0 right-0 top-0 px-2 py-2">
|
||||||
<Link
|
<Link
|
||||||
href={
|
href={
|
||||||
mediaType === 'movie' ? '/movie/[movieId]' : '/tv/[tvId]'
|
mediaType === 'movie' ? `/movie/${id}` : `/tv/${id}`
|
||||||
}
|
}
|
||||||
as={mediaType === 'movie' ? `/movie/${id}` : `/tv/${id}`}
|
|
||||||
>
|
>
|
||||||
<a className="cursor-pointer flex w-full h-7 text-center text-white bg-indigo-500 rounded-sm hover:bg-indigo-400 focus:border-indigo-700 focus:ring-indigo active:bg-indigo-700 transition ease-in-out duration-150">
|
<a className="cursor-pointer flex w-full h-7 text-center text-white bg-indigo-500 rounded-sm hover:bg-indigo-400 focus:border-indigo-700 focus:ring-indigo active:bg-indigo-700 transition ease-in-out duration-150">
|
||||||
<svg
|
<svg
|
||||||
@@ -212,7 +218,10 @@ const TitleCard: React.FC<TitleCardProps> = ({
|
|||||||
{(!currentStatus ||
|
{(!currentStatus ||
|
||||||
currentStatus === MediaStatus.UNKNOWN) && (
|
currentStatus === MediaStatus.UNKNOWN) && (
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowRequestModal(true)}
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setShowRequestModal(true);
|
||||||
|
}}
|
||||||
className="w-full h-7 text-center text-white bg-indigo-500 rounded-sm ml-2 hover:bg-indigo-400 focus:border-indigo-700 focus:ring-indigo active:bg-indigo-700 transition ease-in-out duration-150"
|
className="w-full h-7 text-center text-white bg-indigo-500 rounded-sm ml-2 hover:bg-indigo-400 focus:border-indigo-700 focus:ring-indigo active:bg-indigo-700 transition ease-in-out duration-150"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
@@ -297,7 +306,8 @@ const TitleCard: React.FC<TitleCardProps> = ({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</a>
|
||||||
|
</Link>
|
||||||
</Transition>
|
</Transition>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
20
src/context/InteractionContext.tsx
Normal file
20
src/context/InteractionContext.tsx
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import useInteraction from '../hooks/useInteraction';
|
||||||
|
|
||||||
|
interface InteractionContextProps {
|
||||||
|
isTouch: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const InteractionContext = React.createContext<InteractionContextProps>({
|
||||||
|
isTouch: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const InteractionProvider: React.FC = ({ children }) => {
|
||||||
|
const isTouch = useInteraction();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<InteractionContext.Provider value={{ isTouch }}>
|
||||||
|
{children}
|
||||||
|
</InteractionContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
78
src/hooks/useInteraction.ts
Normal file
78
src/hooks/useInteraction.ts
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import { useState, useEffect } from 'react';
|
||||||
|
|
||||||
|
export const INTERACTION_TYPE = {
|
||||||
|
MOUSE: 'mouse',
|
||||||
|
PEN: 'pen',
|
||||||
|
TOUCH: 'touch',
|
||||||
|
};
|
||||||
|
|
||||||
|
const UPDATE_INTERVAL = 1000; // Throttle updates to the type to prevent flip flopping
|
||||||
|
|
||||||
|
const useInteraction = (): boolean => {
|
||||||
|
const [isTouch, setIsTouch] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const hasTapEvent = 'ontouchstart' in window;
|
||||||
|
setIsTouch(hasTapEvent);
|
||||||
|
|
||||||
|
let localTouch = hasTapEvent;
|
||||||
|
let lastTouchUpdate = Date.now();
|
||||||
|
|
||||||
|
const shouldUpdate = (): boolean =>
|
||||||
|
lastTouchUpdate + UPDATE_INTERVAL < Date.now();
|
||||||
|
|
||||||
|
const onMouseMove = (): void => {
|
||||||
|
if (localTouch && shouldUpdate()) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (shouldUpdate()) {
|
||||||
|
setIsTouch(false);
|
||||||
|
localTouch = false;
|
||||||
|
}
|
||||||
|
}, UPDATE_INTERVAL);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onTouchStart = (): void => {
|
||||||
|
lastTouchUpdate = Date.now();
|
||||||
|
|
||||||
|
if (!localTouch) {
|
||||||
|
setIsTouch(true);
|
||||||
|
localTouch = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onPointerMove = (e: PointerEvent): void => {
|
||||||
|
const { pointerType } = e;
|
||||||
|
|
||||||
|
switch (pointerType) {
|
||||||
|
case INTERACTION_TYPE.TOUCH:
|
||||||
|
case INTERACTION_TYPE.PEN:
|
||||||
|
return onTouchStart();
|
||||||
|
default:
|
||||||
|
return onMouseMove();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (hasTapEvent) {
|
||||||
|
window.addEventListener('mousemove', onMouseMove);
|
||||||
|
window.addEventListener('touchstart', onTouchStart);
|
||||||
|
} else {
|
||||||
|
window.addEventListener('pointerdown', onPointerMove);
|
||||||
|
window.addEventListener('pointermove', onPointerMove);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (hasTapEvent) {
|
||||||
|
window.removeEventListener('mousemove', onMouseMove);
|
||||||
|
window.removeEventListener('touchstart', onTouchStart);
|
||||||
|
} else {
|
||||||
|
window.removeEventListener('pointerdown', onPointerMove);
|
||||||
|
window.removeEventListener('pointermove', onPointerMove);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return isTouch;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useInteraction;
|
7
src/hooks/useIsTouch.ts
Normal file
7
src/hooks/useIsTouch.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { useContext } from 'react';
|
||||||
|
import { InteractionContext } from '../context/InteractionContext';
|
||||||
|
|
||||||
|
export const useIsTouch = (): boolean => {
|
||||||
|
const { isTouch } = useContext(InteractionContext);
|
||||||
|
return isTouch;
|
||||||
|
};
|
@@ -12,6 +12,7 @@ import { IntlProvider } from 'react-intl';
|
|||||||
import { LanguageContext, AvailableLocales } from '../context/LanguageContext';
|
import { LanguageContext, AvailableLocales } from '../context/LanguageContext';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
import Toast from '../components/Toast';
|
import Toast from '../components/Toast';
|
||||||
|
import { InteractionProvider } from '../context/InteractionContext';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const loadLocaleData = (locale: string): Promise<any> => {
|
const loadLocaleData = (locale: string): Promise<any> => {
|
||||||
@@ -90,12 +91,14 @@ const CoreApp: Omit<NextAppComponentType, 'origGetInitialProps'> = ({
|
|||||||
defaultLocale="en"
|
defaultLocale="en"
|
||||||
messages={loadedMessages}
|
messages={loadedMessages}
|
||||||
>
|
>
|
||||||
|
<InteractionProvider>
|
||||||
<ToastProvider components={{ Toast }}>
|
<ToastProvider components={{ Toast }}>
|
||||||
<Head>
|
<Head>
|
||||||
<title>Overseerr</title>
|
<title>Overseerr</title>
|
||||||
</Head>
|
</Head>
|
||||||
<UserContext initialUser={user}>{component}</UserContext>
|
<UserContext initialUser={user}>{component}</UserContext>
|
||||||
</ToastProvider>
|
</ToastProvider>
|
||||||
|
</InteractionProvider>
|
||||||
</IntlProvider>
|
</IntlProvider>
|
||||||
</LanguageContext.Provider>
|
</LanguageContext.Provider>
|
||||||
</SWRConfig>
|
</SWRConfig>
|
||||||
|
Reference in New Issue
Block a user