## Trip Planner Sprint 1 ![](https://i.imgur.com/vXkca8X.jpg) --- ## Team Roles QA - Milly DevOps - Orian Scrum & UX / UI - Paolo --- ### How did we split the work? 🐮 * Split work evenly, working on the hardest issues together and separating to maximise our velocity * Prioritised issues to deliver an MVP * Daily Stand-up with questions --- ![](https://i.imgur.com/CucVDku.png) Estimate 24 points ![](https://i.imgur.com/4sSNHFH.png) 23 Actual poins --- ## Index DB & localForage ![](https://i.imgur.com/lDNsXIm.png) --- #### IndexedDB API * Asynchronously store significant amount of data client-side * object as key value pairs ![](https://i.imgur.com/ig9R7Ha.png) --- #### localForage - A JavaScript library to store and retrieve data asynchronously from IndexedDB - Simplifies using IndexedDB - Uses localStorage if your browser doesn't support IndexedDB --- [IndexedDB API](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) [localForage API Documentation](https://localforage.github.io/localForage/) [localForage GitHub Repo](https://github.com/localForage/localForage) --- ## Pdf Js - PDF Viewer A library that provides a React component to visualise PDF files ![](https://i.imgur.com/jvg3CnI.gif) --- `npm install pdfjs-dist@2.13.216` ![](https://i.imgur.com/x3LxcAn.png) ![](https://i.imgur.com/dDuuF2S.png) --- [React PDF Viewer Documentation](https://react-pdf-viewer.dev/docs/basic-usage/) --- ## Styled Components ![](https://i.imgur.com/1FDoOI5.png) --- Global Variables using the CreateGlobalStyle module ![](https://i.imgur.com/BAbb3aV.png) --- #### Styling a pre-existing component ![](https://i.imgur.com/WYED8j2.png) --- #### Fragments Avoid rendering an extra `<div>` ![](https://i.imgur.com/5Wm7ORb.png) ![](https://i.imgur.com/uB4xw2W.png) ![](https://i.imgur.com/qUyXaWD.png) --- ## React Router - We wanted a simple, intuitive routing system and the ability to create dynamic url paths like in Next.js - We found that we could achieve this with React Router! --- Some of React Router's components ![](https://i.imgur.com/XFzxcX1.png) --- Set up Routes, static and dynamic paths ![](https://i.imgur.com/8lL1GKL.png) --- `Link` to a dynamic path ![](https://i.imgur.com/BfwXHgp.png) --- Access params in in the current Route path! `useParams` is a React Router hook that returns an object of key/value pairs of URL parameters ![](https://i.imgur.com/IUNt2Ag.png) --- ## React custom hooks - One of our main challanges this week was keeping react state synced with our database - We (finally) achieved this with a React custom hook that returns functions that handle both updating the db and the state in one function (whether it's adding / deleting entries) --- ### React cutom hook example - A JavaScript function whose name conventionally starts with ”use” and that may call other React Hooks. - Extracts component logic into reusable functions --- `useToggle.js` ![](https://i.imgur.com/TzRAFZO.png) --- `Toggler.jsx` ![](https://i.imgur.com/2ZXc4pL.png) --- ## React errors we ran into... There were many. Mostly this one :point_down: ![](https://i.imgur.com/rvhZgan.png) --- Potential reasons for this error: 1. Rendering an object (e.g. a JavaScript Date) directly without specifying an object's key (i.e `doc.name`) - React can only render primitive values directly. 2. Rendering an array without using a .map() 3. Calling a function that returns an object or other invalid child (`new Date` returns a date object) --- ![](https://i.imgur.com/MIPPcLm.png) A bit dramatic, don't you think? --- - We were trying to get a document from the db (async) and set the state to that document url so that we could display it. - Only problem is that the componenet `Docs`, where the setState function is called when a user clicks on the document link, then redirects to a new component - `SingleDoc`. Meaning it dismounts (goes bye bye) while trying to do an async operation to update state. --- - Articles online suggested seeveral ways to deal with this: one being moving setState calls up in the component heirarchy --- - For us, it was enough to just make use of handy `useParams` to retrieve the key of the doc, get it from the db and then display it - managing the state of the doc all in the `SingleDoc` component --- ### React Lesson of the week :point_up: - Always, always do a logical check to avoid React trying to render a variable that has an initial state of null (or other falsey value) ![](https://i.imgur.com/Vljp2TP.png) --- ## Jest :black_joker: - Using Jest for testing React requires a folder named `__tests__` and inside you can have your test files `test.js` with `import renderer from 'react-test-renderer'` that you need to npm install --- ### [Snapshot testing](https://jestjs.io/docs/snapshot-testing) ![](https://i.imgur.com/lMfRUbh.png) ![](https://i.imgur.com/XArtITQ.png) --- - Jest compares the rendered output with the previous snapshot. If they match, the test will pass --- This is an example Jest test to check the home page renders ![](https://i.imgur.com/SBh2UBk.png) I wrote some tests in Cypress after having ESLint errors with Jest because we are mostly using jsx files and I was getting compatibility errors. This may be fixed by adding `"lint" : eslint --ext js, jsx --fix"` to the scripts of the package.json --- ## useNavigate() - React Router v6 has a new method for navigating back and forth between pages with the useNavigate() method which enhances the user experience by easily clicking between pages like so :point_down: ![](https://i.imgur.com/pn8GSd4.png) --- ## What we're proud of - We made our MVP during Sprint 1 :sparkles: :confetti_ball: - Smashing those issues :100: - Trying new things :shocked_face_with_exploding_head: --- ## [Demo](https://trip-planner-five.vercel.app/) :palm_tree: ---
{"metaMigratedAt":"2023-06-16T20:42:08.760Z","metaMigratedFrom":"Content","title":"Untitled","breaks":true,"contributors":"[{\"id\":\"9e5170a0-78d4-4b78-8fba-f500bdd88450\",\"add\":2016,\"del\":246},{\"id\":\"ae3532b1-4610-4f25-89ec-b00c8da7a54b\",\"add\":1713,\"del\":247},{\"id\":\"3934dd6c-8588-4d47-a23b-ba8c96da8ea7\",\"add\":2754,\"del\":39}]"}
    218 views
   Owned this note