Skip to content

Commit

Permalink
feat(web): document title
Browse files Browse the repository at this point in the history
  • Loading branch information
betofigueiredo committed Apr 6, 2024
1 parent 6c32e41 commit c5c1f69
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 41 deletions.
4 changes: 2 additions & 2 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Drinquepedia</title>
<title>Drinquepedia | Things go better with a cocktail!</title>
</head>
<body>
<div id="root"></div>
Expand Down
20 changes: 2 additions & 18 deletions web/src/components/DrinksList/DrinksList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Drink } from "@/types/drink";
import Pagination from "@/components/Pagination";
import DrinkRow from "@/components/DrinkRow";
import getCategoryName from "@/utils/getCategoryName";

const DrinksList = ({
drinks,
Expand All @@ -15,23 +16,6 @@ const DrinksList = ({
page: number;
perPage: number;
}) => {
const getCategoryName = (): string => {
const categories: { [key: string]: string } = {
martinis: "Martinis",
tropicais: "Tropicais",
frozen: "Frozen",
quentes: "Quentes",
shot: "Shots",
classicos: "Clássicos",
semalcool: "Sem Álcool",
caipirinhas: "Caipirinhas clássicas",
smoothies: "Smoothies",
};
return (
categories[category as keyof typeof categories] || "Todos os drinques"
);
};

const drinksList =
category === "caipirinhas"
? drinks?.filter((drink) =>
Expand All @@ -49,7 +33,7 @@ const DrinksList = ({
return (
<div>
<h1 className="mb-0 mt-14 font-serif text-3xl font-bold text-gray-700">
{getCategoryName()}
{getCategoryName(category)}
</h1>
<div className="mb-12 text-gray-500">{count} drinques</div>
{drinksList?.map((drink) => <DrinkRow key={drink.id} drink={drink} />)}
Expand Down
3 changes: 3 additions & 0 deletions web/src/pages/Drink/Drink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useParams } from "react-router-dom";
import { useDocumentTitle } from "usehooks-ts";
import useGetDrink from "@/api/useGetDrink";
import Errors from "@/components/Errors";
import Loadings from "@/components/Loadings";
Expand All @@ -9,6 +10,8 @@ const Drink = () => {
const { drinkId } = useParams();
const { isPending, error, data: drink } = useGetDrink(drinkId);

useDocumentTitle(drink ? `${drink?.name} - Drinquepedia` : "Drinquepedia");

if (isPending) {
return (
<div className="container pt-3 leading-relaxed">
Expand Down
4 changes: 4 additions & 0 deletions web/src/pages/Drinks/Drinks.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useSearchParams } from "react-router-dom";
import { useDocumentTitle } from "usehooks-ts";
import useGetDrinks from "@/api/useGetDrinks";
import SearchBar from "@/components/SearchBar";
import DrinksList from "@/components/DrinksList";
import DrinksListHighlights from "@/components/DrinksListHighlights";
import Loadings from "@/components/Loadings";
import Errors from "@/components/Errors";
import getCategoryName from "@/utils/getCategoryName";

const Drinks = ({ category }: { category?: string }) => {
const perPage = category === "caipirinhas" ? 50 : 20;
Expand All @@ -22,6 +24,8 @@ const Drinks = ({ category }: { category?: string }) => {
alcoholicContent,
});

useDocumentTitle(`${getCategoryName(category)} - Drinquepedia`);

return (
<>
{!category && <SearchBar />}
Expand Down
8 changes: 6 additions & 2 deletions web/src/pages/Highlight/Highlight.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Link, useParams } from "react-router-dom";
import { useDocumentTitle } from "usehooks-ts";
import useGetHighlight from "@/api/useGetHighlight";
import Errors from "@/components/Errors";
import Loadings from "@/components/Loadings";
Expand All @@ -8,6 +9,11 @@ import { Button } from "@/components/ui/button";
const Highlight = () => {
const { highlightId } = useParams();
const { isPending, error, data } = useGetHighlight({ highlightId });
const highlight = data?.highlight;

useDocumentTitle(
highlight ? `${highlight.title} - Drinquepedia` : "Drinquepedia",
);

if (isPending) {
return (
Expand All @@ -21,8 +27,6 @@ const Highlight = () => {
return <Errors />;
}

const highlight = data?.highlight;

return (
<div className="container mt-2">
<Breadcrumbs />
Expand Down
3 changes: 3 additions & 0 deletions web/src/pages/Highlights/Highlights.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useDocumentTitle } from "usehooks-ts";
import useGetHighlights from "@/api/useGetHighlights";
import Errors from "@/components/Errors";
import Loadings from "@/components/Loadings";
Expand All @@ -6,6 +7,8 @@ import HighlightCard from "@/components/HighlightCard";
const Highlights = () => {
const { isPending, error, data } = useGetHighlights();

useDocumentTitle("Destaques - Drinquepedia");

if (isPending) {
return (
<div className="container">
Expand Down
33 changes: 19 additions & 14 deletions web/src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { useDocumentTitle } from "usehooks-ts";
import FeaturedHighlights from "@/components/FeaturedHighlights";
import SecondHighlights from "@/components/SecondHighlights";
import ThirdHighlights from "@/components/ThirdHighlights";
import FourthHighlights from "@/components/FourthHighlights";

const Home = () => (
<>
<div className="container">
<FeaturedHighlights />
<SecondHighlights />
</div>
<div className="my-24 w-full bg-gray-100">
<ThirdHighlights />
</div>
<div className="container">
<FourthHighlights />
</div>
</>
);
const Home = () => {
useDocumentTitle("Drinquepedia | Things go better with a cocktail!");

return (
<>
<div className="container">
<FeaturedHighlights />
<SecondHighlights />
</div>
<div className="my-24 w-full bg-gray-100">
<ThirdHighlights />
</div>
<div className="container">
<FourthHighlights />
</div>
</>
);
};

export default Home;
8 changes: 6 additions & 2 deletions web/src/pages/Instruction/Instruction.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useParams } from "react-router-dom";
import { useDocumentTitle } from "usehooks-ts";
import useGetInstruction from "@/api/useGetInstruction";
import Errors from "@/components/Errors";
import Loadings from "@/components/Loadings";
Expand All @@ -7,6 +8,11 @@ import Breadcrumbs from "@/components/Breadcrumbs";
const Instruction = () => {
const { instructionId } = useParams();
const { isPending, error, data } = useGetInstruction({ instructionId });
const instruction = data?.instruction;

useDocumentTitle(
instruction ? `${instruction.title} - Drinquepedia` : "Drinquepedia",
);

if (isPending) {
return (
Expand All @@ -20,8 +26,6 @@ const Instruction = () => {
return <Errors />;
}

const instruction = data?.instruction;

return (
<div className="container mt-2">
<Breadcrumbs />
Expand Down
3 changes: 3 additions & 0 deletions web/src/pages/Instructions/Instructions.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useDocumentTitle } from "usehooks-ts";
import useGetInstructions from "@/api/useGetInstructions";
import Errors from "@/components/Errors";
import Loadings from "@/components/Loadings";
Expand All @@ -6,6 +7,8 @@ import InstructionCard from "@/components/InstructionCard";
const Instructions = () => {
const { isPending, error, data } = useGetInstructions();

useDocumentTitle("Dicas - Drinquepedia");

if (isPending) {
return (
<div className="container">
Expand Down
10 changes: 7 additions & 3 deletions web/src/pages/Knowledge/Knowledge.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { useParams } from "react-router-dom";
import { useDocumentTitle } from "usehooks-ts";
import useGetKnowledge from "@/api/useGetKnowledge";
import Breadcrumbs from "@/components/Breadcrumbs";
import Errors from "@/components/Errors";
import Loadings from "@/components/Loadings";
import { useParams } from "react-router-dom";

const Knowledge = () => {
const { knowledgeSlug } = useParams();
const { isPending, error, data } = useGetKnowledge({ knowledgeSlug });
const knowledge = data?.knowledge;

useDocumentTitle(
knowledge ? `${knowledge.title} - Drinquepedia` : "Drinquepedia",
);

if (isPending) {
return (
Expand All @@ -20,8 +26,6 @@ const Knowledge = () => {
return <Errors />;
}

const knowledge = data?.knowledge;

return (
<div className="container mt-2">
<Breadcrumbs />
Expand Down
3 changes: 3 additions & 0 deletions web/src/pages/Knowledges/Knowledges.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import useGetKnowledges from "@/api/useGetKnowledges";
import { useDocumentTitle } from "usehooks-ts";
import Errors from "@/components/Errors";
import Loadings from "@/components/Loadings";
import KnowledgeCard from "@/components/KnowledgeCard";

const Knowledges = () => {
const { isPending, error, data } = useGetKnowledges();

useDocumentTitle("Tudo sobre bar - Drinquepedia");

if (isPending) {
return (
<div className="container">
Expand Down
16 changes: 16 additions & 0 deletions web/src/utils/getCategoryName/getCategoryName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const getCategoryName = (category?: string): string => {
const categories: { [key: string]: string } = {
martinis: "Martinis",
tropicais: "Tropicais",
frozen: "Frozen",
quentes: "Quentes",
shot: "Shots",
classicos: "Clássicos",
semalcool: "Sem Álcool",
caipirinhas: "Caipirinhas clássicas",
smoothies: "Smoothies",
};
return categories[category as keyof typeof categories] || "Drinques de A a Z";
};

export default getCategoryName;
1 change: 1 addition & 0 deletions web/src/utils/getCategoryName/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./getCategoryName";

0 comments on commit c5c1f69

Please sign in to comment.