Clicks and views #17

Merged
j285he merged 0 commits from feat/clicks-and-views into main 2 years ago
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner
  • Added and styled an Analytics component
  • Added hooks to get and post click and view counts in Analytics/index.tsx and Link/index.tsx
  • Added Linktree font (Karla) in tailwind.config.js

Things left to do:

  • Add endpoints to Analytics/index.tsx and Link/index.tsx and get data from the given object
  • Add onClick={handleClick} to the Links (resolved Mar. 22)
* Added and styled an `Analytics` component * Added hooks to get and post click and view counts in `Analytics/index.tsx` and `Link/index.tsx` * Added Linktree font (Karla) in `tailwind.config.js` Things left to do: * Add endpoints to `Analytics/index.tsx` and `Link/index.tsx` and get data from the given object * ~~Add `onClick={handleClick}` to the Links~~ (resolved Mar. 22)
q63xu (Migrated from git.uwaterloo.ca) approved these changes 2 years ago
q63xu commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

Let's add all the .vs/ files in the .gitignore so others don't have to pull this down

Let's add all the `.vs/` files in the `.gitignore` so others don't have to pull this down
q63xu commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

nit: Let's keep component names in TitleCase!

nit: Let's keep component names in TitleCase!
q63xu commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

Delete this, there isn't a package.json at the very root level

Delete this, there isn't a package.json at the very root level
q63xu commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

Always use const when declaring variables, unless you have to perform direct mutation (which is rare), then use let

Always use `const` when declaring variables, unless you have to perform direct mutation (which is rare), then use `let`
q63xu commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

Good job putting components in diff files, makes the main Analytics file cleaner!

Good job putting components in diff files, makes the main `Analytics` file cleaner!
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

The intention was to declare the viewCount and clickCount variables at the start of the component, and then mutate them in the fetch function inside the useEffect (getting the actual view/click count from the returned json). I can't seem to directly declare const variables in useEffect and then use them. Should I use let or is there another way around this? Thanks!

The intention was to declare the `viewCount` and `clickCount` variables at the start of the component, and then mutate them in the `fetch` function inside the `useEffect` (getting the actual view/click count from the returned json). I can't seem to directly declare `const` variables in `useEffect` and then use them. Should I use `let` or is there another way around this? Thanks!
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

changed this line in version 2 of the diff

changed this line in [version 2 of the diff](/csc/linktree/-/merge_requests/12/diffs?diff_id=51614&start_sha=f00ee4ed45de5a35af1242ae0233e67e4dfc74a6#ef34d826281576e3e7c9439d0c0f9796ef27eac7_1_0)
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

changed this line in version 2 of the diff

changed this line in [version 2 of the diff](/csc/linktree/-/merge_requests/12/diffs?diff_id=51614&start_sha=f00ee4ed45de5a35af1242ae0233e67e4dfc74a6#ba11c550e249da5a04c90d90736c8553d0a98435_3_3)
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

changed this line in version 2 of the diff

changed this line in [version 2 of the diff](/csc/linktree/-/merge_requests/12/diffs?diff_id=51614&start_sha=f00ee4ed45de5a35af1242ae0233e67e4dfc74a6#fa288d1472d29beccb489a676f68739ad365fc47_1_0)
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

added 1 commit

  • 5b2337a0 - Remove/ignore unnecessary files, rename components

Compare with previous version

added 1 commit <ul><li>5b2337a0 - Remove/ignore unnecessary files, rename components</li></ul> [Compare with previous version](/csc/linktree/-/merge_requests/12/diffs?diff_id=51614&start_sha=f00ee4ed45de5a35af1242ae0233e67e4dfc74a6)
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

added 3 commits

  • ab544fc7 - 1 commit from branch main
  • 457aa949 - Resolve merge conflicts with new Links component
  • 72c435fe - Add Karla font from Tailwind to Links

Compare with previous version

added 3 commits <ul><li>ab544fc7 - 1 commit from branch <code>main</code></li><li>457aa949 - Resolve merge conflicts with new Links component</li><li>72c435fe - Add Karla font from Tailwind to Links</li></ul> [Compare with previous version](/csc/linktree/-/merge_requests/12/diffs?diff_id=51676&start_sha=5b2337a044e064c35feb51c15d6d0901193b1c56)
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

changed the description

changed the description
q63xu commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

Hmmm so this approach wouldn't work. Direct mutation is generally avoided in React because it's most often a sign of bad practice. Since React only re-renders when state is changed, during the initial render, you will see 0 views and 0 clicks.

When you mutate viewCount and clickCount, even though you've updated the variables, it won't trigger a re-render, so you'll still see 0 views and 0 clicks.

Instead make both into state variables by using useState and use their appropriate setState functions on lines 14-16

Hmmm so this approach wouldn't work. Direct mutation is generally avoided in React because it's most often a sign of bad practice. Since React only re-renders when state is changed, during the initial render, you will see 0 views and 0 clicks. When you mutate `viewCount` and `clickCount`, even though you've updated the variables, it won't trigger a re-render, so you'll still see 0 views and 0 clicks. Instead make both into state variables by using `useState` and use their appropriate `setState` functions on lines 14-16
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

changed this line in version 4 of the diff

changed this line in [version 4 of the diff](/csc/linktree/-/merge_requests/12/diffs?diff_id=52012&start_sha=72c435fe4785e70e4ce5b5c5c0e9b5d08444afd9#b9f75d55647638dbec0fcf56eaf884ef7696dfc8_6_6)
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

added 1 commit

  • 3f09aa60 - Add state hooks to get rid of let variables

Compare with previous version

added 1 commit <ul><li>3f09aa60 - Add state hooks to get rid of let variables</li></ul> [Compare with previous version](/csc/linktree/-/merge_requests/12/diffs?diff_id=52012&start_sha=72c435fe4785e70e4ce5b5c5c0e9b5d08444afd9)
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

added 1 commit

  • 7228f610 - Change click count documentation

Compare with previous version

added 1 commit <ul><li>7228f610 - Change click count documentation</li></ul> [Compare with previous version](/csc/linktree/-/merge_requests/12/diffs?diff_id=52013&start_sha=3f09aa60738a40f2903c145ad4923e2660b52d8e)
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

Gotcha, thanks!

Gotcha, thanks!
j285he commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

resolved all threads

resolved all threads
q63xu commented 2 years ago (Migrated from git.uwaterloo.ca)
Owner

approved this merge request

approved this merge request

Reviewers

The pull request has been merged.
Sign in to join this conversation.
No reviewers
No Label deployment
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: old/LinkList#17
Loading…
There is no content yet.