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

Feature/analytics #20

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open

Feature/analytics #20

wants to merge 10 commits into from

Conversation

victorlucss
Copy link
Owner

Screen.Recording.2023-11-21.at.21.28.16.mov

@victorlucss victorlucss self-assigned this Nov 22, 2023
Copy link

vercel bot commented Nov 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tonovermelho ❌ Failed (Inspect) Nov 24, 2023 7:44pm

const data = useMemo(() => {
const billsReduce = bills.reduce((prev, curr) => {
const dueDate = new Date(curr.dueDate);
const month = `${dueDate.getMonth() + 1}/${dueDate.getFullYear()}`;
Copy link
Collaborator

@jefo3 jefo3 Mar 29, 2024

Choose a reason for hiding this comment

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

I would rename the variable name month to FormattedDueDate, as it doesn't actually represent the month, but rather the month/year of the due date

if (!prev[month]) {
prev[month] = {};

if (curr.type === BillTypes.EXPENSE) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

From what I understand, this first check is to see if there are already values ​​for that specific month/year, if not yet, I put the curr values ​​as default

If my understanding is right

This part is not necessary if you initialize the expense and income values ​​to 0

Because in the next if you check if curr.type === billTypes.EXPENSE and do a prev[month].expense += curr.value;

If not, do: prev[month].income += curr.value;

Thus, repeating the code

So if the values ​​are initialized with zero, the += operation will work correctly and for cases where the information in the month/year did not yet exist, it becomes the curr value, exactly what the first if does

Copy link
Collaborator

Choose a reason for hiding this comment

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

 if (!prev[month]) {
        prev[month] = {
          expense: 0,
          income: 0,
          month,
          rest: 0
        };
      }

Copy link
Collaborator

Choose a reason for hiding this comment

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

But thinking here,
the code checks if there is no value in that table/year, if not, it initializes

there depending on whether the value of curr.type === BillTypes.EXPENSE
it initializes the expense with the value of curr.value
Then, as the value has already been initialized, it checks whether there is a value for the month/year ( if (prev?.[month]) )

as the prev for this month/year was initialized previously, it does: prev[month].expense += curr.value;

so it's as if it did a curr.values ​​+ curr.values for cases where the prev didn't yet have a value for that month

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.

2 participants