From d6287cb76f72e6cf003bbfbe83589f13641ac5cb Mon Sep 17 00:00:00 2001 From: ialej001 Date: Fri, 2 Sep 2022 17:03:03 -0700 Subject: [PATCH 01/44] created dashboard control panel --- src/components/Dashboard/ControlPanel.tsx | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/components/Dashboard/ControlPanel.tsx diff --git a/src/components/Dashboard/ControlPanel.tsx b/src/components/Dashboard/ControlPanel.tsx new file mode 100644 index 0000000..8aa0bca --- /dev/null +++ b/src/components/Dashboard/ControlPanel.tsx @@ -0,0 +1,42 @@ +import React from 'react'; +import { GoSettings } from 'react-icons/go'; +import { MdDashboard } from 'react-icons/md'; +import { CgLogOut } from 'react-icons/cg'; +import { Tooltip } from 'flowbite-react'; +import { useRouter } from 'next/router'; +import { signOut } from 'next-auth/react'; + +const ControlPanel = () => { + const router = useRouter(); + const buttonSize = 50; + + return ( +
+ + { + router.push('/account'); + }} + size={buttonSize} + className="cursor-pointer mb-5" + /> + + + + { + router.push('/account/preferences'); + }} + size={buttonSize} + className="cursor-pointer hover:bg-gray-400 mb-5" + /> + + + + signOut()} size={buttonSize} /> + +
+ ); +}; + +export default ControlPanel; From 47c33cab9e2fefa1ed76946349aa8d147414b584 Mon Sep 17 00:00:00 2001 From: ialej001 Date: Fri, 2 Sep 2022 18:00:12 -0700 Subject: [PATCH 02/44] created summary tile --- src/components/Dashboard/SummaryTile.tsx | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/components/Dashboard/SummaryTile.tsx diff --git a/src/components/Dashboard/SummaryTile.tsx b/src/components/Dashboard/SummaryTile.tsx new file mode 100644 index 0000000..10cf7ae --- /dev/null +++ b/src/components/Dashboard/SummaryTile.tsx @@ -0,0 +1,44 @@ +import { Card } from 'flowbite-react'; +import React from 'react'; +import { FaGasPump } from 'react-icons/fa'; +import { ImPowerCord } from 'react-icons/im'; +import { MdDriveEta, MdFlight } from 'react-icons/md'; + +interface SummaryTileProps { + type: string; + emissionsValue: number; +} + +const SummaryTile = ({ type, emissionsValue }: SummaryTileProps) => { + return ( +
+ console.log(type)}> +
+

{type}

+ {getIcon(type)} +

Emissions

+

{emissionsValue}

+
+
+
+ ); +}; + +const getIcon = (type: string) => { + const buttonSize = 45; + + switch (type) { + case 'Power': + return ; + case 'Fuel': + return ; + case 'Flight': + return ; + case 'Driving': + return ; + default: + return; + } +}; + +export default SummaryTile; From bc07c7fe356cbefa14b70bd3b5e8427768d7c0da Mon Sep 17 00:00:00 2001 From: ialej001 Date: Fri, 2 Sep 2022 18:00:22 -0700 Subject: [PATCH 03/44] updated styling --- src/components/Dashboard/ControlPanel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Dashboard/ControlPanel.tsx b/src/components/Dashboard/ControlPanel.tsx index 8aa0bca..2450165 100644 --- a/src/components/Dashboard/ControlPanel.tsx +++ b/src/components/Dashboard/ControlPanel.tsx @@ -11,7 +11,7 @@ const ControlPanel = () => { const buttonSize = 50; return ( -
+
{ From eb71ebd095660a7f6593d404ccf39307cc923031 Mon Sep 17 00:00:00 2001 From: ialej001 Date: Fri, 2 Sep 2022 18:00:42 -0700 Subject: [PATCH 04/44] created dash --- src/components/Dashboard/Dashboard.tsx | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/components/Dashboard/Dashboard.tsx diff --git a/src/components/Dashboard/Dashboard.tsx b/src/components/Dashboard/Dashboard.tsx new file mode 100644 index 0000000..df86cf9 --- /dev/null +++ b/src/components/Dashboard/Dashboard.tsx @@ -0,0 +1,38 @@ +import React from 'react'; +import SummaryTile from './SummaryTile'; + +const Dashboard = () => { + const data = [ + { type: 'Power', emissions: 3000 }, + { type: 'Fuel', emissions: 2000 }, + { type: 'Flight', emissions: 4000 }, + { type: 'Driving', emissions: 6000 }, + ]; + + return ( +
+
+

Your total emissions to date

+ +
+
+

+ To this day, your total emissions break down as follows +

+
+
+ {data.map((classification) => { + return ( + + ); + })} +
+
+ ); +}; + +export default Dashboard; From 6aba9d467842f0b5867df49ef28b3474f4a5ac52 Mon Sep 17 00:00:00 2001 From: ialej001 Date: Fri, 2 Sep 2022 18:03:41 -0700 Subject: [PATCH 05/44] incorporated dashboard and control panel --- src/pages/account/index.tsx | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/pages/account/index.tsx b/src/pages/account/index.tsx index 75e2bba..ac78b25 100644 --- a/src/pages/account/index.tsx +++ b/src/pages/account/index.tsx @@ -1,8 +1,8 @@ -import { router } from '@trpc/server'; -import { Button, Spinner } from 'flowbite-react'; -import { signOut, useSession } from 'next-auth/react'; +import { useSession } from 'next-auth/react'; import { useRouter } from 'next/router'; -import { useEffect, useState } from 'react'; +import { useEffect } from 'react'; +import ControlPanel from '../../components/Dashboard/ControlPanel'; +import Dashboard from '../../components/Dashboard/Dashboard'; export default function AccountPage() { const { data: session } = useSession(); @@ -15,24 +15,20 @@ export default function AccountPage() { }, [session]); if (!session) { - return ( -
- Access denied. Please sign in. -
- ) + return
Access denied. Please sign in.
; } + return ( -
-

Account Page

- - +
+
+ +
+
+
+

Welcome, {session.user?.name}

+ +
+
); } - From e708cc8d5c13f12fd795eb3142e56866a9bfc95d Mon Sep 17 00:00:00 2001 From: ialej001 Date: Fri, 2 Sep 2022 18:10:06 -0700 Subject: [PATCH 06/44] created dashboard route --- src/server/router/dashboard.router.ts | 51 +++++++++++++++++++++++++++ src/server/router/index.ts | 5 +-- 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/server/router/dashboard.router.ts diff --git a/src/server/router/dashboard.router.ts b/src/server/router/dashboard.router.ts new file mode 100644 index 0000000..1bf2417 --- /dev/null +++ b/src/server/router/dashboard.router.ts @@ -0,0 +1,51 @@ +import { createRouter } from './context'; + +export const dashboardRouter = createRouter().query('summary', { + async resolve({ ctx }) { + const user = ctx.session?.user; + + if (user) { + const electricityCarbon = ctx.prisma.electricityUse.findMany({ + select: { + carbon_g: true, + estimatedAt: true, + }, + where: { + userId: user.id, + }, + }); + + const vehicleCarbon = ctx.prisma.vehicle.findMany({ + select: { + trips: { + select: { + carbon_g: true, + estimatedAt: true, + }, + }, + }, + where: { + userId: user.id, + }, + }); + + const fuelCarbon = ctx.prisma.fuelUsed.findMany({ + select: { + carbon_g: true, + estimatedAt: true, + }, + }); + + const flightCarbon = ctx.prisma.flight.findMany({ + select: { + carbon_g: true, + estimatedAt: true, + }, + }); + + return { electricityCarbon, vehicleCarbon, fuelCarbon, flightCarbon }; + } + + return {}; + }, +}); diff --git a/src/server/router/index.ts b/src/server/router/index.ts index 6fb8389..06ff4b4 100644 --- a/src/server/router/index.ts +++ b/src/server/router/index.ts @@ -1,6 +1,5 @@ // src/server/router/index.ts import { createRouter } from "./context"; -import superjson from "superjson"; import { exampleRouter } from './example'; import { protectedExampleRouter } from './protected-example-router'; @@ -8,6 +7,7 @@ import { electricityRouter } from './electricity.router'; import { flightRouter } from "./flight.router"; import { vehicleRouter } from './vehicle.router'; import { fuelRouter } from './fuel.router'; +import { dashboardRouter } from "./dashboard.router"; export const appRouter = createRouter() .merge('example.', exampleRouter) @@ -15,7 +15,8 @@ export const appRouter = createRouter() .merge('electricity.', electricityRouter) .merge('flight.', flightRouter) .merge('vehicle.', vehicleRouter) - .merge('fuel.', fuelRouter); + .merge('fuel.', fuelRouter) + .merge('dashboard.', dashboardRouter); // export type definition of API export type AppRouter = typeof appRouter; From ba869786e7d3224994402aa2045f97b7e236aefa Mon Sep 17 00:00:00 2001 From: ialej001 Date: Fri, 2 Sep 2022 18:57:07 -0700 Subject: [PATCH 07/44] renamed power to electricity for consistency --- src/components/Dashboard/Dashboard.tsx | 19 +++++++++++++------ src/components/Dashboard/SummaryTile.tsx | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/components/Dashboard/Dashboard.tsx b/src/components/Dashboard/Dashboard.tsx index df86cf9..39ffba6 100644 --- a/src/components/Dashboard/Dashboard.tsx +++ b/src/components/Dashboard/Dashboard.tsx @@ -1,19 +1,26 @@ import React from 'react'; +import { trpc } from '../../utils/trpc'; import SummaryTile from './SummaryTile'; const Dashboard = () => { - const data = [ - { type: 'Power', emissions: 3000 }, + const dummyData = [ + { type: 'Electricity', emissions: 3000 }, { type: 'Fuel', emissions: 2000 }, { type: 'Flight', emissions: 4000 }, { type: 'Driving', emissions: 6000 }, ]; + const { data, isLoading } = trpc.useQuery(['dashboard.summary']); + + const totalEmissions = dummyData.reduce((previousValue, current) => { + return previousValue + current.emissions; + }, 0); + + console.log(data, totalEmissions); return (
-
-

Your total emissions to date

- +
+

Your total emissions to date

@@ -21,7 +28,7 @@ const Dashboard = () => {

- {data.map((classification) => { + {dummyData.map((classification) => { return ( { const buttonSize = 45; switch (type) { - case 'Power': + case 'Electricity': return ; case 'Fuel': return ; From 96c517baba29f943660ec2eaab6df1e95b8eb6cc Mon Sep 17 00:00:00 2001 From: ialej001 Date: Fri, 2 Sep 2022 21:11:44 -0700 Subject: [PATCH 08/44] added circular progress indicator for relative %s --- package-lock.json | 65 ++++++++++++++++++++++-- package.json | 1 + src/components/Dashboard/SummaryTile.tsx | 26 ++++++++-- 3 files changed, 85 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 04bc37b..5e7fa86 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "next": "12.2.3", "next-auth": "^4.10.3", "nodemailer": "^6.7.8", + "rc-progress": "^3.4.0", "react": "18.2.0", "react-dom": "18.2.0", "react-icons": "^4.4.0", @@ -8900,6 +8901,34 @@ "node": ">= 0.8" } }, + "node_modules/rc-progress": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/rc-progress/-/rc-progress-3.4.0.tgz", + "integrity": "sha512-ZuMyOzzTkZnn+EKqGQ7YHzrvGzBtcCCVjx1McC/E/pMTvr6GWVfVRSawDlWsscxsJs7MkqSTwCO6Lu4IeoY2zQ==", + "dependencies": { + "@babel/runtime": "^7.10.1", + "classnames": "^2.2.6", + "rc-util": "^5.16.1" + }, + "peerDependencies": { + "react": ">=16.9.0", + "react-dom": ">=16.9.0" + } + }, + "node_modules/rc-util": { + "version": "5.23.0", + "resolved": "https://registry.npmjs.org/rc-util/-/rc-util-5.23.0.tgz", + "integrity": "sha512-lgm6diJ/pLgyfoZY59Vz7sW4mSoQCgozqbBye9IJ7/mb5w5h4T7h+i2JpXAx/UBQxscBZe68q0sP7EW+qfkKUg==", + "dependencies": { + "@babel/runtime": "^7.18.3", + "react-is": "^16.12.0", + "shallowequal": "^1.1.0" + }, + "peerDependencies": { + "react": ">=16.9.0", + "react-dom": ">=16.9.0" + } + }, "node_modules/react": { "version": "18.2.0", "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", @@ -8952,8 +8981,7 @@ "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", - "dev": true + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, "node_modules/react-query": { "version": "3.39.2", @@ -9391,6 +9419,11 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "dev": true }, + "node_modules/shallowequal": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/shallowequal/-/shallowequal-1.1.0.tgz", + "integrity": "sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==" + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -17111,6 +17144,26 @@ "unpipe": "1.0.0" } }, + "rc-progress": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/rc-progress/-/rc-progress-3.4.0.tgz", + "integrity": "sha512-ZuMyOzzTkZnn+EKqGQ7YHzrvGzBtcCCVjx1McC/E/pMTvr6GWVfVRSawDlWsscxsJs7MkqSTwCO6Lu4IeoY2zQ==", + "requires": { + "@babel/runtime": "^7.10.1", + "classnames": "^2.2.6", + "rc-util": "^5.16.1" + } + }, + "rc-util": { + "version": "5.23.0", + "resolved": "https://registry.npmjs.org/rc-util/-/rc-util-5.23.0.tgz", + "integrity": "sha512-lgm6diJ/pLgyfoZY59Vz7sW4mSoQCgozqbBye9IJ7/mb5w5h4T7h+i2JpXAx/UBQxscBZe68q0sP7EW+qfkKUg==", + "requires": { + "@babel/runtime": "^7.18.3", + "react-is": "^16.12.0", + "shallowequal": "^1.1.0" + } + }, "react": { "version": "18.2.0", "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", @@ -17147,8 +17200,7 @@ "react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", - "dev": true + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, "react-query": { "version": "3.39.2", @@ -17462,6 +17514,11 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "dev": true }, + "shallowequal": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/shallowequal/-/shallowequal-1.1.0.tgz", + "integrity": "sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==" + }, "shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", diff --git a/package.json b/package.json index 72a7ed4..11c3a83 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "next": "12.2.3", "next-auth": "^4.10.3", "nodemailer": "^6.7.8", + "rc-progress": "^3.4.0", "react": "18.2.0", "react-dom": "18.2.0", "react-icons": "^4.4.0", diff --git a/src/components/Dashboard/SummaryTile.tsx b/src/components/Dashboard/SummaryTile.tsx index 7005fc6..c7992d8 100644 --- a/src/components/Dashboard/SummaryTile.tsx +++ b/src/components/Dashboard/SummaryTile.tsx @@ -1,4 +1,5 @@ -import { Card } from 'flowbite-react'; +import { Card, Progress } from 'flowbite-react'; +import { Circle } from 'rc-progress'; import React from 'react'; import { FaGasPump } from 'react-icons/fa'; import { ImPowerCord } from 'react-icons/im'; @@ -7,9 +8,15 @@ import { MdDriveEta, MdFlight } from 'react-icons/md'; interface SummaryTileProps { type: string; emissionsValue: number; + totalEmissions: number; } -const SummaryTile = ({ type, emissionsValue }: SummaryTileProps) => { +const SummaryTile = ({ + type, + emissionsValue, + totalEmissions, +}: SummaryTileProps) => { + const emissionsPercentage = (emissionsValue / totalEmissions) * 100; return (
console.log(type)}> @@ -17,13 +24,26 @@ const SummaryTile = ({ type, emissionsValue }: SummaryTileProps) => {

{type}

{getIcon(type)}

Emissions

-

{emissionsValue}

+

{emissionsValue} g

+

{emissionsPercentage.toFixed(2)}% of all calculations

+ +
); }; +const getColor = (emissionsPercentage: number) => { + if (emissionsPercentage > 80) return 'red'; + if (emissionsPercentage > 40) return 'yellow'; + return 'green'; +}; + const getIcon = (type: string) => { const buttonSize = 45; From dfaf7e9df28df774efcd297442e4d1c221d052a2 Mon Sep 17 00:00:00 2001 From: ialej001 Date: Fri, 2 Sep 2022 22:14:40 -0700 Subject: [PATCH 09/44] added summary output schema --- src/schema/dashboard.schema.ts | 12 ++++ src/server/router/dashboard.router.ts | 94 +++++++++++++++++---------- 2 files changed, 72 insertions(+), 34 deletions(-) create mode 100644 src/schema/dashboard.schema.ts diff --git a/src/schema/dashboard.schema.ts b/src/schema/dashboard.schema.ts new file mode 100644 index 0000000..5700f9d --- /dev/null +++ b/src/schema/dashboard.schema.ts @@ -0,0 +1,12 @@ +import z from 'zod'; + +export const summarySchema = z.array( + z.object({ type: z.string(), emissions: z.number() }) +); + +export type SummaryResponseType = z.TypeOf; + +export interface SummaryQueryResponse { + data: SummaryResponseType; + isLoading: boolean; +} diff --git a/src/server/router/dashboard.router.ts b/src/server/router/dashboard.router.ts index 1bf2417..e4e62ce 100644 --- a/src/server/router/dashboard.router.ts +++ b/src/server/router/dashboard.router.ts @@ -1,51 +1,77 @@ +import { summarySchema, SummaryResponseType } from '../../schema/dashboard.schema'; import { createRouter } from './context'; export const dashboardRouter = createRouter().query('summary', { + output: summarySchema, async resolve({ ctx }) { const user = ctx.session?.user; if (user) { - const electricityCarbon = ctx.prisma.electricityUse.findMany({ - select: { - carbon_g: true, - estimatedAt: true, - }, - where: { - userId: user.id, - }, - }); + const electricityCarbon = await ctx.prisma.electricityUse + .aggregate({ + _sum: { + carbon_g: true, + }, + where: { + userId: user.id, + }, + }) + .then((response) => response._sum.carbon_g); - const vehicleCarbon = ctx.prisma.vehicle.findMany({ - select: { - trips: { - select: { - carbon_g: true, - estimatedAt: true, + const vehicleCarbon = await ctx.prisma.vehicle + .findMany({ + select: { + trips: { + select: { + carbon_g: true, + }, }, }, - }, - where: { - userId: user.id, - }, - }); + where: { + userId: user.id, + }, + }) + .then((response) => + response.reduce((previous, current) => { + return ( + previous + + current.trips.reduce((previous, current) => { + return previous + current.carbon_g; + }, 0) + ); + }, 0) + ); - const fuelCarbon = ctx.prisma.fuelUsed.findMany({ - select: { - carbon_g: true, - estimatedAt: true, - }, - }); + const fuelCarbon = await ctx.prisma.fuelUsed + .aggregate({ + _sum: { + carbon_g: true, + }, + where: { + userId: user.id, + }, + }) + .then((response) => response._sum.carbon_g); - const flightCarbon = ctx.prisma.flight.findMany({ - select: { - carbon_g: true, - estimatedAt: true, - }, - }); + const flightCarbon = await ctx.prisma.flight + .aggregate({ + _sum: { + carbon_g: true, + }, + where: { + userId: user.id, + }, + }) + .then((response) => response._sum.carbon_g); - return { electricityCarbon, vehicleCarbon, fuelCarbon, flightCarbon }; + return [ + { type: 'Electricity', emissions: electricityCarbon ?? 0 }, + { type: 'Driving', emissions: vehicleCarbon ?? 0 }, + { type: 'Fuel', emissions: fuelCarbon ?? 0 }, + { type: 'Flight', emissions: flightCarbon ?? 0 }, + ]; } - return {}; + return []; }, }); From 0bfc8efdedfa2de93fdb18aa25c707900afa557e Mon Sep 17 00:00:00 2001 From: ialej001 Date: Fri, 2 Sep 2022 22:22:45 -0700 Subject: [PATCH 10/44] added loading spinner --- src/components/Dashboard/Dashboard.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/Dashboard/Dashboard.tsx b/src/components/Dashboard/Dashboard.tsx index 39ffba6..f1ce3f2 100644 --- a/src/components/Dashboard/Dashboard.tsx +++ b/src/components/Dashboard/Dashboard.tsx @@ -1,3 +1,4 @@ +import { Spinner } from 'flowbite-react'; import React from 'react'; import { trpc } from '../../utils/trpc'; import SummaryTile from './SummaryTile'; @@ -11,28 +12,31 @@ const Dashboard = () => { ]; const { data, isLoading } = trpc.useQuery(['dashboard.summary']); - const totalEmissions = dummyData.reduce((previousValue, current) => { + const totalEmissions = data?.reduce((previousValue, current) => { return previousValue + current.emissions; - }, 0); + }, 0) ?? 0; console.log(data, totalEmissions); return (
-
+

Your total emissions to date

+

{totalEmissions} g

- To this day, your total emissions break down as follows + To this date, your total emissions break down as follows

-
- {dummyData.map((classification) => { +
+ {isLoading && !data && } + {!isLoading && data && data.map((classification) => { return ( ); From 70382b913483e420da37cef962e869fcb97ead88 Mon Sep 17 00:00:00 2001 From: ialej001 Date: Fri, 2 Sep 2022 22:23:14 -0700 Subject: [PATCH 11/44] removed unused types --- src/schema/dashboard.schema.ts | 9 +-------- src/server/router/dashboard.router.ts | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/schema/dashboard.schema.ts b/src/schema/dashboard.schema.ts index 5700f9d..202dfda 100644 --- a/src/schema/dashboard.schema.ts +++ b/src/schema/dashboard.schema.ts @@ -2,11 +2,4 @@ import z from 'zod'; export const summarySchema = z.array( z.object({ type: z.string(), emissions: z.number() }) -); - -export type SummaryResponseType = z.TypeOf; - -export interface SummaryQueryResponse { - data: SummaryResponseType; - isLoading: boolean; -} +); \ No newline at end of file diff --git a/src/server/router/dashboard.router.ts b/src/server/router/dashboard.router.ts index e4e62ce..b7bdb0e 100644 --- a/src/server/router/dashboard.router.ts +++ b/src/server/router/dashboard.router.ts @@ -1,4 +1,4 @@ -import { summarySchema, SummaryResponseType } from '../../schema/dashboard.schema'; +import { summarySchema } from '../../schema/dashboard.schema'; import { createRouter } from './context'; export const dashboardRouter = createRouter().query('summary', { From 5cb10a3cce8ceffb6b379a6aaa54e783303c1408 Mon Sep 17 00:00:00 2001 From: ialej001 Date: Fri, 2 Sep 2022 23:55:51 -0700 Subject: [PATCH 12/44] added and refactored layouts --- src/layouts/AccountLayout.tsx | 20 ++++++++++++++++++++ src/pages/_app.tsx | 19 ++++++++++++++++--- src/pages/account/index.tsx | 31 ++++++++++++++----------------- 3 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 src/layouts/AccountLayout.tsx diff --git a/src/layouts/AccountLayout.tsx b/src/layouts/AccountLayout.tsx new file mode 100644 index 0000000..c634b7a --- /dev/null +++ b/src/layouts/AccountLayout.tsx @@ -0,0 +1,20 @@ +import React, { ReactNode } from 'react' +import ControlPanel from '../components/Dashboard/ControlPanel' + +interface AccountLayoutProps { + children: ReactNode +} +const AccountLayout = ({ children }: AccountLayoutProps) => { + return ( +
+
+ +
+
+ { children } +
+
+ ) +} + +export default AccountLayout \ No newline at end of file diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 84e4636..806f54a 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -7,15 +7,28 @@ import { SessionProvider } from 'next-auth/react'; import '../styles/globals.css'; import Footer from '../components/Footer'; import Nav from '../components/Nav'; +import { NextPage } from 'next'; +import { ReactElement, ReactNode } from 'react'; +import { AppProps } from 'next/app'; -const MyApp: AppType = ({ +export type NextPageWithLayout

= NextPage & { + getLayout?: (page: ReactElement) => ReactNode; +}; + +type AppPropsWithLayout = AppProps & { + Component: NextPageWithLayout; +}; + +const MyApp = ({ Component, pageProps: { session, ...pageProps }, -}) => { +}: AppPropsWithLayout) => { + const getLayout = Component.getLayout ?? ((page) => page); + return (