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

Create LargeList, LargeListItem components #793

Closed
wants to merge 4 commits into from

Conversation

BrianSantoso
Copy link
Contributor

Revised requested changes from #785
LargeList/LargeListItem is the selectable list of gray, rectangular, containers underneath "Select your post type".
image

Comment on lines +1 to +5
import React, { ReactChildren, useState } from "react";
import { StyleSheet, css } from "aphrodite";

// Components
import LargeListItem from "~/components/Form/LargeListItem";
Copy link
Contributor

Choose a reason for hiding this comment

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

Going forward, let's do away with this type of import styling. No one is really interested in what's imported unless they find some bug. In which case, they wouldn't care about the style of import anyways. Just make sure to alphabetize. (I think there's a VS-code ways to alphbetize. On MacOS, it's Fn + F9)

Suggested change
import React, { ReactChildren, useState } from "react";
import { StyleSheet, css } from "aphrodite";
// Components
import LargeListItem from "~/components/Form/LargeListItem";
import React, { ReactChildren, useState } from "react";
import { StyleSheet, css } from "aphrodite";
import LargeListItem from "~/components/Form/LargeListItem";

Comment on lines +8 to +12
selectMany: boolean;
useLargeHitbox: boolean;
customListStyle: StyleSheet;
onChange?: Function;
children: ReactChildren;
Copy link
Contributor

Choose a reason for hiding this comment

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

abc

useLargeHitbox,
customListStyle,
onChange,
children,
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for children. Let's just passdown an array of item. Better alternative would be just passdown prop-objects to List & list formats items accordingly. But either way works.
I would like to avoid playing around with children like you are doing below since children could be anything.

Suggested change
children,
items: Array<ReactElement<typeof LargeListItemProps>>,

onChange,
children,
}: LargeListProps) {
let [isActives, setIsActives] = useState(children.map(() => false));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let [isActives, setIsActives] = useState(children.map(() => false));
const [activeIndices, setActiveIndicies] = useState<Array<ids>>([]);

<LargeListItem
checkboxSquare={selectMany}
useLargeHitbox={useLargeHitbox}
isActive={isActives[index]}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
isActive={isActives[index]}
isActive={activeIndices.includes([index])}

Comment on lines +33 to +41
let changed;
if (selectMany) {
changed = [...isActives]; // Do not modify other boxes
} else {
changed = isActives.map(() => false); // Set all other boxes to false
}
changed[index] = value;
setIsActives(changed);
onChange && onChange({ isActives, index, value, id }); // Send information about the state change
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's think about how we can refactor this based on the suggestions I've given above

);
};

const wrappedChildren = children.map(renderListItem);
Copy link
Contributor

Choose a reason for hiding this comment

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

probably dont need this with suggestions

@lightninglu10 lightninglu10 deleted the large-list-component branch December 9, 2021 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants