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

Migrate to Next.js 14 app directory #156

Merged
merged 88 commits into from
Jan 5, 2024
Merged

Migrate to Next.js 14 app directory #156

merged 88 commits into from
Jan 5, 2024

Conversation

ProchaLu
Copy link
Member

@ProchaLu ProchaLu commented Jan 2, 2024

Closes #152

This PR migrates the portfolio to Next.js 14 and the app directory structure. It imports the necessary changes from the original portfolio and fixes any errors encountered during the process.

TODO

Compare the current changes with the upstream repo:

https://github.com/vickonrails/next-starter-peacock/compare/vickonrails:next-starter-peacock:master...upleveled:next-starter-peacock:update-to-next-14?diff=unified&w=

dependabot bot and others added 30 commits April 29, 2021 09:05
Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8.
- [Release notes](https://github.com/isaacs/ini/releases)
- [Commits](npm/ini@v1.3.5...v1.3.8)

Signed-off-by: dependabot[bot] <[email protected]>
…-6.5.4

chore(deps): bump elliptic from 6.5.3 to 6.5.4
<ul className="list-none flex flex-wrap pl-0">
{items.map((tag) => (
<li
key={`items-${tag}`}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used template literals including prefixes for the values of key props

`;

const ExperimentItem = ({ experiment }: Props) => {
export function ExperimentItem({ experiment }: { experiment: Experiment }) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added new created type from line 9 to avoid any

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +1 to +2
import { AllHTMLAttributes } from 'react';
import { cn } from '../utils/cn';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed imported HTMLAttributes since it is never used, and changed to relative imports

<a
href="https://github.com/vickOnRails/next-starter-peacock"
target="_blank"
rel="noopener noreferrer"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed typo from norefferrer to noreferrer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any of these changes can also be a separate new PR to upstream

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (external) {
return (
<a
data-test-id={dataTestId}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add data-test-id for Playwright testing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed all data-test-ids

24018f3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    await page
      .locator('div:has-text("WorksArticlesNotesAbout") a')
      .nth(4)
      .getAttribute('href'),
  • doesn't it make more sense to use nav here instead of div? it seems there are 2 navs, be sure to write a good selector that will select the correct one
  • I guess using the .nth() is also a bit brittle
  • probably you can do a better version using just page.locator(...).getAttribute('href')

{notes.map((note) => (
<Note
key={`note-${note.id}`}
id={note.id}
key={`note-${note.slug}`}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used template literals including prefixes for the values of key props

import { IContent } from '../../utils/content';

// TODO: use some type of hash function to generate the colors
const colorsLookup = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed COLORS_LOOKUP to camelCase colorsLookup

href={`/works/${slug}`}
className={cn(
'group rounded-xl select-none no-underline flex flex-col lg:py-10 w-full md:flex-row transition-transform hover:cursor-pointer hover:scale-[102%] active:scale-95',
colorsLookup[slug as keyof typeof colorsLookup],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a type to avoid any. slug is cast to the type keyof typeof colorsLookup, telling TS that the slug is a key of the colorsLookup object.

@@ -0,0 +1,31 @@
import { IContentType } from './content';

export const contentTypesMap: Map<IContentType, any> = new Map([
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed variable CONTENT_TYPES_MAP to use camelCase

Comment on lines 1 to 2
import fs from 'node:fs';
import path from 'node:path';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the imports from import fs form 'fs' to import fs form 'node:fs'. The same for path

Copy link
Member

@karlhorky karlhorky Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these node: changes you added can be added to a 3rd new separate PR to the upstream vickonrails repo - then our repo doesn't diverge as much

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +28 to +29
tags?: string[];
category?: string;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tags and category to type IContent since these values can be optional and this type is used on multiple occasions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be PRed to upstream vickonrails?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +35 to 40
* Sorts content by their dates
* @param a {Date} - Date of post 1
* @param b {Date} - Date of post 2
*/

export const sortByDate = (a: { date?: Date }, b: { date?: Date }) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the function up to avoid 'sortByDate' being used before it was defined.

Comment on lines -166 to +200
.map((contentFile) => {
const filePath = `${contentDir}/${contentFile}`;
const rawContent = fs.readFileSync(filePath, {
.map((contentItem) => {
const contentPath = `${contentDir}/${contentItem}`;
const rawContent = fs.readFileSync(contentPath, {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the variable names since they were already declared in line 2 and line 196

id: uuid(),
};
} as IContent;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added type assertion because for TS the type returned had previewImage and id but this was wrong because in lines 207-209 we spread the data object and added previewImage and id

Copy link
Member

@karlhorky karlhorky Jan 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, let's try to avoid a type assertion if possible (for all type assertions)

usually it means that the types need to be more strict somewhere

eg. maybe the data type:

@@ -221,15 +253,12 @@ export const getContentWithTag = (tag: string, contentType: IContentType) => {
...data,
previewImage: data.previewImage || '/images/image-placeholder.png',
id: uuid(),
};
} as IContent;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added type assertion because for TS the type returned had previewImage and id but this was wrong because in lines 253-255 we spread the data object and added previewImage and id

Copy link
Member

@karlhorky karlhorky Jan 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, let's try to avoid a type assertion if possible (for all type assertions)

usually it means that the types need to be more strict somewhere

eg. maybe the data type:

const rawContent = fs.readFileSync(filePath, {
.filter((content) => content.endsWith('.md'))
.map((content) => {
const contentPath = `${contentDir}/${content}`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the variable names since it was already declared

@@ -277,15 +306,16 @@ export const getContentInCategory = (
...data,
previewImage: data.previewImage || '/images/image-placeholder.png',
id: uuid(),
};
} as IContent;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added type assertion because for TS the type returned had previewImage and id but this was wrong because in lines 306-308 we spread the data object and added previewImage and id

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, wonder why we need this... What are the properties in the data object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial type when hovering over data is

const data: {
    [key: string]: any;
}

These are the properties that data can have, some properties are optional

  title: string;
  slug: string;
  basePath: string;
  date: Date;
  draft?: boolean;
  selectedWork?: boolean;
  description?: string;
  previewImage?: string;
  tags?: string[];
  category?: string;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't data this type? maybe it should have this type applied to it instead?

});

articlesContent.sort(sortByDate).forEach((contentItem: IContent) => {
const { title, previewImage, date, slug, description } = contentItem;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed id, because it was declared but never used

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything unused - eg. a destructured property like this or an unused import - can be PRed to upstream in a separate new PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@karlhorky karlhorky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to unblock merging before we finish the feedback - I'll finish the remaining feedback afterwards and we can do follow-up PRs if necessary

@ProchaLu ProchaLu merged commit a1af9f5 into main Jan 5, 2024
3 checks passed
@ProchaLu ProchaLu deleted the update-to-next-14 branch January 5, 2024 08:18
@upleveled upleveled deleted a comment from ProchaLu Jan 6, 2024
@upleveled upleveled deleted a comment from ProchaLu Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge App Router changes from upstream
5 participants