Skip to content

Commit e226b6f

Browse files
Wojtazzzzgrzegorzpokorskitypeofweb
authored
feat: Nowy layout (#196)
Zmiany wprowadzają odświeżony wygląd dla całego serwisu. Layout został zaproponowany w issue #140. Większość styli napisanych w CSS Modules zastała zastąpiona Tailwindem. W kilku miejscach logika z komponentów została wydzielona do hooków. Zostały również wprowadzone kosmetyczne zmiany w panelu administracyjnym. BREAKING CHANGE: Nowy Layout Resolves #140, #183, #111 --------- Co-authored-by: Grzegorz Pokorski <[email protected]> Co-authored-by: Michał Miszczyszyn <[email protected]>
1 parent 32d1953 commit e226b6f

File tree

158 files changed

+5773
-10480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+5773
-10480
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"react/jsx-curly-brace-presence": ["error", "never"],
2020
"jsx-a11y/anchor-is-valid": "off",
2121
"jsx-a11y/no-onchange": "off",
22+
"jsx-a11y/no-redundant-roles": "off",
2223
"import/no-extraneous-dependencies": [
2324
"error",
2425
{

.gitattributes

Lines changed: 0 additions & 3 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ test-results.xml
4242
key
4343
key.pub
4444

45-
icomoon-v1.0/*
46-
!icomoon-v1.0/fonts
47-
!icomoon-v1.0/style.css
48-
!icomoon-v1.0/selection.json
49-
5045
.vercel
5146

5247
# Supabase

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"semi": true,
33
"singleQuote": true,
44
"trailingComma": "all",
5-
"printWidth": 100
5+
"printWidth": 100,
6+
"plugins": ["prettier-plugin-tailwindcss"]
67
}

api-helpers/api-hofs.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ import Boom from '@hapi/boom';
33
import { createServerSupabaseClient } from '@supabase/auth-helpers-nextjs';
44
import { object } from 'yup';
55

6+
import { logger } from './logger';
7+
import { openConnection } from './prisma/db';
8+
import { handlePrismaError, isPrismaError } from './prisma/prisma-helper';
9+
610
import type { Member, PrismaClient, UserRole } from '@prisma/client';
711
import type { User } from '@supabase/auth-helpers-nextjs';
812
import type { IncomingMessage } from 'http';
913
import type { NextApiResponse, NextApiRequest } from 'next';
10-
11-
import { logger } from './logger';
12-
1314
import type { AnySchema, ObjectSchema, InferType } from 'yup';
1415

15-
import { closeConnection, openConnection } from './prisma/db';
16-
import { handlePrismaError, isPrismaError } from './prisma/prisma-helper';
17-
1816
type SomeSchema = Record<string, AnySchema<any, any, any>>;
1917
type AllAllowedFields = 'body' | 'query';
2018

@@ -119,7 +117,7 @@ export const withDb =
119117
res: NextApiResponse,
120118
) => Promise<unknown> | unknown,
121119
) =>
122-
async (req: R, res: NextApiResponse) => {
120+
(req: R, res: NextApiResponse) => {
123121
try {
124122
const prisma = openConnection();
125123
return handler(unsafe__set(req, 'db', prisma), res);
@@ -129,8 +127,6 @@ export const withDb =
129127
} else {
130128
throw err;
131129
}
132-
} finally {
133-
await closeConnection();
134130
}
135131
};
136132

api-helpers/articles.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88

99
import { HTTPNotFound } from './errors';
1010

11-
import type { Blog, PrismaClient } from '@prisma/client';
11+
import type { PrismaClient } from '@prisma/client';
1212

1313
// https://res.cloudinary.com/polskifrontend/image/fetch
1414

@@ -21,12 +21,24 @@ export const getArticlesForGrid = async (prisma: PrismaClient, page: number) =>
2121
orderBy: {
2222
lastArticlePublishedAt: 'desc',
2323
},
24-
include: {
24+
select: {
25+
id: true,
26+
name: true,
27+
href: true,
28+
favicon: true,
2529
articles: {
2630
take: TILES_ARTICLES_PER_BLOG,
2731
orderBy: {
2832
publishedAt: 'desc',
2933
},
34+
select: {
35+
id: true,
36+
title: true,
37+
description: true,
38+
publishedAt: true,
39+
href: true,
40+
slug: true,
41+
},
3042
},
3143
},
3244
});
@@ -69,8 +81,20 @@ export const getArticlesForList = async (prisma: PrismaClient, page: number) =>
6981
orderBy: {
7082
publishedAt: 'desc',
7183
},
72-
include: {
73-
blog: true,
84+
select: {
85+
id: true,
86+
title: true,
87+
description: true,
88+
publishedAt: true,
89+
href: true,
90+
slug: true,
91+
blog: {
92+
select: {
93+
name: true,
94+
href: true,
95+
favicon: true,
96+
},
97+
},
7498
},
7599
});
76100

@@ -111,8 +135,19 @@ export const getArticleBySlug = async (prisma: PrismaClient, slug: string) => {
111135
slug,
112136
blog: { isPublic: true },
113137
},
114-
include: {
115-
blog: true,
138+
select: {
139+
id: true,
140+
description: true,
141+
title: true,
142+
publishedAt: true,
143+
href: true,
144+
blog: {
145+
select: {
146+
href: true,
147+
name: true,
148+
favicon: true,
149+
},
150+
},
116151
},
117152
});
118153

@@ -126,7 +161,7 @@ export const getArticleBySlug = async (prisma: PrismaClient, slug: string) => {
126161
};
127162
};
128163

129-
const replaceFaviconWithCdn = <T extends Blog>(blog: T): T => {
164+
const replaceFaviconWithCdn = <T extends { readonly favicon: string | null }>(blog: T): T => {
130165
return {
131166
...blog,
132167
favicon: blog.favicon ? imageUrlToCdn(blog.favicon) : blog.favicon,

api-helpers/feedFunctions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { EMPTY, firstValueFrom, from, of } from 'rxjs';
88
import { catchError, map, mergeMap, groupBy, last, timeout, filter } from 'rxjs/operators';
99
import Slugify from 'slugify';
1010

11-
import type { Blog, Prisma, PrismaClient } from '@prisma/client';
12-
1311
import {
1412
getBlogName,
1513
getFavicon,
@@ -20,6 +18,8 @@ import { getYouTubeChannelFavicon } from './external-services/youtube';
2018
import { logger } from './logger';
2119
import { streamToRx } from './rxjs-utils';
2220

21+
import type { Blog, Prisma, PrismaClient } from '@prisma/client';
22+
2323
const MAX_CONCURRENCY = 5;
2424
const MAX_FETCHING_TIME = Ms('6 s');
2525

api-helpers/general-feed.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,18 @@ export async function getGeneralFeed(prisma: PrismaClient) {
1515
orderBy: {
1616
updatedAt: 'desc',
1717
},
18-
include: {
19-
blog: true,
18+
select: {
19+
title: true,
20+
description: true,
21+
href: true,
22+
publishedAt: true,
23+
updatedAt: true,
24+
blog: {
25+
select: {
26+
name: true,
27+
href: true,
28+
},
29+
},
2030
},
2131
});
2232

api-helpers/rxjs-utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import { Observable } from 'rxjs';
44
import { distinctUntilChanged } from 'rxjs/operators';
55

6-
import type { Subscription } from 'rxjs';
7-
86
import { logger } from './logger';
97

8+
import type { Subscription } from 'rxjs';
109
import type { Duplex } from 'stream';
1110

1211
export function streamToRx<S extends Duplex = Duplex, T = ReturnType<S['read']>>(
Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import { getLastArticlePage, getLastBlogPage } from '../../../../api-helpers/articles';
2-
import { closeConnection, openConnection } from '../../../../api-helpers/prisma/db';
2+
import { openConnection } from '../../../../api-helpers/prisma/db';
33
import { BlogsGrid } from '../../../../components/BlogsGrid/BlogsGrid';
44
import { BlogsList } from '../../../../components/BlogsList/BlogsList';
5-
import { MAX_PAGES, REVALIDATION_TIME } from '../../../../constants';
65
import { getPagesArray } from '../../../../utils/array-utils';
76

87
import type { DisplayStyle } from '../../../../types';
98

10-
type HomePageProps = {
9+
const MAX_PAGES = 5;
10+
11+
export type HomePageProps = {
1112
readonly params: {
1213
readonly displayStyle: DisplayStyle;
1314
readonly page: string;
1415
};
1516
};
1617

17-
export const revalidate = REVALIDATION_TIME;
18+
export const revalidate = 900; // 15 minutes
1819

1920
export default function HomePage({ params }: HomePageProps) {
2021
const { displayStyle, page } = params;
2122

22-
if (displayStyle === 'grid') {
23+
if (displayStyle !== 'list') {
2324
// @ts-expect-error Server Component
2425
return <BlogsGrid page={page} />;
2526
}
@@ -29,24 +30,20 @@ export default function HomePage({ params }: HomePageProps) {
2930
}
3031

3132
export const generateStaticParams = async () => {
32-
try {
33-
const prisma = openConnection();
33+
const prisma = openConnection();
3434

35-
const [gridLastPage, listLastPage] = await Promise.all([
36-
await getLastBlogPage(prisma),
37-
await getLastArticlePage(prisma),
38-
]);
35+
const [gridLastPage, listLastPage] = await Promise.all([
36+
await getLastBlogPage(prisma),
37+
await getLastArticlePage(prisma),
38+
]);
3939

40-
const gridPages = getPagesArray(gridLastPage, MAX_PAGES);
41-
const listPages = getPagesArray(listLastPage, MAX_PAGES);
40+
const gridPages = getPagesArray(gridLastPage, MAX_PAGES);
41+
const listPages = getPagesArray(listLastPage, MAX_PAGES);
4242

43-
const paths = [
44-
...gridPages.map((page) => ({ displayStyle: 'grid', page })),
45-
...listPages.map((page) => ({ displayStyle: 'list', page })),
46-
];
43+
const paths = [
44+
...gridPages.map((page) => ({ displayStyle: 'grid' as const, page })),
45+
...listPages.map((page) => ({ displayStyle: 'list' as const, page })),
46+
] satisfies readonly HomePageProps['params'][];
4747

48-
return paths;
49-
} finally {
50-
await closeConnection();
51-
}
48+
return paths;
5249
};

0 commit comments

Comments
 (0)