Skip to content

Commit

Permalink
Merge pull request #24 from hackerspace-ntnu/22-feat-create-individua…
Browse files Browse the repository at this point in the history
…l-news-article-pages

22 feat create individual news article pages
  • Loading branch information
michaelbrusegard authored Feb 7, 2024
2 parents e5a61a9 + eff20dd commit 7e48e02
Show file tree
Hide file tree
Showing 48 changed files with 987 additions and 671 deletions.
3 changes: 0 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ next-env.d.ts
public/sitemap.xml
public/robots.txt

# prettier
prettier.config.js

# docker
Dockerfile*
.dockerignore
Expand Down
3 changes: 1 addition & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ const config = {
'next/core-web-vitals',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:prettier/recommended',
],
rules: {
// These opinionated rules are enabled in stylistic-type-checked above.
// Feel free to reconfigure them to your own preference.
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Lint and Format
name: Lint

on: push
jobs:
lint-and-format:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -11,4 +11,3 @@ jobs:
bun-version: 1.0.24
- run: bun install
- run: bun lint
- run: bun format
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules

Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"bradlc.vscode-tailwindcss",
"lokalise.i18n-ally",
"vivaxy.vscode-conventional-commits",
Expand Down
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
],
"i18n-ally.localesPaths": ["messages"],
"i18n-ally.keystyle": "nested",
"codeQL.githubDatabase.download": "never"
"i18n-ally.keystyle": "nested"
}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM imbios/bun-node:20-alpine
FROM imbios/bun-node:20-slim

WORKDIR /app

COPY package.json bun.lockb ./

RUN bun install --frozen-lockfile --production
RUN bun install --production

COPY . .

Expand Down
20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,12 @@ Then to serve the build locally, run:
bun run start
```

## Check linting, formatting and types
## Check linting and formatting

To check linting, formatting or types you run the respective command:

Linting:

```bash
bun run lint
```

Formatting:

```bash
bun run format
```

Types:
To check linting and formatting you run the respective command:

```bash
bun run type
bun lint
```

If you are using vscode and are experiencing issues with types, you can restart the typescript server by pressing `cmd + shift + p` and then type `TypeScript: Restart TS Server` (You need to have a typescript file open for this to work).
Expand Down
Binary file modified bun.lockb
Binary file not shown.
8 changes: 5 additions & 3 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"goToPreviousPage": "Go to previous page",
"next": "Next",
"goToNextPage": "Go to next page",
"morePages": "More pages"
"morePages": "More pages",
"page": "page"
},
"layout": {
"hackerspaceHome": "Hackerspace homepage",
Expand Down Expand Up @@ -42,8 +43,9 @@
},
"news": {
"title": "News",
"page": "Page",
"internalArticle": "This is an internal article",
"newArticle": "New article"
"newArticle": "New article",
"readTime": "{count, plural, =0 {less than a minute} one {# minute} other {# minutes}} read",
"views": "Views"
}
}
8 changes: 5 additions & 3 deletions messages/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"goToPreviousPage": "Gå til forrige side",
"next": "Neste",
"goToNextPage": "Gå til neste side",
"morePages": "Flere sider"
"morePages": "Flere sider",
"page": "side"
},
"layout": {
"hackerspaceHome": "Hackerspace hjemmeside",
Expand Down Expand Up @@ -42,8 +43,9 @@
},
"news": {
"title": "Nyheter",
"page": "Side",
"internalArticle": "Dette er en intern artikkel",
"newArticle": "Ny artikkel"
"newArticle": "Ny artikkel",
"readTime": "{count, plural, =0 {mindre enn ett minutt} one {# minutt} other {# minutter}} read",
"views": "Visninger"
}
}
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@
"build": "next build",
"dev": "next dev",
"lint": "next lint",
"format": "prettier --check '**/*.{js,cjs,ts,tsx}'",
"type": "tsc --noEmit",
"start": "next start"
},
"lint-staged": {
"*.{js,cjs,ts,tsx}": [
"eslint --fix",
"prettier --write"
"eslint --fix"
]
},
"dependencies": {
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-separator": "^1.0.3",
Expand All @@ -30,6 +28,7 @@
"clsx": "^2.1.0",
"country-flag-icons": "^1.5.9",
"cva": "^1.0.0-beta.1",
"husky": "^9.0.10",
"lucide-react": "^0.312.0",
"next": "^14.0.4",
"next-intl": "^3.4.4",
Expand All @@ -38,9 +37,9 @@
"nuqs": "^1.15.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"reading-time": "^1.5.0",
"sharp": "^0.33.2",
"tailwind-merge": "^2.2.0",
"tailwind-scrollbar": "^3.0.5",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.22.4"
},
"devDependencies": {
Expand All @@ -53,12 +52,15 @@
"@typescript-eslint/parser": "^6.11.0",
"eslint": "^8.54.0",
"eslint-config-next": "^14.0.4",
"husky": "^8.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"lint-staged": "^15.2.0",
"postcss": "^8.4.31",
"prettier": "^3.1.0",
"prettier-plugin-tailwindcss": "^0.5.7",
"tailwind-scrollbar": "^3.0.5",
"tailwindcss": "^3.3.5",
"tailwindcss-animate": "^1.0.7",
"typescript": "^5.1.6"
},
"packageManager": "[email protected]"
Expand Down
Binary file added public/authorMock.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 17 additions & 17 deletions public/favicon/site.webmanifest
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "",
"short_name": "",
"icons": [
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#0c0a09",
"background_color": "#0c0a09",
"display": "standalone"
"name": "Hackerspace NTNU",
"short_name": "Hackerspace",
"icons": [
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#0c0a09",
"background_color": "#0c0a09",
"display": "standalone"
}
13 changes: 7 additions & 6 deletions src/app/[locale]/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { unstable_setRequestLocale } from 'next-intl/server';
import { type ReactNode } from 'react';

import { Footer } from '@/components/layout/Footer';
import { Header } from '@/components/layout/Header';
import { Main } from '@/components/layout/Main';

export default function Dashboardlayout({
type DashboardProps = {
children: React.ReactNode;
params: { locale: string };
};

export default function Dashboard({
children,
params: { locale },
}: {
children: ReactNode;
params: { locale: string };
}) {
}: DashboardProps) {
unstable_setRequestLocale(locale);
return (
<>
Expand Down
34 changes: 34 additions & 0 deletions src/app/[locale]/(dashboard)/news/(header)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { SquarePen } from 'lucide-react';
import { useTranslations } from 'next-intl';
import { unstable_setRequestLocale } from 'next-intl/server';

import { Link } from '@/lib/navigation';

import { Button } from '@/components/ui/Button';

type NewsHeaderProps = {
children: React.ReactNode;
params: { locale: string };
};

export default function NewsHeader({
children,
params: { locale },
}: NewsHeaderProps) {
unstable_setRequestLocale(locale);
const t = useTranslations('news');
return (
<>
<div className='flex items-center justify-between'>
<h1 className='my-4'>{t('title')}</h1>
<Button asChild size='sm'>
<Link href='/news/new'>
<SquarePen className='mr-2 h-4 w-4' />
{t('newArticle')}
</Link>
</Button>
</div>
{children}
</>
);
}
15 changes: 15 additions & 0 deletions src/app/[locale]/(dashboard)/news/(header)/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { PaginationCarouselSkeleton } from '@/components/layout/PaginationCarouselSkeleton';
import { CardGridSkeleton } from '@/components/news/CardGridSkeleton';
import { ItemGridSkeleton } from '@/components/news/ItemGridSkeleton';
import { Separator } from '@/components/ui/Separator';

export default function NewsSkeleton() {
return (
<>
<CardGridSkeleton />
<Separator className='my-6' />
<ItemGridSkeleton />
<PaginationCarouselSkeleton className='my-6' />
</>
);
}
61 changes: 61 additions & 0 deletions src/app/[locale]/(dashboard)/news/(header)/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { articleMockData as articleData } from '@/mock-data/article';
import { useTranslations } from 'next-intl';
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';
import { createSearchParamsCache, parseAsInteger } from 'nuqs/parsers';
import { Suspense } from 'react';

import { PaginationCarousel } from '@/components/layout/PaginationCarousel';
import { CardGrid } from '@/components/news/CardGrid';
import { ItemGrid } from '@/components/news/ItemGrid';
import { ItemGridSkeleton } from '@/components/news/ItemGridSkeleton';
import { Separator } from '@/components/ui/Separator';

export async function generateMetadata({
params: { locale },
}: {
params: { locale: string };
}) {
const t = await getTranslations({ locale, namespace: 'layout' });

return {
title: t('news'),
};
}

export default function News({
params: { locale },
searchParams,
}: {
params: { locale: string };
searchParams: Record<string, string | string[] | undefined>;
}) {
unstable_setRequestLocale(locale);
const t = useTranslations('ui');
const searchParamsCache = createSearchParamsCache({
[t('page')]: parseAsInteger.withDefault(1),
});

const { [t('page')]: page = 1 } = searchParamsCache.parse(searchParams);
// TODO: Button to create new article should only be visible when logged in
return (
<>
<CardGrid topArticles={articleData.slice(0, 4)} />
<Separator className='my-6' />
<Suspense key={page} fallback={<ItemGridSkeleton />}>
<ItemGrid page={page} />
</Suspense>
<PaginationCarousel
className='my-6'
totalPages={Math.ceil(articleData.length / 6)}
t={{
goToPreviousPage: t('goToPreviousPage'),
previous: t('previous'),
morePages: t('morePages'),
goToNextPage: t('goToNextPage'),
next: t('next'),
page: t('page'),
}}
/>
</>
);
}
Loading

0 comments on commit 7e48e02

Please sign in to comment.