Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove autofocus on dialog text input, reduce category image size #395

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ui/src/components/Player/DetectionCategoryButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box } from "@mui/material";
import { Box, useMediaQuery, useTheme } from "@mui/material";
import type { StaticImageData } from "next/legacy/image";
import Image from "next/legacy/image";

Expand All @@ -9,6 +9,8 @@ export default function DetectionCategoryButton({
icon: StaticImageData;
title: string;
}) {
const theme = useTheme();
const isDesktop = useMediaQuery(theme.breakpoints.up("sm"));
return (
skanderm marked this conversation as resolved.
Show resolved Hide resolved
<Box
sx={{
Expand All @@ -17,7 +19,12 @@ export default function DetectionCategoryButton({
alignItems: "center",
}}
>
<Image src={icon.src} alt={`${title} icon`} width={100} height={100} />
<Image
src={icon.src}
alt={`${title} icon`}
width={isDesktop ? 100 : 20}
height={isDesktop ? 100 : 20}
/>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new Next.js Image component has some responsive support but I had some difficulties making it work with the fill setting, so I reverted to the legacy Image component with media queries. The icon and the category text were on top of each other, and without fill you need to specify the width/height anyway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about having multiple copies of each image and hiding/unhiding with display: none on different breakpoints?

I've been trying to stay away from useMediaQuery because it's JS based which has some downsides (biggest problem is layout shifts). In this case (inside a modal) it's not really an issue but don't want to encourage the pattern. Unless there's a better solution I don't know of?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yeah legacy Image isn't ideal, but we are using it elsewhere. It may get removed soon since it's been deprecated, so we'll be forced to figure it out at that point… but I guess it buys us some time

{title}
</Box>
);
Expand Down
13 changes: 4 additions & 9 deletions ui/src/components/Player/DetectionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import {
ToggleButton,
ToggleButtonGroup,
Typography,
useMediaQuery,
} from "@mui/material";
import { useTheme } from "@mui/material/styles";
import type { StaticImageData } from "next/legacy/image";
import { useState } from "react";

Expand Down Expand Up @@ -48,8 +46,6 @@ export default function DetectionDialog({
const [description, setDescription] = useState("");
const [playerOffset, setPlayerOffset] = useState<number>();
const [playlistTimestamp, setPlaylistTimestamp] = useState<number>();
const theme = useTheme();
const isDesktop = useMediaQuery(theme.breakpoints.up("sm"));

const submitDetection = useSubmitDetectionMutation({
onSuccess: () => {
Expand Down Expand Up @@ -175,9 +171,9 @@ export default function DetectionDialog({
size="large"
aria-label="Report sound"
fullWidth
orientation={isDesktop ? "horizontal" : "vertical"}
orientation="horizontal"
sx={{
marginY: isDesktop ? 4 : 1,
marginY: [1, 4],
}}
>
{categoryButtons.map(({ id, iconImage }) => (
Expand All @@ -188,8 +184,8 @@ export default function DetectionDialog({
component={Paper}
sx={{
"&&&": {
marginX: isDesktop ? 5 : 0,
marginY: isDesktop ? 0 : 1,
marginX: [1, 5],
marginY: [1, 0],
borderRadius: 1,
overflow: "visible",
border: "solid 2px",
Expand All @@ -209,7 +205,6 @@ export default function DetectionDialog({
))}
</ToggleButtonGroup>
<TextField
autoFocus
margin="dense"
placeholder="Describe what you heard (optional)"
type="text"
Expand Down
Loading