OpenBeta / open-tacos

Rock climbing route catalog (openbeta.io)
https://openbeta.io
GNU Affero General Public License v3.0
133 stars 117 forks source link

Migrate openbet.io/edit to Next 13 app dir #1073

Closed vnugent closed 8 months ago

vnugent commented 8 months ago

What would you like to be able to do? Please describe. Area pages and the landing page have been migrated to Next 13 app dir. Let's migrate pages/edit.

Todo:

You may need to mark the file with 'use client' for now. See https://nextjs.org/docs/pages/building-your-application/upgrading/app-router-migration#step-4-migrating-pages

btmccord commented 8 months ago

I'll take this on

btmccord commented 8 months ago

I am not sure that I am doing this right...

After following your to-dos adding 'use clients' gives me a error for having async/await in a client component. Not adding it causes compiling to fail for using next/router in a server component. I assume we need to update these to use the newer next/navigation routing for this to work?

Screenshot 2024-01-13 101918

The only way that was successful was very similar to the Next migration guide. I made two files (page.tsx & EditsContent.tsx) under src/app/edit. Page is a server component and basically just calls getChangeHistoryServerSide and passes the history to EditsContent which is a client component (has 'use client') and contains the code previously in the Page component.

vnugent commented 8 months ago

Thanks for taking on this one. There are a few things that automagically work by convention in Next 13. One of them is shared layout. You can remove the import Layout in page.tsx. Next 13 will put all page.tsx files under src/app in the layout in https://github.com/OpenBeta/open-tacos/blob/develop/src/app/layout.tsx (you don't have to explicitly import the layout file).

vnugent commented 8 months ago

An example page.tsx: https://github.com/OpenBeta/open-tacos/blob/develop/src/app/area/%5B%5B...slug%5D%5D/page.tsx

btmccord commented 8 months ago

Got it.

Removing the Layout element fixes the compile error.

It now renders with a different header. I assume this is what we want?

Screenshot 2024-01-13 112702 Screenshot 2024-01-13 112716

vnugent commented 8 months ago

Yes. Should be the same as the main page (openbeta.io) and all the area pages