Skip to content

Commit

Permalink
feat: worked on news grid view
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrusegard committed Jan 24, 2024
1 parent 41da5cf commit 918c409
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 8 deletions.
3 changes: 3 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
"NTNUKiD": "The working life network KID",
"copyright": "Copyright",
"allRightsReserved": "All rights reserved"
},
"news": {
"title": "News"
}
}
3 changes: 3 additions & 0 deletions messages/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
"NTNUKiD": "Arbeidslivsnettverket KID",
"copyright": "Opphavsrett",
"allRightsReserved": "Alle rettigheter reservert"
},
"news": {
"title": "Nyheter"
}
}
Binary file added public/mock.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 52 additions & 1 deletion src/app/[locale]/(dashboard)/news/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { useTranslations } from 'next-intl';
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';

import { cx } from '@/lib/utils';

import { NewsCard } from '@/components/news/NewsCard';

export async function generateMetadata({
params: { locale },
}: {
Expand All @@ -17,6 +22,52 @@ export default function News({
}: {
params: { locale: string };
}) {
const mockData = [
{
id: 1,
title: 'Gruppe status: prosjekt spill',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 2,
title: 'DevOps Møtet',
date: '69. oktober 6969',
photoUrl: 'mock.jpg',
},
{
id: 3,
title: 'Jonas er kul',
date: '42. november 2023',
photoUrl: 'mock.jpg',
},
{
id: 4,
title: 'Iskrem er godt',
date: '18. februar 1942',
photoUrl: 'mock.jpg',
},
];
unstable_setRequestLocale(locale);
return <div>this should be news page</div>;
const t = useTranslations('news');
return (
<>
<h1 className='my-4'>{t('title')}</h1>
<div className='grid h-full max-h-144 min-h-160 grid-rows-4 gap-4 xs:h-1/2 xs:min-h-80 xs:grid-cols-3 xs:grid-rows-2 md:grid-cols-4 lg:h-3/5'>
{mockData.slice(0, 4).map((data, index) => (
<NewsCard
className={cx(
index === 0 && 'row-span-1 xs:col-span-2 md:row-span-2',
index === 1 && 'col-span-1 row-span-1 md:col-span-2',
index === 3 && 'row-span-1 xs:col-span-2 md:col-span-1',
)}
key={data.id}
title={data.title}
date={data.date}
photoUrl={data.photoUrl}
/>
))}
</div>
</>
);
}
2 changes: 1 addition & 1 deletion src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function Localelayout({ children, params: { locale } }: Props) {
>
<body className='h-full w-full bg-background font-inter text-foreground antialiased'>
<RootProviders params={{ locale: locale }}>
<div className='fixed bottom-0 top-0 flex h-full w-full flex-col overflow-y-scroll scroll-smooth scrollbar-thin scrollbar-track-background scrollbar-thumb-primary/40 scrollbar-corner-background scrollbar-thumb-rounded-lg hover:scrollbar-thumb-primary/80'>
<div className='fixed bottom-0 top-0 h-full w-full overflow-y-scroll scroll-smooth scrollbar-thin scrollbar-track-background scrollbar-thumb-primary/40 scrollbar-corner-background scrollbar-thumb-rounded-lg hover:scrollbar-thumb-primary/80'>
{children}
</div>
</RootProviders>
Expand Down
7 changes: 1 addition & 6 deletions src/components/layout/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ type Props = {

function Main({ children, mainClassName, className }: Props) {
return (
<main
className={cx(
'flex h-full w-full flex-grow justify-center',
mainClassName,
)}
>
<main className={cx('flex h-full w-full justify-center', mainClassName)}>
<div
className={cx(
'h-full w-full max-w-screen-2xl px-4 sm:px-11 md:px-16 lg:px-24',
Expand Down
38 changes: 38 additions & 0 deletions src/components/news/NewsCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { cx } from '@/lib/utils';

import {
Card,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/Card';

type NewsCardProps = {
className?: string;
title: string;
date: string;
photoUrl: string;
};

function NewsCard({ className, title, date, photoUrl }: NewsCardProps) {
return (
<Card
className={cx(
'flex h-full min-h-32 w-full bg-cover bg-center',
className,
)}
style={{ backgroundImage: `url(/${photoUrl})` }}
>
<CardHeader className='mt-auto w-full bg-background/95 p-4 backdrop-blur supports-[backdrop-filter]:bg-background/60 lg:p-6'>
<CardTitle className='line-clamp-1 text-lg sm:text-xl lg:text-2xl'>
{title}
</CardTitle>
<CardDescription className='line-clamp-1 text-xs sm:text-sm'>
{date}
</CardDescription>
</CardHeader>
</Card>
);
}

export { NewsCard };
86 changes: 86 additions & 0 deletions src/components/ui/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import * as React from 'react';

import { cx } from '@/lib/utils';

const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cx(
'rounded-lg border bg-card text-card-foreground shadow-sm',
className,
)}
{...props}
/>
));
Card.displayName = 'Card';

const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cx('flex flex-col space-y-1.5 p-6', className)}
{...props}
/>
));
CardHeader.displayName = 'CardHeader';

const CardTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h3
ref={ref}
className={cx(
'text-2xl font-semibold leading-none tracking-tight',
className,
)}
{...props}
/>
));
CardTitle.displayName = 'CardTitle';

const CardDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p
ref={ref}
className={cx('text-sm text-muted-foreground', className)}
{...props}
/>
));
CardDescription.displayName = 'CardDescription';

const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cx('p-6 pt-0', className)} {...props} />
));
CardContent.displayName = 'CardContent';

const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cx('flex items-center p-6 pt-0', className)}
{...props}
/>
));
CardFooter.displayName = 'CardFooter';

export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardDescription,
CardContent,
};
18 changes: 18 additions & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ export default {
'3-auto': 'repeat(3, auto)',
'2-auto': 'repeat(2, auto)',
},
minHeight: {
'104': '26rem',
'112': '28rem',
'120': '30rem',
'128': '32rem',
'144': '36rem',
'160': '40rem',
'192': '48rem',
},
maxHeight: {
'104': '26rem',
'112': '28rem',
'120': '30rem',
'128': '32rem',
'144': '36rem',
'160': '40rem',
'192': '48rem',
},
},
},
plugins: [
Expand Down

0 comments on commit 918c409

Please sign in to comment.