From 2c1765387ac1458fc1a109482cb7b63f3c7995d0 Mon Sep 17 00:00:00 2001 From: ryanmio Date: Mon, 18 Mar 2024 21:09:06 -0400 Subject: [PATCH] comments --- app/grower/[growerName]/Header.js | 1 + app/grower/[growerName]/SummarySection.js | 1 + app/grower/[growerName]/TableSection.js | 33 +++---- app/growersearch/page.js | 100 +++++++++++----------- app/pumpkin/[id]/GraphCard.js | 1 + app/pumpkin/[id]/ImageCard.js | 1 + 6 files changed, 71 insertions(+), 66 deletions(-) diff --git a/app/grower/[growerName]/Header.js b/app/grower/[growerName]/Header.js index 97492326..b924d9ab 100644 --- a/app/grower/[growerName]/Header.js +++ b/app/grower/[growerName]/Header.js @@ -1,3 +1,4 @@ +// app/grower/[growerName]/Header.js const Header = ({ data }) => { const strippedRanking = data.globalRanking.replace('Global: ', ''); diff --git a/app/grower/[growerName]/SummarySection.js b/app/grower/[growerName]/SummarySection.js index 39b4f4ab..093bdc0b 100644 --- a/app/grower/[growerName]/SummarySection.js +++ b/app/grower/[growerName]/SummarySection.js @@ -1,3 +1,4 @@ +// app/grower/[growerName]/SummarySection.js const SummarySection = ({ data }) => (

Lifetime Stats

diff --git a/app/grower/[growerName]/TableSection.js b/app/grower/[growerName]/TableSection.js index 5117076b..6b9c7c10 100644 --- a/app/grower/[growerName]/TableSection.js +++ b/app/grower/[growerName]/TableSection.js @@ -1,3 +1,4 @@ +// app/grower/[growerName]/TableSection.js import { useTable, useSortBy } from 'react-table'; import Link from 'next/link'; @@ -8,9 +9,9 @@ const TableSection = ({ data, columns }) => { headerGroups, rows, prepareRow, - } = useTable({ - columns, - data, + } = useTable({ + columns, + data, initialState: { sortBy: [{ id: 'weight', desc: true }] } }, useSortBy); @@ -45,18 +46,18 @@ const TableSection = ({ data, columns }) => { return ( {row.cells.map(cell => { - if (cell.column.id === 'contestName') { - const { key: cellKey, ...restCellProps } = cell.getCellProps(); - return ( - -
- - {cell.render('Cell')} - -
- - ); - } + if (cell.column.id === 'contestName') { + const { key: cellKey, ...restCellProps } = cell.getCellProps(); + return ( + +
+ + {cell.render('Cell')} + +
+ + ); + } const { key: cellKey, ...restCellProps } = cell.getCellProps(); return ( @@ -70,7 +71,7 @@ const TableSection = ({ data, columns }) => { ); })} - +
); diff --git a/app/growersearch/page.js b/app/growersearch/page.js index a069502a..5124085e 100644 --- a/app/growersearch/page.js +++ b/app/growersearch/page.js @@ -9,7 +9,7 @@ import { trackUserEvent, trackError, GA_ACTIONS, GA_CATEGORIES } from '../../app // Function to convert a string to title case function toTitleCase(str) { - return str.replace(/\w\S*/g, function(txt) { + return str.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); } @@ -42,32 +42,32 @@ const GrowerSearch = ({ user, handleSave }) => { const [state, dispatch] = useReducer(reducer, initialState); useEffect(() => { - if (state.growerName) { - trackUserEvent(GA_ACTIONS.Search_Initiated, GA_CATEGORIES.GrowerSearch); - getGrowerSuggestions(toTitleCase(state.growerName), (error, suggestions) => { - if (error) { - trackError(error.message, 'getGrowerSuggestions', GA_CATEGORIES.GrowerSearch, GA_ACTIONS.Fetch_Suggestions_Failure); - toast.error('Error fetching grower suggestions: ' + error.message); - } else { - trackUserEvent(GA_ACTIONS.Fetch_Suggestions_Success, GA_CATEGORIES.GrowerSearch); - dispatch({ type: 'SET_SUGGESTIONS', payload: suggestions }); - } -}); - } -}, [state.growerName]); + if (state.growerName) { + trackUserEvent(GA_ACTIONS.Search_Initiated, GA_CATEGORIES.GrowerSearch); + getGrowerSuggestions(toTitleCase(state.growerName), (error, suggestions) => { + if (error) { + trackError(error.message, 'getGrowerSuggestions', GA_CATEGORIES.GrowerSearch, GA_ACTIONS.Fetch_Suggestions_Failure); + toast.error('Error fetching grower suggestions: ' + error.message); + } else { + trackUserEvent(GA_ACTIONS.Fetch_Suggestions_Success, GA_CATEGORIES.GrowerSearch); + dispatch({ type: 'SET_SUGGESTIONS', payload: suggestions }); + } + }); + } + }, [state.growerName]); useEffect(() => { - if (state.selectedGrower && state.selectedGrower.id) { - fetchPumpkins(state.selectedGrower.id) - .then((pumpkins) => { - trackUserEvent(GA_ACTIONS.Pumpkin_Data_Fetched, GA_CATEGORIES.GrowerSearch); - dispatch({ type: 'SET_PUMPKIN_PREVIEW', payload: pumpkins }); - }) - .catch((error) => { - trackError(error, 'fetchPumpkins', GA_CATEGORIES.GrowerSearch, GA_ACTIONS.Pumpkin_Data_Error); - }); - } -}, [state.selectedGrower]); + if (state.selectedGrower && state.selectedGrower.id) { + fetchPumpkins(state.selectedGrower.id) + .then((pumpkins) => { + trackUserEvent(GA_ACTIONS.Pumpkin_Data_Fetched, GA_CATEGORIES.GrowerSearch); + dispatch({ type: 'SET_PUMPKIN_PREVIEW', payload: pumpkins }); + }) + .catch((error) => { + trackError(error, 'fetchPumpkins', GA_CATEGORIES.GrowerSearch, GA_ACTIONS.Pumpkin_Data_Error); + }); + } + }, [state.selectedGrower]); const handleSelectGrower = (grower) => { @@ -89,32 +89,32 @@ const GrowerSearch = ({ user, handleSave }) => { ]; return ( -
-
-

Search for your name

- dispatch({ type: 'SET_GROWER_NAME', payload: e.target.value })} - placeholder="Enter grower name" - className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" - /> - {state.suggestions.map(suggestion => ( -
handleSelectGrower(suggestion)} className="bg-white shadow p-2 mt-2 cursor-pointer hover:bg-gray-100"> - {suggestion.id} -
- ))} - {state.selectedGrower && ( -
-

Selected Grower: {state.selectedGrower.id}

-

Pumpkin Preview:

- - -
- )} +
+
+

Search for your name

+ dispatch({ type: 'SET_GROWER_NAME', payload: e.target.value })} + placeholder="Enter grower name" + className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" + /> + {state.suggestions.map(suggestion => ( +
handleSelectGrower(suggestion)} className="bg-white shadow p-2 mt-2 cursor-pointer hover:bg-gray-100"> + {suggestion.id} +
+ ))} + {state.selectedGrower && ( +
+

Selected Grower: {state.selectedGrower.id}

+

Pumpkin Preview:

+ + +
+ )} +
-
-); + ); }; export default GrowerSearch; diff --git a/app/pumpkin/[id]/GraphCard.js b/app/pumpkin/[id]/GraphCard.js index f4711297..6f58f2c2 100644 --- a/app/pumpkin/[id]/GraphCard.js +++ b/app/pumpkin/[id]/GraphCard.js @@ -1,3 +1,4 @@ +// app/pumpkin/[id]/GraphCard.js import React, { useMemo, useRef } from 'react'; import { Line } from 'react-chartjs-2'; import 'chartjs-adapter-date-fns'; diff --git a/app/pumpkin/[id]/ImageCard.js b/app/pumpkin/[id]/ImageCard.js index 547e910d..5026b662 100644 --- a/app/pumpkin/[id]/ImageCard.js +++ b/app/pumpkin/[id]/ImageCard.js @@ -1,3 +1,4 @@ +// app/pumpkin/[id]/ImageCard.js import React, { useState, useEffect, useContext } from 'react'; import { storage, db } from '../../../firebase'; import { toast } from 'react-hot-toast';