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

Add filter to homepage #37

Merged
merged 4 commits into from
Jun 28, 2021
Merged

Add filter to homepage #37

merged 4 commits into from
Jun 28, 2021

Conversation

gaoxk
Copy link
Contributor

@gaoxk gaoxk commented Jun 24, 2021

Notion ticket link

add filter

ezgif com-gif-maker

Implementation description

  • added approved_languages to user context
  • added filter component
  • hooked up state + user context in Homepage with Filter

note:

  • renamed story folder to homepage
  • the home page will break for users with no approved languages set

Steps to test

  1. Insert a user with approved languages '{"HINDI":3, "FRENCH":2, "BENGALI":4}'. make a second user, but log in as the first user.
  2. insert some NGO friendly stories
INSERT INTO stories (title, description, youtube_link, level, translated_languages) VALUES ('Goodnight, Tinku!', 'Tinku, a little pup at Mangu\'s farm is not sleepy at all. He decides to step out into the night and meets many interesting animals.', 'https://www.youtube.com/watch?v=evHY-2oSokY', 2, '{"HINDI", "FRENCH"}');
INSERT INTO stories (title, description, youtube_link, level, translated_languages) VALUES ('The Flying Elephant', 'Find out how a flying elephant changes the life of a poor farmer.', 'https://www.youtube.com/watch?v=hh_4Axs3ZVQ', 4, '{"BENGALI"}');
INSERT INTO stories (title, description, youtube_link, level, translated_languages) VALUES ('The Lion and the Fox', 'The smart lion thinks he can use the fox to bring him food every day. But the fox is smarter.', 'https://www.youtube.com/watch?v=pFDXCXVvtRo', 3, '{"BENGALI"}');
INSERT INTO stories (title, description, youtube_link, level, translated_languages) VALUES ('A Book for Puchku', 'Puchku has run out of books to read. Then she discovers more books in the top shelf of the library bookcase. But Puchku is small, and the bookcase tall. How will she ever get to her beloved books?', 'https://www.youtube.com/watch?v=PKxMjO4HPvE', 3, '{}');
  1. Insert the translations
INSERT INTO story_translations (story_id, language, stage, translator_id) VALUES (1, 'HINDI', 'TRANSLATE', 1);
INSERT INTO story_translations (story_id, language, stage, translator_id) VALUES (1, 'FRENCH', 'TRANSLATE', 1);
INSERT INTO story_translations (story_id, language, stage, translator_id) VALUES (1, 'BENGALI', 'TRANSLATE', 2);
INSERT INTO story_translations (story_id, language, stage, translator_id) VALUES (2, 'BENGALI', 'TRANSLATE', 1);
INSERT INTO story_translations (story_id, language, stage, translator_id) VALUES (3, 'BENGALI', 'TRANSLATE', 1);
INSERT INTO story_translations (story_id, language, stage, translator_id) VALUES (3, 'HINDI', 'TRANSLATE', 2);

TODO: grey out filter on viewing my work

Checklist

  • My PR name is descriptive and in imperative tense
  • My commit messages are descriptive and in imperative tense. My commits are atomic and trivial commits are squashed or fixup'd into non-trivial commits
  • For backend changes, I have run the appropriate linters: docker exec -it <backend-container-id> /bin/bash -c "black . && isort --profile black ."

Copy link
Collaborator

@jennchenn jennchenn left a comment

Choose a reason for hiding this comment

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

the filter seems to be working properly! just a couple of questions about some things

flex-direction: column;
height: 500px;
justify-content: space-between;
min-width: 350px;
Copy link
Collaborator

Choose a reason for hiding this comment

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

did we want the css properties to be alphabetized?

if (displayMyStories) {
return storyTranslationId ? "review book" : "translate book";
}
return "view translation";
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the user presses a button with view translation should that also try to assign them as either a reviewer/translator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. I think some of our existing logic is flawed here.
If the user is browsing stories/translations, the call-to-action-button (primary button) should assign them as translator/reviewer.
If the user is looking at story translations they are already translators/reviewers of, the call-to-action-button (primary button) should open the translation platform.

logic is now changed to reflect this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

when we toggle for role "For translation", should only the "translate book" button show up? or can the "review book" button show up as well?
right now when i'm toggled to For Translation i see only the review book button, but when i toggle to For Review i see nothing (could also be my test data so i'll keep testing but wanted to clarify)

onToggle={setRole}
/>
</div>
<div id="filter-level">
Copy link
Collaborator

Choose a reason for hiding this comment

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

my level slider doesn't seem to align properly with the levels--is this an issue with my laptop?
image

also quick q i think i'm having some trouble navigating the figma hahah is there an updated wireframe where the levels are a slider instead of pill buttons?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made a change, hows it look now?

slider doesnt have a figma design right now - Russel and I discussed using sliders over buttons on slack. Currently the slider's styling is default html/css.

Copy link
Collaborator

Choose a reason for hiding this comment

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

still doesn't seem to match up properly for me
image

i'm not sure if my laptop's aspect ratio is just weird though?

@@ -134,16 +144,16 @@ const StoryCard = ({
<p className="story-card-title">{title}</p>
<div className="story-card-tags">
{/* TODO: make tags that reflect actual state */}
<Tag displayText={`level ${level}`} />
<Tag displayText="language needed" />
<Tag displayText={`Level ${level}`} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

did design have any preference for capitalization?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. Will double-check with them.

Copy link
Collaborator

@e-wai e-wai left a comment

Choose a reason for hiding this comment

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

Some visual questions
image
image

  • The width is awkward on my laptop, so it probably looks awkward for others as well
  • Can we change "Filter Stories" so it looks more like a title? The categories are caps and the title is lowercase, with very similar sizes. I almost expect there to be another filter setting underneath Filter stories
  • Role toggle button looks weird. Probably some CSS fun to sort out

One more thought - what components within the HomePage directory are re-usable? Looking at the parts there, I don't think the primary/secondary buttons are necessarily homepage-specific. Along with the toggle button, they might deserve their own components folder

<div className="filter">
<h1>Filter Stories</h1>
<div>
<h4>TRANSLATION LANGUAGE</h4>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we establish some standards around what font sizes/styles correspond to h1 and h4?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

role,
setRole,
}: FilterProps) => {
// language state in Homepage can't default to user context value
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why can't homepage handle the default logic?

Copy link
Contributor Author

@gaoxk gaoxk Jun 26, 2021

Choose a reason for hiding this comment

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

🤔 i think i was hallucinating or something. Works now, logic moved to homepage

}: FilterProps) => {
// language state in Homepage can't default to user context value
// set the default language from user approvedLanguages here
if (!Object.keys(approvedLanguages).includes(language)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does !(language in approvedLanguages) not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(code is outdated now) but yee that works too!

@@ -58,6 +59,7 @@ const StoryCard = ({
youtubeLink,
level,
language,
displayMyStories,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: is there another name that we could use? displayMyStories feels like a homepage-level logic concept, that seems distinct from what the storyCard component should know

  • maybe isAssignedToUser, storyInProgress?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think of isMyStory?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, don't mind that at all

level: number,
userId: number,
): QueryInformation => {
let result = {};

if (role === Role.Translator && !displayMyStories) {
if (isTranslator && !displayMyStories) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

ooh nice this is so much prettier, thank you!!

@gaoxk
Copy link
Contributor Author

gaoxk commented Jun 26, 2021

@e-wai reverted toggle button css changes, lmk how it looks.

Regarding reusability - yeah, a ton of homepage files are reusable. In a separate PR I want to split off a lot of stuff into a utils/ folder. This will also be necessary for design-system-y-stuff (eg consistent Titles and Subtitles)

Regarding Filter title: I'll keep it as it is for now as its inline with figma designs, but this is good feedback for design that we can discuss at Sundays meeting.

</div>
<div>
<h4>ROLE</h4>
<ToggleButton
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure if this is relevant to the comment Emma made about the css for the Role button but when i view the site on my laptop instead of monitor i see this (could also just be my laptop being weird sorry):
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

LOL mine's also not having it, but in a different way

image

@e-wai
Copy link
Collaborator

e-wai commented Jun 27, 2021

Also comment for general interest - the escape character for apostrophe was double single quote for me ('') not the slash (\')

INSERT INTO stories (title, description, youtube_link, level, translated_languages) VALUES ('Goodnight, Tinku!', 'Tinku, a little pup at Mangu''s farm is not sleepy at all. He decides to step out into the night and meets many interesting animals.', 'https://www.youtube.com/watch?v=evHY-2oSokY', 2, '{"HINDI", "FRENCH"}');

@e-wai
Copy link
Collaborator

e-wai commented Jun 27, 2021

Maybe it's worth putting homepage CSS troubleshooting into its own ticket? With stories, my right top corner looks like attached image. Have to scroll sideways to see it though
image

@gaoxk
Copy link
Contributor Author

gaoxk commented Jun 27, 2021

Toggle & header/story card css alignment issues should be good now.

Copy link
Collaborator

@e-wai e-wai left a comment

Choose a reason for hiding this comment

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

Toggle button all nice and pretty now! @gaoxk created an issue for CSS troubleshooting homepage 🚀

Everything else looks good to me 🎉

role + displayMyStory + button text
combo was incorrect. button text
logic was backwards.
Copy link
Collaborator

@jennchenn jennchenn left a comment

Choose a reason for hiding this comment

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

looks good!

@gaoxk gaoxk merged commit 930e1f9 into main Jun 28, 2021
@gaoxk gaoxk mentioned this pull request Aug 1, 2021
4 tasks
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.

3 participants