Skip to content

Commit

Permalink
chore!: add deprecation notice
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelblijleven committed Apr 10, 2024
1 parent d9524b9 commit ece7312
Show file tree
Hide file tree
Showing 31 changed files with 27 additions and 2,435 deletions.
17 changes: 17 additions & 0 deletions src/app/(home)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Link from "next/link";
import { BeanconquerorUsp } from "@/components/home/usp";
import {Alert, AlertDescription, AlertTitle} from "@/components/ui/alert";

function WrappedLink() {
return (
Expand All @@ -18,6 +19,21 @@ function WrappedLink() {
);
}

function DBDeprecationNotice() {
return (
<Alert variant={"destructive"}>
<AlertTitle>Database deprecation</AlertTitle>
<AlertDescription>
A change in the pricing strategy of the database provider increased the costs of hosting Beanstats by several
hundreds of dollars, making it impossible to keep providing the database related functionalities of Beanstats free of charge.
Therefor these functionalities had to be removed from Beanstats.

Contact me if you need an export of your data.
</AlertDescription>
</Alert>
)
}

export default function Home() {
return (
<div className={"flex flex-col items-center"}>
Expand All @@ -35,6 +51,7 @@ export default function Home() {
Beanstats extends Beanconqueror and makes it easy to enter data,
visualise data and share bean entries
</p>
<DBDeprecationNotice />
<BeanconquerorUsp />
</section>
</div>
Expand Down
10 changes: 2 additions & 8 deletions src/components/beanconqueror/share/view/shared-bean.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ const GeneralTabsContent = ({ decoded }: { decoded: BeanProto }) => (
/>
)}
{/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */}
<LabelledValue
type={"rating"}
label={"Roast range"}
value={decoded.roastRange}
<LabelledValue type={"rating"} label={"Roast range"} value={decoded.roastRange}
/>
<LabelledValue
type={"string"}
Expand Down Expand Up @@ -86,10 +83,7 @@ const GeneralTabsContent = ({ decoded }: { decoded: BeanProto }) => (
<CardContent>
<div className={"grid grid-cols-1 md:grid-cols-2 gap-2"}>
{/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */}
<LabelledValue
type={"number"}
label={"Weight"}
value={decoded.weight}
<LabelledValue type={"number"} label={"Weight"} value={decoded.weight}
/>
{/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */}
<LabelledValue type={"number"} label={"Cost"} value={decoded.cost} />
Expand Down
178 changes: 6 additions & 172 deletions src/components/coffee/share.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
"use client";

import dynamic from "next/dynamic";
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer";
import { Button, buttonVariants } from "@/components/ui/button";
import { type SelectBean } from "@/lib/db/beans/get-bean-details";
import { createUrlFromFormSchema } from "@/lib/beanconqueror/proto/proto-helpers";
import { type beanInformationFormSchema } from "@/lib/beanconqueror/validations/bean-information-form-schema";

import { Button } from "@/components/ui/button";
import { useState } from "react";
import { getBeankLink } from "@/lib/beanlink";
import { getBeanLink } from "@/lib/beanlink";
import CopyContainer from "@/components/copy-container";
import { useMediaQuery } from "@/lib/hooks";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { getShortShareLink } from "@/lib/share/actions";

import { useToast } from "@/components/ui/use-toast";

const QRCode = dynamic(
() => import("@/components/qrcode-card").then((module) => module.QRCode),
{ ssr: false },
);

type BeanDetails = Awaited<SelectBean>;
type Varieties = BeanDetails["varieties"];

/**
* Maps the length value to a BeanMix value, where
* 0 is unknown, 1 is single origin and 2 is a blend
Expand All @@ -51,55 +27,6 @@ function getBeanMix(
return "SINGLE_ORIGIN";
}

/**
* Map varieties to bean information schema
* @param varieties
*/
function getVarietyInformation(
varieties: Varieties,
): beanInformationFormSchema["varietyInformation"] {
if (varieties.length === 0) {
return undefined;
}

return varieties.map((variety) => ({
variety: variety.name ?? undefined,
country: variety.country ?? undefined,
region: variety.region ?? undefined,
farm: variety.farm ?? undefined,
farmer: variety.farmer ?? undefined,
elevation: variety.elevation ?? undefined,
processing: variety.processing ?? undefined,
}));
}

/**
* Create bean information scheme from provided BeanDetails
* @param bean
*/
function createBeanInformationSchema(
bean: BeanDetails,
): beanInformationFormSchema | null {
if (bean === undefined) return null;

return {
coffeeName: bean.name,
roaster: bean.roaster.name,
roastingDate: bean.roastDate ? new Date(bean.roastDate) : undefined,
// beanRoastingType: NOT IMPLEMENTED
// degreeOfRoast: NOT IMPLEMENTED
// roast: NOT IMPLEMENTED
beanMix: getBeanMix(bean.varieties.length),
weight: bean.weight ?? undefined,
cost: bean.price ?? undefined,
// flavourProfile: // TODO: add this to the frontend
// cuppingPoints: NOT IMPLEMENTED
// decaffeinated: bean.isDecaf // TODO: add this too
notes: bean.notes ?? undefined,
varietyInformation: getVarietyInformation(bean.varieties),
};
}

/**
* Represents a section where the Beanconqueror QR code can be rendered
* @param url
Expand All @@ -111,8 +38,8 @@ function QRCodeSection({ url }: { url: string }) {

const onButtonClick = async () => {
try {
const beanlink = await getBeankLink(url);
setShareUrl(beanlink);
const beanlink = await getBeanLink(url);
setShareUrl(beanlink.link);
setShow(true);
toast({
title: "Success",
Expand Down Expand Up @@ -142,96 +69,3 @@ function QRCodeSection({ url }: { url: string }) {
</>
);
}

/**
* Container for all the share options
* @param bean
* @constructor
*/
function ShareContainer({ bean }: { bean: BeanDetails }) {
const values = createBeanInformationSchema(bean);

if (!values) {
return null;
}

const shareUrl = createUrlFromFormSchema(values);
const beanstatsText = bean.isPublic
? "This coffee is set to public, so the url can be shared with others."
: "To share this coffee via its url, you have to set it to 'public'.";

return (
<div className={"divide-y space-y-4 max-w-xl"}>
<section className={"space-y-2"}>
<h3 className={"font-semibold mb-1"}>Share via Beanstats link</h3>
<div className={"text-sm text-muted-foreground"}>{beanstatsText}</div>
{bean.isPublic && (
<CopyContainer
value={window.location.toString()}
displayValue={"Copy url"}
/>
)}
</section>
<section className={"space-y-2"}>
<h3 className={"font-semibold mb-1"}>Share with Beanconqueror</h3>
<QRCodeSection url={shareUrl} />
</section>
</div>
);
}

/**
* Share component which renders a shareable link (if public) and the beanconqueror import QR Code
* @param bean
* @constructor
*/
export function ShareComponent({ bean }: { bean: BeanDetails }) {
const [open, setOpen] = useState<boolean>(false);
const isDesktop = useMediaQuery("(min-width: 768px)");

if (bean === null) {
return null;
}

if (isDesktop) {
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button variant={"outline"} size={"sm"}>
Share
</Button>
</DialogTrigger>
<DialogContent className={"sm:max-w-[425px]"}>
<DialogHeader>
<DialogTitle>Share</DialogTitle>
<DialogDescription>Share this coffee.</DialogDescription>
</DialogHeader>
<ShareContainer bean={bean} />
</DialogContent>
</Dialog>
);
}

return (
<Drawer open={open} onOpenChange={setOpen}>
<DrawerTrigger
className={buttonVariants({ variant: "outline", size: "sm" })}
>
Share
</DrawerTrigger>
<DrawerContent>
<DrawerHeader className={"max-w-xl"}>
<DrawerTitle>Share</DrawerTitle>
<DrawerDescription>Share this coffee.</DrawerDescription>
</DrawerHeader>
<DrawerFooter className={"max-w-xl mx-auto"}>
<ShareContainer bean={bean} />
<DrawerClose className={"self-end"}>
<Button variant="outline">Cancel</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
);
}

81 changes: 0 additions & 81 deletions src/components/detail-pages/bean-detail.tsx

This file was deleted.

Loading

0 comments on commit ece7312

Please sign in to comment.