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

Adds ability to join existing shopping list #21

Merged
merged 6 commits into from
Apr 23, 2023
Merged

Conversation

jeremiahfallin
Copy link
Collaborator

@jeremiahfallin jeremiahfallin commented Apr 18, 2023

Description

This PR adds a form to allow users to enter an existing list token so they can join an existing list whilst giving feedback if they entered an invalid list token.

It also changes our routing to adopt createBrowserRouter and createRoutesFromElements so that we can use the loader action which is not compatible with the original BrowserRouter to remove flickering when redirecting. The code also adds a redirect to prevent users with tokens to access to home view.

Related Issue

Closes #5

Acceptance Criteria

If a user doesn’t already have a token:

  • The Home view shows a form that allows the user to enter a token to join an existing list, in addition to the button that allows them to create a new list.
  • The input that accepts the list token has a semantic label element associated with its
  • The user can submit this form with both the mouse and the Enter key
  • If the list exists, the token is saved in localStorage
    the user is redirected to the List view and shown the items on that list
  • If the list does not exist, the user is shown an error message that explains the problem

If a user does already have a token:

  • They are automatically redirected to the List view.
  • If the user does not have a token and they try to navigate to the list or add item views they are redirected to the welcome page.

Type of Changes

Type
🐛 Bug fix
✨ New feature

Updates

Before

image

After

image

Testing Steps / QA Criteria

In your terminal, use git checkout -b jf-yj-join-shopping-list to create a new branch and switch over.
Use git pull origin jf-yj-join-shopping-list to bring the changes from remote to local.
npm start to start a local instance of our app.
Remove tcl-shopping-list-token from local storage prior to testing.

  • On the home page, clicking on 'Join an existing list' should focus the input.
  • Type in an existing token such as 'my test list' in the input field and click Join. This should also work with the enter key.
  • This should bring you to the list view and prepopulate any items from that list.
  • You should be able to travel to the add items page, but not the home page (there should be no flicker on redirect). Upon entering the app with a token, you should be redirected to the list view.
  • If you input a invalid token (i.e. a 2 word token )or a token that doesn't exist, then a error message, List not found. Please try another token., should display below the join button that will clearly automatically after a delay.

@jeremiahfallin jeremiahfallin changed the title Add ability to join existing shopping list Adds ability to join existing shopping list Apr 18, 2023
@github-actions
Copy link

github-actions bot commented Apr 18, 2023

Visit the preview URL for this PR (updated for commit d8c024b):

https://tcl-55-smart-shopping-list--pr21-jf-yj-join-shopping-rnplqx79.web.app

(expires Sat, 29 Apr 2023 16:18:01 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 607d14028385ebfcc7c9ec69a7bb14d95ed54078

@Yaosaur Yaosaur marked this pull request as ready for review April 20, 2023 11:29
Copy link
Collaborator

@ticiadev ticiadev left a comment

Choose a reason for hiding this comment

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

Code looks good and everything works as expected!

Just wondering though, are Firebase tokens meant to be case-sensitive? It looks like they're all lowercase so far, and the input only allows for tokens entered with matching case. Should users be able to enter their token, e.g. "My Test List" and still have that accepted?

Copy link
Collaborator

@katherineyuneman katherineyuneman left a comment

Choose a reason for hiding this comment

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

Everything looks great and is functioning as intended!

@ticiadev made a good point about the case sensitivity. All of the random words that are generated through the npm package are lowercase (see https://www.npmjs.com/package/@the-collab-lab/shopping-list-utils?activeTab=code ). That said, the user story doesn't address if the Join Existing List should be case sensitive as it is now. Maybe we can discuss Sunday and add to a future story depending on what we decide?

<Route path="/" element={<Layout />}>
<Route
index
loader={() => listToken && redirect('/list')}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great solution and works really well!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good work! 🚀

const [message, setMessage] = useState('');

useEffect(() => {
const timer = setTimeout(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like that the error message timeout is consistent across the app now. I think we should try to remember this going forward for other user issues as well.

const handleChange = (e) => setUserEnteredToken(e.target.value);
const handleFormSubmit = (e) => {
e.preventDefault();
streamListItems(userEnteredToken, (snapshot) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be a good idea here to check if there's no token and display an appropriate message.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Resolved! Nice catch!

}}
>
<label htmlFor="join-list">Join an existing list</label>
<input
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice use of semantics here

Copy link
Collaborator

@mentalcaries mentalcaries left a comment

Choose a reason for hiding this comment

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

So far, so good! The flicker on redirect is gone!

Copy link
Collaborator

@lyleschemmerling lyleschemmerling left a comment

Choose a reason for hiding this comment

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

great work!

Copy link
Collaborator

@5hraddha 5hraddha left a comment

Choose a reason for hiding this comment

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

Good job @jeremiahfallin and @Yaosaur 🚀

@Yaosaur Yaosaur merged commit 2a2521e into main Apr 23, 2023
2 checks passed
@Yaosaur Yaosaur deleted the jf-yj-join-shopping-list branch April 23, 2023 19:44
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.

5. As a user, I want to join an existing shopping list so I can share a shopping list with another person
7 participants