Skip to content

Commit

Permalink
antdのreact19に関する複数の問題を修正しました。
Browse files Browse the repository at this point in the history
  • Loading branch information
harumiWeb committed Jan 10, 2025
1 parent ccc33cc commit b21253b
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 102 deletions.
24 changes: 4 additions & 20 deletions app/components/ConvertButton/ConvertButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";

import { Button } from "antd";
import { useAtom } from "jotai";
import {
filePathsAtom,
Expand All @@ -14,20 +13,6 @@ import {
import { Modal } from "antd";
import { convert } from "@/app/lib/utils";
import "@ant-design/v5-patch-for-react-19";
import { createStyles } from 'antd-style';

const useStyles = createStyles(({ token, css }) => {
return {
button: css`
padding: 20px 16px;
font-weight: bold;
text-transform: uppercase;
color: ${token.colorPrimary};
letter-spacing: 0.1em;
font-size: 18px;
`
};
});

export default function ConvertButton() {
const [filePaths] = useAtom(filePathsAtom);
Expand All @@ -37,12 +22,11 @@ export default function ConvertButton() {
const [isProcessing, setIsProcessing] = useAtom(isProcessingAtom);
const [, setProcessedFilePaths] = useAtom(processedFilePathsAtom);
const [, setTabSelected] = useAtom(tabSelectedAtom);
const { styles, } = useStyles();
const [modal, contextHolder] = Modal.useModal();

return (
<>
<Button
<button
onClick={() =>
convert(
setIsProcessing,
Expand All @@ -55,8 +39,8 @@ export default function ConvertButton() {
setTabSelected
)
}
className={`${styles.button} ${
filePaths.length > 0 && !isProcessing ? "" : "cursor-not-allowed"
className={`bg-white font-bold text-lg uppercase text-primary border-none p-[8px_8px] tracking-wider hover:bg-[#b1fede] rounded-md transition-all duration-200 ${
filePaths.length > 0 && !isProcessing ? "" : "cursor-not-allowed opacity-50"
}`}
title={
filePaths.length > 0 && !isProcessing
Expand All @@ -66,7 +50,7 @@ export default function ConvertButton() {
disabled={filePaths.length === 0 || isProcessing}
>
Convert
</Button>
</button>
{contextHolder}
</>
);
Expand Down
2 changes: 1 addition & 1 deletion app/components/LoadingModal/LoadingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function LoadingModal() {
isProcessing || isSaving ? "block" : "hidden"
}`}
>
<div className="bg-white rounded-lg px-6 py-6 min-w-[300px] flex flex-col gap-4 justify-center items-center">
<div className="bg-white rounded-lg px-6 py-6 min-w-[300px] flex flex-col gap-4 justify-center items-center modal-open-animation">
<div className="flex flex-col gap-2 justify-center items-center">
<Spin size="large"></Spin>
<p className="text-lg font-medium text-[#00b96b]">
Expand Down
2 changes: 2 additions & 0 deletions app/components/SettingsMenu/Quality.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ const IntegerStep: React.FC = () => {
min={1}
max={100}
onChange={onChange}
defaultValue={75}
value={typeof inputValue === "number" ? inputValue : 0}
/>
</Col>
<Col span={4}>
<InputNumber
min={1}
max={100}
defaultValue={75}
style={{ margin: "0 16px" }}
value={inputValue}
onChange={onChange}
Expand Down
56 changes: 22 additions & 34 deletions app/components/WindowMenu/ContextMenu/FileMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import type { MenuProps } from "antd";
import { Dropdown, Button } from "antd";
import { Dropdown } from "antd";
import { useAtom } from "jotai";
import {
fileInfosAtom,
Expand All @@ -20,7 +20,6 @@ import { convert, openDialog, saveAll, saveSelected } from "@/app/lib/utils";
import { useEffect, useRef, useState } from "react";
import { Modal } from "antd";
import "@ant-design/v5-patch-for-react-19";
import { useStyles } from "@/app/components/WindowMenu/WindowMenu";

const items: MenuProps["items"] = [
{
Expand Down Expand Up @@ -53,23 +52,20 @@ const items: MenuProps["items"] = [

export default function FileMenu() {
const [filePaths, setFilePaths] = useAtom(filePathsAtom);
const [isFocused, ] = useAtom(isFocusedAtom);
const [isFocused] = useAtom(isFocusedAtom);
const fileButtonRef = useRef<HTMLButtonElement | null>(null);
const [fileInfos, setFileInfos] = useAtom(fileInfosAtom);
const [tabSelected, setTabSelected] = useAtom(tabSelectedAtom);
const [processedFilePathsSorted, setProcessedFilePathsSorted] = useAtom(
processedFilePathsSortedAtom
);
const [checkboxSelected, setCheckboxSelected] = useAtom(checkboxSelectedAtom);
const [, setProcessedFilePaths] = useAtom(
processedFilePathsAtom
);
const [, setProcessedFilePaths] = useAtom(processedFilePathsAtom);
const [, setIsSaving] = useAtom(isSavingAtom);
const [quality, ] = useAtom(qualityAtom);
const [extensionType, ] = useAtom(extensionTypeAtom);
const [quality] = useAtom(qualityAtom);
const [extensionType] = useAtom(extensionTypeAtom);
const [isProcessing, setIsProcessing] = useAtom(isProcessingAtom);
const [modal, ] = Modal.useModal();
const { styles, } = useStyles();
const [modal] = Modal.useModal();

function removeResult() {
setProcessedFilePathsSorted([]);
Expand Down Expand Up @@ -160,13 +156,13 @@ export default function FileMenu() {

return (
<Dropdown menu={{ items }} trigger={["click"]}>
<Button
<button
ref={fileButtonRef}
onClick={() => {}}
className={styles.button}
className="bg-primary text-white border-none h-[98%] p-[2px_8px] text-sm tracking-wide hover:bg-[#84ddb8] rounded-md transition-all duration-200"
>
File(F)
</Button>
</button>
</Dropdown>
);
}
Expand Down Expand Up @@ -194,15 +190,13 @@ function FileOpen(): React.ReactNode {

function FileRemoveAll(): React.ReactNode {
const [filePaths, setFilePaths] = useAtom(filePathsAtom);
const [tabSelected, ] = useAtom(tabSelectedAtom);
const [tabSelected] = useAtom(tabSelectedAtom);
const [, setFileInfos] = useAtom(fileInfosAtom);
const [processedFilePathsSorted, setProcessedFilePathsSorted] = useAtom(
processedFilePathsSortedAtom
);
const [, setCheckboxSelected] = useAtom(checkboxSelectedAtom);
const [, setProcessedFilePaths] = useAtom(
processedFilePathsAtom
);
const [, setProcessedFilePaths] = useAtom(processedFilePathsAtom);

function removeAll() {
setFilePaths([]);
Expand Down Expand Up @@ -255,10 +249,8 @@ function FileRemoveAll(): React.ReactNode {

function FileSaveAll(): React.ReactNode {
const [isSaving, setIsSaving] = useState(false);
const [processedFilePathsSorted, ] = useAtom(
processedFilePathsSortedAtom
);
const [modal, ] = Modal.useModal();
const [processedFilePathsSorted] = useAtom(processedFilePathsSortedAtom);
const [modal] = Modal.useModal();
return (
<button
className={`flex items-center justify-between leading-5 w-full ${
Expand All @@ -285,11 +277,9 @@ function FileSaveAll(): React.ReactNode {

function FileSaveSelected(): React.ReactNode {
const [isSaving, setIsSaving] = useState(false);
const [processedFilePathsSorted, ] = useAtom(
processedFilePathsSortedAtom
);
const [checkboxSelected, ] = useAtom(checkboxSelectedAtom);
const [modal, ] = Modal.useModal();
const [processedFilePathsSorted] = useAtom(processedFilePathsSortedAtom);
const [checkboxSelected] = useAtom(checkboxSelectedAtom);
const [modal] = Modal.useModal();
return (
<button
className={`flex items-center justify-between leading-5 w-full ${
Expand Down Expand Up @@ -328,14 +318,12 @@ function FileSaveSelected(): React.ReactNode {

function FileConvert(): React.ReactNode {
const [isProcessing, setIsProcessing] = useAtom(isProcessingAtom);
const [, setProcessedFilePaths] = useAtom(
processedFilePathsAtom
);
const [modal, ] = Modal.useModal();
const [filePaths, ] = useAtom(filePathsAtom);
const [fileInfos, ] = useAtom(fileInfosAtom);
const [quality, ] = useAtom(qualityAtom);
const [extensionType, ] = useAtom(extensionTypeAtom);
const [, setProcessedFilePaths] = useAtom(processedFilePathsAtom);
const [modal] = Modal.useModal();
const [filePaths] = useAtom(filePathsAtom);
const [fileInfos] = useAtom(fileInfosAtom);
const [quality] = useAtom(qualityAtom);
const [extensionType] = useAtom(extensionTypeAtom);
const [, setTabSelected] = useAtom(tabSelectedAtom);
return (
<button
Expand Down
11 changes: 5 additions & 6 deletions app/components/WindowMenu/ContextMenu/HelpMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use client";

import type { MenuProps } from "antd";
import { Dropdown, Button, Modal } from "antd";
import { Dropdown, Modal } from "antd";
import { useAtom } from "jotai";
import { isFocusedAtom } from "@/app/lib/atom";
import { useEffect, useRef, useState } from "react";
import "@ant-design/v5-patch-for-react-19";
import { useStyles } from "@/app/components/WindowMenu/WindowMenu";
import "antd/dist/reset.css";

const items: MenuProps["items"] = [
{
Expand All @@ -18,7 +18,6 @@ const items: MenuProps["items"] = [
export default function HelpMenu() {
const [isFocused] = useAtom(isFocusedAtom);
const helpButtonRef = useRef<HTMLButtonElement | null>(null);
const { styles, } = useStyles();
useEffect(() => {
const handleKeyDownSelectShortcut = async (event: KeyboardEvent) => {
if (event.key === "h" && event.altKey && isFocused) {
Expand All @@ -37,13 +36,13 @@ export default function HelpMenu() {

return (
<Dropdown menu={{ items }} trigger={["click"]}>
<Button
<button
onClick={() => {}}
className={styles.button}
className="bg-primary text-white border-none h-[98%] p-[2px_8px] text-sm tracking-wide hover:bg-[#84ddb8] rounded-md transition-all duration-200"
ref={helpButtonRef}
>
Help(H)
</Button>
</button>
</Dropdown>
);
}
Expand Down
45 changes: 29 additions & 16 deletions app/components/WindowMenu/ContextMenu/SelectMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
"use client";

import type { MenuProps } from "antd";
import { Dropdown, Button } from "antd";
import { Dropdown } from "antd";
import { useAtom } from "jotai";
import { checkboxSelectedAtom, isFocusedAtom, processedFilePathsSortedAtom } from "@/app/lib/atom";
import {
checkboxSelectedAtom,
isFocusedAtom,
processedFilePathsSortedAtom,
} from "@/app/lib/atom";
import { useEffect, useRef } from "react";
import "@ant-design/v5-patch-for-react-19";
import { useStyles } from "@/app/components/WindowMenu/WindowMenu";

const items: MenuProps["items"] = [
{
label: <SelectAll />,
key: "0",
}
},
];

export default function SelectMenu() {
const [isFocused, ] = useAtom(isFocusedAtom);
const [isFocused] = useAtom(isFocusedAtom);
const [checkboxSelected, setCheckboxSelected] = useAtom(checkboxSelectedAtom);
const [processedFilePathsSorted, ] = useAtom(processedFilePathsSortedAtom);
const [processedFilePathsSorted] = useAtom(processedFilePathsSortedAtom);
const selectButtonRef = useRef<HTMLButtonElement | null>(null);
const { styles, } = useStyles();
useEffect(() => {
const handleKeyDownSelectShortcut = async (event: KeyboardEvent) => {
if (event.key === "a" && event.ctrlKey && isFocused && processedFilePathsSorted.length > 0) {
if (
event.key === "a" &&
event.ctrlKey &&
isFocused &&
processedFilePathsSorted.length > 0
) {
event.preventDefault();
setCheckboxSelected((prev) =>
prev.map((item) => ({
Expand All @@ -47,29 +54,31 @@ export default function SelectMenu() {

return (
<Dropdown menu={{ items }} trigger={["click"]}>
<Button
<button
onClick={() => {}}
className={styles.button}
ref={selectButtonRef}
className="bg-primary text-white border-none h-[98%] p-[2px_8px] text-sm tracking-wide hover:bg-[#84ddb8] rounded-md transition-all duration-200"
>
Select(S)
</Button>
</button>
</Dropdown>
);
}

function SelectAll(): React.ReactNode {
const [, setCheckboxSelected] = useAtom(checkboxSelectedAtom);
const [processedFilePathsSorted, ] = useAtom(processedFilePathsSortedAtom);
const [processedFilePathsSorted] = useAtom(processedFilePathsSortedAtom);
return (
<button
title="Select all files."
onClick={() => setCheckboxSelected((prev) =>
onClick={() =>
setCheckboxSelected((prev) =>
prev.map((item) => ({
...item,
checked: !item.checked,
}))
)}
)
}
onKeyDown={(e) => {
if (e.key === "Enter") {
setCheckboxSelected((prev) =>
Expand All @@ -81,12 +90,16 @@ function SelectAll(): React.ReactNode {
}
}}
disabled={processedFilePathsSorted.length === 0}
className={`flex items-center justify-between leading-5 ${processedFilePathsSorted.length === 0 ? "text-gray-300 cursor-not-allowed" : ""}`}
className={`flex items-center justify-between leading-5 ${
processedFilePathsSorted.length === 0
? "text-gray-300 cursor-not-allowed"
: ""
}`}
>
Select All
<span className="text-xs pl-4 flex items-center justify-center pt-[1px]">
Ctrl+A
</span>
</button>
);
}
}
10 changes: 5 additions & 5 deletions app/components/WindowMenu/WindowMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import HelpMenu from "./ContextMenu/HelpMenu";
import { BorderOutlined, MinusOutlined, CloseOutlined } from "@ant-design/icons";
import { createStyles } from 'antd-style';

export const useStyles = createStyles(({ token, css }) => ({
export const useStyles = createStyles(({ css }) => ({
button: css`
background-color: ${token.colorPrimary};
background-color: #00b96b;
&:hover {
background-color: ${token.colorPrimaryHover};
color: ${token.colorPrimary};
background-color: #6cd9ac;
color: #00b96b;
}
color: white;
border: none;
height: 99%;
height: 98%;
padding: 2px 8px;
`,
}));
Expand Down
Loading

0 comments on commit b21253b

Please sign in to comment.