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

WRQ-32437: Fixed deletion of favorite colors for ColorPicker #1676

Merged
merged 9 commits into from
Aug 26, 2024
43 changes: 39 additions & 4 deletions ColorPickerPOC/ColorPickerPOC.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import {generateOppositeColor} from './utils';

import componentsCss from './ColorPickerPOC.module.less';
import Spotlight, {getDirection} from "../../enact/packages/spotlight";
daniel-stoian-lgp marked this conversation as resolved.
Show resolved Hide resolved

const SpottableButton = Spottable(ButtonBase);

Expand Down Expand Up @@ -90,6 +91,35 @@
}, 100);
}, []);

const handleKeyDown = useCallback((ev) => {

Check warning on line 94 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L94

Added line #L94 was not covered by tests
stanca-pop-lgp marked this conversation as resolved.
Show resolved Hide resolved
if(ev.keyCode === 13) {
const target = ev.target.id ? ev.target : ev.target.offsetParent;

shakeEffectRef.current = setTimeout(() => {
target.classList.add(componentsCss.shakeFavoriteColor);

Check warning on line 99 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L98-L99

Added lines #L98 - L99 were not covered by tests
}, 300);

timerRef.current = setTimeout(() => {
setEditEnabled(true);
setClickEnabled(false);
target.classList.remove(componentsCss.shakeFavoriteColor);

Check warning on line 105 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L102-L105

Added lines #L102 - L105 were not covered by tests
}, 1000);
}
}, [editEnabled]);

const handleKeyUp = useCallback((ev) => {

Check warning on line 110 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L110

Added line #L110 was not covered by tests
if(ev.keyCode === 13) {
const target = ev.target.id ? ev.target : ev.target.offsetParent;
target.classList.remove(componentsCss.shakeFavoriteColor);

Check warning on line 113 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L113

Added line #L113 was not covered by tests

clearTimeout(shakeEffectRef.current);
clearTimeout(timerRef.current);
setTimeout(() => {
setClickEnabled(true);

Check warning on line 118 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L115-L118

Added lines #L115 - L118 were not covered by tests
}, 100);
}
}, []);

return (
<div>
<Row className={componentsCss.favoriteColorsRow}>
Expand All @@ -102,8 +132,8 @@
key={`${color}_${index + 4}`}
minWidth={false}
onClick={onSelectFavoriteColor}
onMouseDown={onPressHandler}
onMouseUp={onReleaseHandler}
onKeyDown={handleKeyDown}
onKeyUp={handleKeyUp}
onPointerDown={onPressHandler}
onPointerUp={onReleaseHandler}
size="small"
Expand All @@ -127,8 +157,8 @@
key={`${color}_${index}`}
minWidth={false}
onClick={onSelectFavoriteColor}
onMouseDown={onPressHandler}
onMouseUp={onReleaseHandler}
onKeyDown={handleKeyDown}
onKeyUp={handleKeyUp}
onPointerDown={onPressHandler}
onPointerUp={onReleaseHandler}
size="small"
Expand Down Expand Up @@ -177,6 +207,11 @@
const [favoriteColors, setFavoriteColors] = useState(colors);
const [selectedColor, setSelectedColor] = useState(color);

useEffect(() => {
setFavoriteColors(colors);
setSelectedColor(color);

Check warning on line 212 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L210-L212

Added lines #L210 - L212 were not covered by tests
}, [color, colors]);

useEffect(() => {
if (selectedColor || favoriteColors) {
onChangeColor({selectedColor, favoriteColors});
Expand Down
1 change: 1 addition & 0 deletions ColorPickerPOC/ColorPickerSlider.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
justify-content: center;
align-items: center;
background-color: #eeeeee;
color: rgb(76, 80, 89);
border-radius: 12px;
margin-left: 30px;
}
Expand Down