Skip to content

Commit

Permalink
Fix: アンテナ絞り込み条件設定画面のタブが切り替えられない問題 (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode authored Nov 29, 2024
1 parent 8d94a8d commit 69f679e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/javascript/mastodon/features/antennas/filtering.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,15 @@ const TextList: React.FC<{
};

const RadioPanel: React.FC<{
antennaId: string;
items: { title: string; value: string }[];
valueLengths: number[];
alertMessage: React.ReactElement;
onChange: (value: string) => void;
}> = ({ items, valueLengths, alertMessage, onChange }) => {
}> = ({ antennaId, items, valueLengths, alertMessage, onChange }) => {
const [error, setError] = useState(false);
const [value, setValue] = useState('');
const [lastAntennaId, setLastAntennaId] = useState('');

useEffect(() => {
if (valueLengths.length >= 2) {
Expand All @@ -203,7 +205,11 @@ const RadioPanel: React.FC<{
}, [valueLengths]);

useEffect(() => {
if (items.length > 0) {
if (
items.length > 0 &&
valueLengths.length === items.length &&
antennaId !== lastAntennaId
) {
for (let i = 0; i < valueLengths.length; i++) {
const length = valueLengths[i] ?? 0;
const item = items[i] ?? { value: '' };
Expand All @@ -215,17 +221,20 @@ const RadioPanel: React.FC<{
}
setValue(items[0]?.value ?? '');
}
}, [items, valueLengths, setValue, onChange]);
}, [antennaId, lastAntennaId, items, valueLengths, setValue, onChange]);

const handleChange = useCallback(
({ currentTarget }: React.MouseEvent<HTMLButtonElement>) => {
const selected = currentTarget.getAttribute('data-value') ?? '';
if (value !== selected) {
onChange(selected);
setValue(selected);

// Set the flag for the first manual tab change.
setLastAntennaId(antennaId);
}
},
[value, setValue, onChange],
[value, setValue, onChange, setLastAntennaId, antennaId],
);

return (
Expand Down Expand Up @@ -585,6 +594,7 @@ const AntennaSetting: React.FC<{

<div className='scrollable antenna-setting'>
<RadioPanel
antennaId={id}
items={rangeRadioItems}
valueLengths={rangeRadioLengths}
alertMessage={
Expand Down Expand Up @@ -617,6 +627,7 @@ const AntennaSetting: React.FC<{
)}

<RadioPanel
antennaId={id}
items={contentRadioItems}
valueLengths={contentRadioLengths}
alertMessage={
Expand Down

0 comments on commit 69f679e

Please sign in to comment.