Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmio committed Mar 19, 2024
1 parent e1ec2f9 commit 2c17653
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 66 deletions.
1 change: 1 addition & 0 deletions app/grower/[growerName]/Header.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// app/grower/[growerName]/Header.js
const Header = ({ data }) => {
const strippedRanking = data.globalRanking.replace('Global: ', '');

Expand Down
1 change: 1 addition & 0 deletions app/grower/[growerName]/SummarySection.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// app/grower/[growerName]/SummarySection.js
const SummarySection = ({ data }) => (
<div className="bg-white shadow rounded-lg p-4 md:col-span-2 flex flex-col">
<h2 className="text-xl font-bold mb-2">Lifetime Stats</h2>
Expand Down
33 changes: 17 additions & 16 deletions app/grower/[growerName]/TableSection.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// app/grower/[growerName]/TableSection.js
import { useTable, useSortBy } from 'react-table';
import Link from 'next/link';

Expand All @@ -8,9 +9,9 @@ const TableSection = ({ data, columns }) => {
headerGroups,
rows,
prepareRow,
} = useTable({
columns,
data,
} = useTable({
columns,
data,
initialState: { sortBy: [{ id: 'weight', desc: true }] }
}, useSortBy);

Expand Down Expand Up @@ -45,18 +46,18 @@ const TableSection = ({ data, columns }) => {
return (
<tr key={key} {...restRowProps}>
{row.cells.map(cell => {
if (cell.column.id === 'contestName') {
const { key: cellKey, ...restCellProps } = cell.getCellProps();
return (
<td key={cellKey} {...restCellProps} className={`table-cell-spacing w-[200px]`}>
<div className={`w-full`} title={cell.value}>
<Link href={`/site-profile/${encodeURIComponent(row.original.contestName)}`} className="text-current hover:text-current no-underline hover:underline">
{cell.render('Cell')}
</Link>
</div>
</td>
);
}
if (cell.column.id === 'contestName') {
const { key: cellKey, ...restCellProps } = cell.getCellProps();
return (
<td key={cellKey} {...restCellProps} className={`table-cell-spacing w-[200px]`}>
<div className={`w-full`} title={cell.value}>
<Link href={`/site-profile/${encodeURIComponent(row.original.contestName)}`} className="text-current hover:text-current no-underline hover:underline">
{cell.render('Cell')}
</Link>
</div>
</td>
);
}

const { key: cellKey, ...restCellProps } = cell.getCellProps();
return (
Expand All @@ -70,7 +71,7 @@ const TableSection = ({ data, columns }) => {
</tr>
);
})}
</tbody>
</tbody>
</table>
</div>
);
Expand Down
100 changes: 50 additions & 50 deletions app/growersearch/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down Expand Up @@ -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) => {
Expand All @@ -89,32 +89,32 @@ const GrowerSearch = ({ user, handleSave }) => {
];

return (
<div className="min-h-screen flex justify-start flex-col items-center">
<div className="container mx-auto px-4 pt-10 mt-4 flex flex-col space-y-4 bg-white shadow rounded-lg p-4 max-w-2xl w-full">
<h1 className="text-2xl font-bold mb-4 text-center">Search for your name</h1>
<input
type="text"
value={state.growerName}
onChange={(e) => 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 => (
<div key={suggestion.id} onClick={() => handleSelectGrower(suggestion)} className="bg-white shadow p-2 mt-2 cursor-pointer hover:bg-gray-100">
{suggestion.id}
</div>
))}
{state.selectedGrower && (
<div className="flex flex-col mt-4">
<h2>Selected Grower: {state.selectedGrower.id}</h2>
<h3 className="text-xl font-bold mb-2">Pumpkin Preview:</h3>
<TableSection data={state.pumpkinPreview} columns={pumpkinColumns} />
<button onClick={handleConfirm} className="green-button inline-flex items-center justify-center px-2 py-1 border border-transparent text-sm font-medium rounded-md shadow-sm text-white hover:text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 self-center">Confirm</button>
</div>
)}
<div className="min-h-screen flex justify-start flex-col items-center">
<div className="container mx-auto px-4 pt-10 mt-4 flex flex-col space-y-4 bg-white shadow rounded-lg p-4 max-w-2xl w-full">
<h1 className="text-2xl font-bold mb-4 text-center">Search for your name</h1>
<input
type="text"
value={state.growerName}
onChange={(e) => 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 => (
<div key={suggestion.id} onClick={() => handleSelectGrower(suggestion)} className="bg-white shadow p-2 mt-2 cursor-pointer hover:bg-gray-100">
{suggestion.id}
</div>
))}
{state.selectedGrower && (
<div className="flex flex-col mt-4">
<h2>Selected Grower: {state.selectedGrower.id}</h2>
<h3 className="text-xl font-bold mb-2">Pumpkin Preview:</h3>
<TableSection data={state.pumpkinPreview} columns={pumpkinColumns} />
<button onClick={handleConfirm} className="green-button inline-flex items-center justify-center px-2 py-1 border border-transparent text-sm font-medium rounded-md shadow-sm text-white hover:text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 self-center">Confirm</button>
</div>
)}
</div>
</div>
</div>
);
);
};

export default GrowerSearch;
1 change: 1 addition & 0 deletions app/pumpkin/[id]/GraphCard.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions app/pumpkin/[id]/ImageCard.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 2c17653

Please sign in to comment.