Skip to content

Commit

Permalink
fix reordering in edit palette screen
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalkishor1991 committed Aug 18, 2024
1 parent 8385b10 commit 2f5767b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/PaletteCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const PaletteCard = (props) => {
/>
<MenuItemWrapper
onPress={() => {
navigation.navigate('Palette', { paletteId });
navigation.navigate('PaletteEdit', { paletteId });
}}
icon="edit"
label="Edit"
Expand Down
10 changes: 8 additions & 2 deletions screens/PaletteEditScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export default function PaletteScreen({ navigation, route }) {

const { height } = Dimensions.get('window');
const palette = allPalettes.find((palette) => palette.id === paletteId);
const colors = palette?.colors;
const [colors, setColors] = useState(palette?.colors);
useEffect(() => {
setColors(allPalettes.find((palette) => palette.id === paletteId)?.colors);
}, [allPalettes, paletteId]);
const onColorDelete = React.useCallback(
(hex) => {
deleteColorFromPalette(palette.id, palette.colors.find((c) => c.color === hex).id || null);
Expand Down Expand Up @@ -80,7 +83,7 @@ export default function PaletteScreen({ navigation, route }) {

const colorsToShow = React.useMemo(
() => colors?.slice(0, pro.plan != 'free' ? colors.length : 4),
[colors, pro.plan != 'starter']
[colors, pro.plan]
);

const handleColorSelected = (color) => {
Expand All @@ -97,6 +100,9 @@ export default function PaletteScreen({ navigation, route }) {
keyExtractor={keyExtractor}
style={styles.listview}
onDragEnd={({ data: reorderedColors }) => {
// Colors is update in local state first and then updated on the server and in global state.
// The whole state logic is little messed up now and need refactoring but for now this approach works.
setColors(reorderedColors);
updatePalette(palette.id, { ...palette, colors: reorderedColors });
}}
ListFooterComponent={ListFooterComponent}
Expand Down

0 comments on commit 2f5767b

Please sign in to comment.