Skip to content

Commit

Permalink
Add dedicated favorites tab
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Sep 23, 2023
1 parent f7b2aca commit af32277
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 177 deletions.
8 changes: 8 additions & 0 deletions apps/web/app/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
InboxIcon,
InformationCircleIcon,
MagnifyingGlassIcon,
StarIcon,
UserGroupIcon,
} from "@heroicons/react/24/outline";
import { Link, useLocation } from "@remix-run/react";
Expand Down Expand Up @@ -55,6 +56,13 @@ export default function Sidebar() {
>
Search
</SidebarLink>
<SidebarLink
to="/favorites"
icon={StarIcon}
active={location.pathname.startsWith("/favorites")}
>
Favorites
</SidebarLink>
<SidebarLink
to="/notifications"
icon={InboxIcon}
Expand Down
11 changes: 11 additions & 0 deletions apps/web/app/components/simpleHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { ReactNode } from "react";

export default function SimpleHeader({ children }: { children?: ReactNode }) {
return (
<div className="p-3 sm:py-0">
<h1 className="mb-4 truncate text-center text-3xl font-semibold leading-7 sm:text-left">
{children}
</h1>
</div>
);
}
54 changes: 54 additions & 0 deletions apps/web/app/routes/favorites.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { json, type LoaderArgs, type V2_MetaFunction } from "@remix-run/node";
import { dehydrate, QueryClient, useQuery } from "@tanstack/react-query";
import invariant from "tiny-invariant";
import BottleTable from "~/components/bottleTable";
import EmptyActivity from "~/components/emptyActivity";

import Layout from "~/components/layout";
import SimpleHeader from "~/components/simpleHeader";
import useApi from "~/hooks/useApi";
import useAuth from "~/hooks/useAuth";
import { redirectToAuth } from "~/lib/auth.server";
import { fetchBottlesInCollection } from "~/queries/collections";

export async function loader({ context, request }: LoaderArgs) {
if (!context.user) return redirectToAuth({ request });

const queryClient = new QueryClient();
await queryClient.prefetchQuery(
["collections", "user", context.user.id, "default"],
() => fetchBottlesInCollection(context.api, "me", "default"),
);

return json({ dehydratedState: dehydrate(queryClient) });
}

export const meta: V2_MetaFunction = () => {
return [
{
title: "Favorites",
},
];
};

export default function Favorites() {
const api = useApi();
const { user } = useAuth();

invariant(user);

const { data } = useQuery(["collections", "user", user.id, "default"], () =>
fetchBottlesInCollection(api, "me", "default"),
);

return (
<Layout>
<SimpleHeader>Favorites</SimpleHeader>
{data && data.results.length ? (
<BottleTable bottleList={data.results} rel={data.rel} />
) : (
<EmptyActivity>No favorites recorded yet.</EmptyActivity>
)}
</Layout>
);
}
163 changes: 0 additions & 163 deletions apps/web/app/routes/friends._index.tsx

This file was deleted.

Loading

0 comments on commit af32277

Please sign in to comment.