Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clean up and display the dashboard #2

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 22 additions & 26 deletions components/shared/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import Link from "next/link";
import styles from "./Button.module.css";
import classNames from "classnames";
// import Link from "next/link";
import { Link } from "react-router-dom"
import styles from "./Button.module.css"
import classNames from "classnames"

type Button = {
children: React.ReactNode;
variant?: "primary";
size?: "small" | "medium" | "large";
href?: string;
onClick?: () => void;
disabled?: boolean;
loading?: boolean;
icon?: React.ReactNode;
target?: string;
};
children: React.ReactNode
variant?: "primary"
size?: "small" | "medium" | "large"
href?: string
onClick?: () => void
disabled?: boolean
loading?: boolean
icon?: React.ReactNode
target?: string
}

const Button = ({
children,
Expand All @@ -29,30 +30,25 @@ const Button = ({
const commonProps = {
className: classNames(styles.button, styles[variant], styles[size]),
...props,
};
}

const iconElement = icon ? <span className={styles.icon}>{icon}</span> : null;
const iconElement = icon ? <span className={styles.icon}>{icon}</span> : null

if (href) {
return (
<Link href={href} target={target} {...commonProps}>
<Link to={href} target={target} {...commonProps}>
{iconElement}
{children}
</Link>
);
)
}

return (
<button
type="button"
onClick={onClick}
disabled={disabled || loading}
{...commonProps}
>
<button type="button" onClick={onClick} disabled={disabled || loading} {...commonProps}>
{iconElement}
{loading ? "Loading..." : children}
</button>
);
};
)
}

export default Button;
export default Button
21 changes: 11 additions & 10 deletions components/shared/EmptyCard/EmptyCard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Heading, Text } from "@radix-ui/themes";
import { Chaos } from "../Illustrations/Illustrations";
import { Heading, Text } from "@radix-ui/themes"
import { Chaos } from "../Illustrations/Illustrations"

import styles from "./EmptyCard.module.css";
import { TEMP_animationOptions } from "@/lib/utils";
import { motion } from "framer-motion";
import Link from "next/link";
import styles from "./EmptyCard.module.css"
import { TEMP_animationOptions } from "@/lib/utils"
import { motion } from "framer-motion"
// import Link from "next/link";

const EmptyCard = () => {
return (
Expand All @@ -14,12 +14,13 @@ const EmptyCard = () => {
</Heading>

<Text size="3" className={styles.text}>
Should multiple trips be displayed, please pay attention to the details to determine which trip is intended for you.
Should multiple trips be displayed, please pay attention to the details to determine which trip is intended for
you.
</Text>

<Chaos className={styles.illustration} />
</motion.div>
);
};
)
}

export default EmptyCard;
export default EmptyCard
37 changes: 18 additions & 19 deletions components/shared/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { usePathname, useRouter } from "next/navigation";
import IconButton from "../IconButton/IconButton";
import { ArrowLeft, Dots } from "../Icons/Icons";
import styles from "./Navigation.module.css";
import { useState } from "react";
import { useAuth } from "@/hooks/auth";
import { Button } from "@radix-ui/themes";
import { useApp } from "@/context/AppContext";
import { Popover } from "react-tiny-popover";
import Menu from "../Menu/Menu";
import IconButton from "../IconButton/IconButton"
import { ArrowLeft, Dots } from "../Icons/Icons"
import styles from "./Navigation.module.css"
import { useState } from "react"
import { useAuth } from "@/hooks/auth"
import { useApp } from "@/context/AppContext"
import { Popover } from "react-tiny-popover"
import Menu from "../Menu/Menu"
import { useNavigate } from "react-router-dom"

const Navigation = () => {
const { user, logout } = useAuth({ middleware: "auth" });
const { toggleMenu, menuOpen, closeMenu } = useApp();
const pathname = usePathname();
const router = useRouter();
const { user, logout } = useAuth({ middleware: "auth" })
const { toggleMenu, menuOpen, closeMenu } = useApp()
const pathname = window.location.pathname
const navigate = useNavigate()

// TODO: make less ugly & more robust
const back = pathname.startsWith("/tour")
? () => {
router.back();
navigate(-1)
}
: null;
: null

return (
<>
Expand Down Expand Up @@ -48,7 +47,7 @@ const Navigation = () => {
</Popover>
</header>
</>
);
};
)
}

export default Navigation;
export default Navigation
115 changes: 52 additions & 63 deletions components/shared/TourCard/TourCard.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
import classNames from "classnames";
import styles from "./TourCard.module.css";
import { Heading, Text } from "@radix-ui/themes";
import { Tour } from "@/types";
import { formatTourAddress, getStatusNiceName } from "@/lib/format";
import VehicleDetails from "../VehicleDetails/VehicleDetails";
import StatusIndicator from "../StatusIndicator/StatusIndicator";
import {
TEMP_animationOptions,
getGoogleMapsLatLngLink,
getStatusColor,
} from "@/lib/utils";
import { useState } from "react";
import { motion, useMotionValue } from "framer-motion";
import Link from "next/link";
import Button from "../Button/Button";
import { Phone } from "../Icons/Icons";
import { init } from "next/dist/compiled/webpack/webpack";
import { useAuth } from "@/hooks/auth";
import { isPilotOrSimilar } from "@/lib/roles";
import classNames from "classnames"
import styles from "./TourCard.module.css"
import { Heading, Text } from "@radix-ui/themes"
import { Tour } from "@/types"
import { formatTourAddress, getStatusNiceName } from "@/lib/format"
import VehicleDetails from "../VehicleDetails/VehicleDetails"
import StatusIndicator from "../StatusIndicator/StatusIndicator"
import { TEMP_animationOptions, getGoogleMapsLatLngLink, getStatusColor } from "@/lib/utils"
import { useState } from "react"
import { motion, useMotionValue } from "framer-motion"
// import Link from "next/link";
import Button from "../Button/Button"
import { Phone } from "../Icons/Icons"
import { init } from "next/dist/compiled/webpack/webpack"
import { useAuth } from "@/hooks/auth"
import { isPilotOrSimilar } from "@/lib/roles"
import { Link } from "react-router-dom"

type TourCard = {
tour: Tour;
flight: string;
className?: string;
initiallyExpanded?: boolean;
};
tour: Tour
flight: string
className?: string
initiallyExpanded?: boolean
}

const TourCard = (props: TourCard) => {
const { user } = useAuth({ middleware: "auth" });
const isPilot = isPilotOrSimilar(user);
const { user } = useAuth({ middleware: "auth" })
const isPilot = isPilotOrSimilar(user)

const { tour, flight, initiallyExpanded = false, className, ...rest } = props;
const tourStartDateTime = new Date(tour.abfahrtzeit);
const statusColor = getStatusColor(tour.status);
const { tour, flight, initiallyExpanded = false, className, ...rest } = props
const tourStartDateTime = new Date(tour.abfahrtzeit)
const statusColor = getStatusColor(tour.status)

const [expanded, setExpanded] = useState(initiallyExpanded);
const [expanded, setExpanded] = useState(initiallyExpanded)
// const [height, setHeight] = useState();

const zIndex = useMotionValue(expanded ? 2 : 0);
const zIndex = useMotionValue(expanded ? 2 : 0)

// const cardRef = useRef<HTMLDivElement>(null);

Expand Down Expand Up @@ -66,9 +63,9 @@ const TourCard = (props: TourCard) => {
// }
// };

const CardComponent = initiallyExpanded ? "div" : Link;
const CardComponent = initiallyExpanded ? "div" : Link

console.log(tour);
console.log(tour)

return (
<motion.div
Expand All @@ -81,7 +78,7 @@ const TourCard = (props: TourCard) => {
// onUpdate={(ter) => console.log("check index", ter)}
>
<CardComponent
href={`/tours/${tour.flightno}/${tour.id}`}
to={`/tours/${tour.flightno}/${tour.id}`}
className={styles.card}
// style={{ height: height ? `${height}px` : undefined }}
>
Expand All @@ -96,9 +93,7 @@ const TourCard = (props: TourCard) => {
>
<motion.div>
<Heading size={expanded ? "7" : "5"} weight={"medium"}>
{flight
? `To: ${tour.zielstrasse}`
: `Flight Number: ${tour.flightno}`}
{flight ? `To: ${tour.zielstrasse}` : `Flight Number: ${tour.flightno}`}
</Heading>
</motion.div>
{tourStartDateTime && (
Expand All @@ -111,29 +106,26 @@ const TourCard = (props: TourCard) => {
})}
</span>
{parseInt(tour.verspaetung) > 0 && (
<span className={styles.delay}>
+{Math.floor(parseInt(tour.verspaetung) / 60)} min
</span>
<span className={styles.delay}>+{Math.floor(parseInt(tour.verspaetung) / 60)} min</span>
)}
</Text>
</motion.div>
)}

{expanded &&
(tour.note_departure !== "" || tour.note_arrival !== "") && (
<motion.div className={styles.notes}>
{tour.note_departure !== "" && (
<Text as="div" size={"2"}>
{tour.note_departure}
</Text>
)}
{tour.note_arrival !== "" && (
<Text as="div" size={"2"}>
{tour.note_arrival}
</Text>
)}
</motion.div>
)}
{expanded && (tour.note_departure !== "" || tour.note_arrival !== "") && (
<motion.div className={styles.notes}>
{tour.note_departure !== "" && (
<Text as="div" size={"2"}>
{tour.note_departure}
</Text>
)}
{tour.note_arrival !== "" && (
<Text as="div" size={"2"}>
{tour.note_arrival}
</Text>
)}
</motion.div>
)}
{expanded && tour.latitude !== "" && tour.longitude !== "" && (
<div className={styles.gps}>
<Button
Expand Down Expand Up @@ -176,10 +168,7 @@ const TourCard = (props: TourCard) => {
</Text>
</div>
</motion.div>
<StatusIndicator
status={tour.status}
className={styles.statusIndicator}
/>
<StatusIndicator status={tour.status} className={styles.statusIndicator} />
<VehicleDetails
kfzfarbe={tour.kfzfarbe}
kfzkennzeichen={tour.kfzkennzeichen}
Expand All @@ -199,7 +188,7 @@ const TourCard = (props: TourCard) => {
</motion.div>
</CardComponent>
</motion.div>
);
};
)
}

export default TourCard;
export default TourCard
Loading