-
-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathAutoEntityButton.tsx
More file actions
89 lines (82 loc) · 2.75 KB
/
AutoEntityButton.tsx
File metadata and controls
89 lines (82 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { Tooltip, Button, useMediaQuery } from '@mui/material';
import { Autorenew, SwipeVertical } from '@mui/icons-material';
import { useCurrentPoll } from 'src/hooks/useCurrentPoll';
import { theme } from 'src/theme';
import { YOUTUBE_POLL_NAME } from 'src/utils/constants';
import { ComparisonsContext } from 'src/pages/comparisons/Comparison';
import { MobileButton } from 'src/components/buttons';
interface Props {
onClick: () => Promise<void>;
disabled?: boolean;
variant?: 'compact' | 'full';
compactLabel?: string;
compactLabelLoc?: 'left' | 'right';
}
const AutoEntityButton = ({
onClick,
disabled = false,
variant = 'compact',
compactLabel,
compactLabelLoc,
}: Props) => {
const { t } = useTranslation();
const { name: pollName } = useCurrentPoll();
const smallScreen = useMediaQuery(theme.breakpoints.down('sm'));
const context = useContext(ComparisonsContext);
if (pollName !== YOUTUBE_POLL_NAME) {
return null;
}
return (
<>
{smallScreen && variant === 'compact' ? (
<MobileButton
className={context.hasLoopedThroughCriteria ? 'glowing' : undefined}
disabled={disabled}
color="secondary"
size="small"
onClick={onClick}
sx={{
fontSize: { xs: '0.7rem', sm: '0.8rem' },
}}
data-testid={`auto-entity-button-${variant}`}
startIcon={compactLabelLoc === 'left' ? compactLabel : undefined}
endIcon={compactLabelLoc === 'right' ? compactLabel : undefined}
>
<SwipeVertical />
</MobileButton>
) : (
<Tooltip
title={`${t('entitySelector.newVideo')}`}
aria-label="new_video"
>
{/* A non-disabled element, such as <span>, is required by the Tooltip
component to properly listen to fired events. */}
<span>
<Button
fullWidth={variant === 'full' ? true : false}
disabled={disabled}
color="secondary"
variant="outlined"
size="small"
onClick={onClick}
startIcon={variant === 'full' ? undefined : <Autorenew />}
sx={
variant === 'full'
? { minHeight: '100px', fontSize: '1rem' }
: { fontSize: { xs: '0.7rem', sm: '0.8rem' } }
}
data-testid={`auto-entity-button-${variant}`}
>
{variant === 'full'
? t('entitySelector.letTournesolSelectAVideo')
: t('entitySelector.auto')}
</Button>
</span>
</Tooltip>
)}
</>
);
};
export default AutoEntityButton;