To build a PSDS progress tracker using React and TypeScript along with using other features like IndexedDB, Context API, reducer and custom hooks.
To build a PSDS progress tracker using React and TypeScript along with using other features like IndexedDB, Context API, reducer and custom hooks.
Data structure is a way by which data is stored and arranged in the disk space of the computer or memory storage, so that the data can be easily used and manipulated in the future. It provides an effective way of performing various operations related to data management.
With a sufficient understanding of data structures, we can make efficient use of the resources provided to us by the Operating System. Factors like application responsiveness depends largely on the way we utilize the underlying data structures, being implemented.
You will build this project using Typescript and the React library, yet a simple project which utilizes the Context API and reducer features of React.js, and uses browser realtime IndexedDB, that means the app will not have a physical database, rather it caches for the particular browser.
This project consists of the following stages:
A demo video for reference purpose is provided. Moreover, you can also visit the live application here.
indexedDB
. [Note: Refer to the documentation here to understand the concept of 'Firebase like functionality'.]custom hooks
, contexts
and reducer
.To build a PSDS progress tracker using React and TypeScript along with using other features like IndexedDB, Context API, reducer and custom hooks.
Data structure is a way by which data is stored and arranged in the disk space of the computer or memory storage, so that the data can be easily used and manipulated in the future. It provides an effective way of performing various operations related to data management.
With a sufficient understanding of data structures, we can make efficient use of the resources provided to us by the Operating System. Factors like application responsiveness depends largely on the way we utilize the underlying data structures, being implemented.
You will build this project using Typescript and the React library, yet a simple project which utilizes the Context API and reducer features of React.js, and uses browser realtime IndexedDB, that means the app will not have a physical database, rather it caches for the particular browser.
This project consists of the following stages:
A demo video for reference purpose is provided. Moreover, you can also visit the live application here.
indexedDB
. [Note: Refer to the documentation here to understand the concept of 'Firebase like functionality'.]custom hooks
, contexts
and reducer
.Before the process of development starts, we need to setup the proper development environment which is the requisite of the application we're aiming to build.
typescript
as the template.testing
, logo
, setup
, etc., since, probably, you will not be needing them.LocalBase
module, since we'll be using IndexedDB features in our application.On completion of this task, you should be able to setup a React application. The application should give a similar result as shown in the screenshot below when visited at http://localhost:3000.
To begin with, we have the question details in an excel sheet. We need to be able to store the same details in JSON
format in the IndexedDB.
JSON
.JSON
out of it, now try to implement a specific TypeScript Interface. The properties you'll adhere to are - topicName
, questions
, isStarted
, doneQuestions
. It is important to use the syntactical contract that an entity should conform to. [NOTE: The interface we're referring to here is for the topic card for each topic, like Array, Matrix, etc. topicName
refers to the name of the topic. questions
is an integer that keeps the count of questions for a particular topicName
. isStarted
is a boolean which contains the status of a particular topicName
. doneQuestions
is an integer that keeps the count of completed questions.][NOTE: You may not see the left part of the page as shown here since you have not yet implemented that at this stage. The right part is what you should only see.]
Setup the LocalBase instance and seed the data to the browser's IndexedDB.
Make your own custom database functions like - insertData()
, getData()
, findDocByKey(param)
, and updateData(param)
etc. Making these basic indeed database functionalities makes your life easier to work and focus on writing react and business logics
.
On visiting http://localhost:3000 and going to the console section of the developer tools in Chrome, you should be able to notice the seeded data logs of localbase
. [NOTE: This data is seeded only once, hence the logs will be visible only once. After the seeding, the data is cached on your local machine.]
useContext
is of course the React Hook way to consume React Context. It's a way to share data to any descendent component without having to manually pass the props through every intermediary component. Sometimes known as prop drilling.
This stage will be the building blocks of your whole reactive state to control efficiently to avoid prop drilling issue. Context provides a way to pass data through the component tree without having to pass props down manually at every level.
Try to figure out what initial state
you need to get started and create using React.createContext()
hooks.
For a better understanding, you are free to refer to this IContext interface.
interface IContext {
questionData: IQuestionData[];
updateData: Function;
singleQuestionData?: IQuestionData;
}
App.tsx
file with <QuestionDataContext.Provider
> and provide initialState
as value
to it. A sample screenshot of contextAPI
logs is given for reference.Refer to the following points to gain clarity on the above console log:
questionData
, updatedData()
, and a bound dispatch action
is also needed for managing the context in the whole app. However the dispatcher will not be required at the moment.contextAPI
loads properly and error free, check the console from the developer tools of Chrome. Check if provider context provides the complex-states
to the deeper of the components
.Go to your browser and open http://localhost:3000 and go to console
in developer tools of Chrome and you'll see an output similar to the above picture.
Well, according to React, Hooks are functions that let you “hook into” React state and life cycle features from functional components.
Before the arrival of Hooks, state and React life cycles could only be used in a class component. Starting from version 16.8, React rolled out a lot of features that enables developers to hook into a React state without having to write a single class component.
Coming this far, building your own context
, you really made to 60% of the logic behind the application. To make use of that context, we need to utilize something called hooks, provided by the React library.
useState<any>()
and useEffect<any>()
hooks.data/state
changes?You should be able to create custom hooks which can simply fetch and update the question details in the IndexedDB. Moreover, you should also have a custom hook having helper functions which will be able to manipulate the states.
Here, you will be introduced with TailwindCSS, a utility first CSS Framework. Nowadays Cards with FlexLayout is very much accepted by users.
[NOTE: TailwindCSS has been taken as a preference for building this application. You are free to use other constructs.]
Refer to the Prototyped UI below and create your UI similar to this.
[NOTE: You are free to work on your own design.]
react-router-dom
should now come in handy. Figure out how you'll make use of it to achieve a nice UX.If you've referred to the above image for the design, then your app's frontend might look similar. Otherwise, you're free to go creative.
In this section, you'll be implementing the question module page.
Here you'll be working on a type of tabular structure with Mark As Done
functionality.
Now at this stage, you have to build something similar like the above picture, with a relevant title, search bar, and tabular view for the questions.
The search bar input takes phrases and searches from Database / context state
and populates the tabular view with relevant found questions. Use higher order function like
arr.filter((param)=>[...found(questions)])
Build the tabular structure using higher order array methods of ES7, like map()
.
Mark As Done / Undone feature in the component, by using updateData()
function.
To initialize and use context state use React.useContext(state)
in the corresponding components.
Reducer
to learn more advanced concepts of React.DarkTheme
toggle bar?You should have a finished application, similar to 450-DSA-Tracker.netlify.app.