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

Responsive wine list #57

Merged
merged 2 commits into from
Oct 30, 2023
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
11 changes: 10 additions & 1 deletion vinoa-web/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ body {
display: flex;
flex-direction: column;
min-height: 100vh;
@apply font-["Noto"];
}

h1,
Expand All @@ -16,13 +17,21 @@ h3,
h4,
h5,
h6 {
@apply text-2xl;
@apply font-["Noto"];
}
p {
@apply font-["Julius"];
}

nav li {
@apply bg-[#F5F5F5];
@apply rounded-md;
@apply px-4;
@apply py-2;
}

button {
@apply bg-[#F5F5F5];
@apply px-3;
@apply py-1;
}
20 changes: 5 additions & 15 deletions vinoa-web/app/wines/page.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import WineListCard from '@/components/WineListCard';
import WineList from '@/components/WineList';
import { getTags } from '@/sanity/sanity-utils/tag-utils';
import { getWines } from '@/sanity/sanity-utils/wine-utils';

export const dynamic = 'force-dynamic';

const WinesPage = async () => {
const wines: Wine[] = await getWines();
return (
<div>
<h1>Wine Page</h1>
<ul>
{wines.map((wine) => (
<li key={wine._id}>
<WineListCard wine={wine}></WineListCard>
</li>
))}
</ul>
</div>
);
const wines = await getWines();
const tags: string[] = await getTags();
return <WineList wines={wines} tags={tags} />;
};

export default WinesPage;
2 changes: 1 addition & 1 deletion vinoa-web/components/Rating/Rating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Rating = ({ label, rating, maxRating = 5, setRating }: RatingProps) => {
onClick={handleOnClick}
key={i}
className={
'text-wine-red z-0 text-xl' +
'text-wine-red z-0 text-sm md:text-xl' +
(setRating ? ' cursor-pointer' : '')
}
/>
Expand Down
66 changes: 66 additions & 0 deletions vinoa-web/components/WineList/WineList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use client';
import WineListCard from '../WineListCard';
import { useState } from 'react';

interface Props {
wines: Wine[];
tags: string[];
}

const WineList = ({ wines, tags }: Props) => {
const [activeFilter, setActiveFilter] = useState('all');
const [winesToShow, setWinesToShow] = useState(wines);

const handleOnClick = (tag: string) => {
setActiveFilter(tag);
if (tag === 'all') {
setWinesToShow(wines);
} else {
const filteredWines = wines.filter((wine) => wine.tag == tag);
setWinesToShow(filteredWines);
setActiveFilter(tag);
}
};
console.log(tags);
return (
<div>
<div>
<ul className='flex flex-row justify-center md:justify-start text-xs md:text-base md:pl-8 pb-6'>
<li className='m-2'>
<button
onClick={() => handleOnClick('all')}
className={`${'all' == activeFilter && 'ring-2 ring-black '} ${
'all' != activeFilter &&
'hover:underline-offset-4 hover:underline'
} `}
>
All wines
</button>
</li>
{tags.map((tag, idx) => (
<li className='m-2' key={idx}>
<button
className={`${tag == activeFilter && 'ring-2 ring-black '} ${
tag != activeFilter &&
'hover:underline-offset-4 hover:underline'
} `}
onClick={() => handleOnClick(tag)}
>
{tag}
</button>
</li>
))}
</ul>
</div>

<ul className='flex flex-col md:justify-items-center gap-4 items-center lg:grid lg:grid-cols-2 mx-4 lg:mx-8'>
{winesToShow.map((wine) => (
<li className='w-full md:w-auto lg:w-full mb-6' key={wine._id}>
<WineListCard wine={wine}></WineListCard>
</li>
))}
</ul>
</div>
);
};
export default WineList;
2 changes: 2 additions & 0 deletions vinoa-web/components/WineList/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import WineList from './WineList';
export default WineList;
54 changes: 38 additions & 16 deletions vinoa-web/components/WineListCard/WineListCard.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
'use client';
import Image from 'next/image';
import Link from 'next/link';
import Rating from '../Rating';
import { getReviewsForWine } from '@/sanity/sanity-utils/review-utils';
import { getAverageRating } from '@/lib/utils/helperFunctions';
import { use, useEffect, useState } from 'react';
import user from '@/sanity/schemas/user';
interface WineProps {
wine: Wine;
}
const WineListCard = ({
wine: { name, imageUrl, country, region, smell, taste, body, slug },
wine: { name, imageUrl, country, region, smell, taste, body, slug, price },
}: WineProps) => {
const [reviews, setReviews] = useState([] as Review[]);

useEffect(() => {
const fetchReviews = async () => {
const reviewsFetched = await getReviewsForWine(slug);
setReviews(reviewsFetched);
};
fetchReviews();
}, []);

const averageRating = getAverageRating(reviews);
return (
<Link href={`/wines/${slug}`}>
<div className='bg-violet-dark m-4 p-4 flex flex-row'>
<div>
<div className='h-56 lg:h-60 md:w-[28rem] grid grid-cols-2 bg-grey-highlight rounded-xl p-2 shadow-[4px_4px_4px_rgba(0,0.30,0.30,0.30)]'>
<div className='w-28 h-[13rem] lg:h-56 lg:w-36 relative'>
<Image
width={160}
height={160}
className='rounded-xl'
alt='Image of a wine bottle'
src={`${imageUrl}`}
layout='fill'
objectFit='cover'
/>

<p>Rating</p>
<p>1/5</p>
</div>
<div className='px-5'>
<h1 className='text-2xl pb-4'>{name}</h1>
<div className='flex flex-col grow h-auto'>
<p>Country: {country}</p>
<p>Region: {region}</p>
<p>Body: {body}</p>
<p>Smell: {smell}</p>
<p>Taste: {taste}</p>
<div className='text-xs md:text-base justify-between flex flex-col gap-4'>
<h1 className='text-sm md:text-xl'>{name}</h1>
<div className='grid grid-cols-2 text-xs uppercase'>
<p className='font-semibold'>Taste</p> <p>{taste}</p>
<p className='font-semibold'>Aroma</p> <p>{smell}</p>
<p className='font-semibold'>Body</p> <p>{body}</p>
</div>
<div className='grid grid-cols-2 '>
<div className='place-self-start self-end'>
<Rating rating={averageRating} />
</div>
{price && (
<div className='place-self-end'>
<p className='text-wine-red font-bold'>{price} NOK</p>
</div>
)}
</div>
</div>
</div>
Expand Down
16 changes: 16 additions & 0 deletions vinoa-web/sanity/sanity-utils/tag-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { groq } from 'next-sanity';
import client from '../sanityClient';

export const getTags = async () => {
const tags = await client.fetch(
groq`*[_type == "tag"]{
name
}`,
{},
{
cache: 'no-store',
}
);
const tagNames = tags.map((tag: any) => tag.name);
return tagNames;
};
2 changes: 0 additions & 2 deletions vinoa-web/sanity/sanity-utils/wine-utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { groq } from 'next-sanity';
import client from '../sanityClient';



export async function getWines(): Promise<Array<Wine>> {
const wines: Array<Wine> = await client.fetch(
groq`*[_type == "wine"]{
Expand Down
11 changes: 11 additions & 0 deletions vinoa-web/store/wine-store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { create } from 'zustand';

interface WineStore {
wines: Wine[];
setWines: (wines: Wine[]) => void;
}

export const useWineStore = create<WineStore>()((set) => ({
wines: Array<Wine>(),
setWines: (wines) => set({ wines }),
}));
2 changes: 1 addition & 1 deletion vinoa-web/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
'violet-light': '#322E59',

// new colors
'grey-highlight': '#F5F5F5',
'grey-highlight': '#E6E6E6',
'wine-violet': '#19082E',
'wine-red': '#8C0B0F',
},
Expand Down
Loading