Skip to content

Commit

Permalink
Merge pull request #79 from dskunkler/77-let-events-become-trackable
Browse files Browse the repository at this point in the history
77: let events become trackable
  • Loading branch information
dskunkler authored Aug 31, 2023
2 parents 0e1c738 + 724d3d3 commit ee3e3d7
Show file tree
Hide file tree
Showing 5 changed files with 473 additions and 133 deletions.
1 change: 1 addition & 0 deletions src/components/calendar-wizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const CalendarWizard = (props: CalendarProps) => {
startDate={date}
setMacro={setMacroData}
events={noviceEvents}
userGoal={userGoal}
/>
)}
<div className="flex justify-center">
Expand Down
5 changes: 3 additions & 2 deletions src/components/macro-cycle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type MacroCycleProps = {
setMacro?: (val: MacroCycle) => void;
macroCycle?: PrismaMacroCycle;
events?: CycleEvent[];
userGoal?: string;
};

const macroArray = [
Expand Down Expand Up @@ -70,7 +71,7 @@ export const MacroKey = () => {
};

export const MacroCycle = (props: MacroCycleProps) => {
const { setMacro, macroCycle: macroCycleProp } = props;
const { setMacro, macroCycle: macroCycleProp, userGoal = "" } = props;
const startDate = macroCycleProp ? macroCycleProp.start : props.startDate;
if (!startDate) {
throw new Error("Start dating missing in MacroCycle");
Expand All @@ -79,7 +80,7 @@ export const MacroCycle = (props: MacroCycleProps) => {
const today = new Date(startDate);
const [phases, setPhases] = useState<MicroCycleShape[]>(macroArray);
const [goal, setGoal] = useState(
macroCycleProp ? macroCycleProp.goal : "Get Yoked"
macroCycleProp ? macroCycleProp.goal : userGoal
);
const [macroCycle, setMacroCycle] = useState<MacroCycle>({
start: today,
Expand Down
36 changes: 36 additions & 0 deletions src/components/macro-view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from "react";
import { api } from "~/utils/api";
import { CalendarWizard } from "../components/calendar-wizard";
import { useEffect, useState } from "react";
import MacroCycleComponent from "../components/macro-cycle";

const MacroView = () => {
api.posts.getAll.useQuery();

const { data: latestMacroData } = api.macroCycles.getMostRecent.useQuery();

useEffect(() => {
// console.log("latest?: ", latestMacroData);
}, [latestMacroData]);

const [showCalendar, setShowCalendar] = useState(false);

return (
<>
{latestMacroData ? (
<MacroCycleComponent macroCycle={latestMacroData} />
) : showCalendar ? (
<CalendarWizard closeCal={() => setShowCalendar(false)} />
) : (
<button
onClick={() => setShowCalendar(true)}
className="rounded-full border border-purple-200 px-4 py-1 text-sm font-semibold text-purple-600 hover:border-transparent hover:bg-purple-600 hover:text-white focus:outline-none focus:ring-2 focus:ring-purple-600 focus:ring-offset-2"
>
Get Started
</button>
)}
</>
);
};

export default MacroView;
33 changes: 2 additions & 31 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import { type NextPage } from "next";
import Head from "next/head";

import { api } from "~/utils/api";
import { SignInButton, useUser, UserButton } from "@clerk/nextjs";
import { CalendarWizard } from "../components/calendar-wizard";
import { useEffect, useState } from "react";
import { LoadingPage } from "../components/loading-spinner";
import MacroCycleComponent from "../components/macro-cycle";
import MacroView from "~/components/macro-view";

const Home: NextPage = () => {
// This is for learning purposes can remove later

api.posts.getAll.useQuery();
const user = useUser();

const { data: latestMacroData, isLoading: isLoadingCycles } =
api.macroCycles.getMostRecent.useQuery();

useEffect(() => {
// console.log("latest?: ", latestMacroData);
}, [latestMacroData]);

const [showCalendar, setShowCalendar] = useState(false);

return (
<>
<Head>
Expand All @@ -36,21 +21,7 @@ const Home: NextPage = () => {
Climb <span className="text-[hsl(280,100%,70%)]">HARDER</span>{" "}
</h1>
<div className="flex w-full flex-col items-center gap-2">
{user.isSignedIn &&
!showCalendar &&
(latestMacroData ? (
<MacroCycleComponent macroCycle={latestMacroData} />
) : (
<button
onClick={() => setShowCalendar(true)}
className="rounded-full border border-purple-200 px-4 py-1 text-sm font-semibold text-purple-600 hover:border-transparent hover:bg-purple-600 hover:text-white focus:outline-none focus:ring-2 focus:ring-purple-600 focus:ring-offset-2"
>
Get Started
</button>
))}
{showCalendar && !latestMacroData && (
<CalendarWizard closeCal={() => setShowCalendar(false)} />
)}
{user.isSignedIn && <MacroView />}
</div>
</div>
</main>
Expand Down
Loading

1 comment on commit ee3e3d7

@vercel
Copy link

@vercel vercel bot commented on ee3e3d7 Aug 31, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.