Skip to main content

Home


This components represents the landing page of the app that appears after the inital load time.

State variables


This component utilizes the useState() hook and defines the following state variables :

State VariableValuesDescription
isOpenBooleanWhether the block is clicked or not
clickedDateStringStores the date of the clicked block
data[]An array containing all the objects with the date matching to the date of clicked block
transactionsCountNumberNumber of transactions on that day
tooltipViewBooleanWhether block is hovered or not
isLoadingBooleanWhether the initial loading time is over
yearlyDebitNumberStores the year-round debit amount
yearlyCreditNumberStores the year-round credit amount
dateTransactionsNumberA 53*7 2D array storing the number of transactions made on that day
dateBlocksNumberA 53*7 2D array storing the date of the block
hueNumberA 53*7 2D array used as h value in hsl() coloring
saturationNumberA 53*7 2D array used as s value in hsl() coloring
lightnessNumberA 53*7 2D array used as l value in hsl() coloring

For handling the date and time based calculations and I have used Moment.js

Inside the useEffect hook


First the useEffect() hook runs during the initial page load and runs the following functions asynchronously to set the corresponding dates,number of transactions and color intensity to each block :

FunctionDescription
setDateWiseTransactions()Sets number of transactions corresponding to each date
setDates()Sets corresponding dates of each block
setColor()Sets hsl() values of each block
calcTotalSpending()Calculate the total debit and credit in last year

calcTotalSpending()


This function calculates the total debit amount and total credit amount of all the transactions made in the past 1 year and store the values in the yearlyDebit and yearlyCredit state variables respectively.

const calcTotalSpending = async () => {
let sumDebit=0,sumCredit=0;
for(let i=0;i<transactions.length;i++){
if(transactions[i].type==="debit") sumDebit+=transactions[i].amount;
else sumCredit+=transactions[i].amount;
}
return [ setYearlyDebit(sumDebit),setYearlyCredit(sumCredit) ];
}