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

feat: add tabs #10

Merged
merged 13 commits into from
Feb 23, 2023
Merged

feat: add tabs #10

merged 13 commits into from
Feb 23, 2023

Conversation

Majortheus
Copy link
Contributor

Based on this video where @diego3g suggests to make this site close to a real visual code, and one of the suggestions is to have tabs, so tried to have a look on what i could come up with, and this is the result

Preview:
preview

@vercel
Copy link

vercel bot commented Feb 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
fala-dev ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 22, 2023 at 3:43PM (UTC)

@diego3g
Copy link
Owner

diego3g commented Feb 17, 2023

First of all, WTF, this is awesome. I'll take a look at it in a couple of days and add my comments here. Thanks!

Copy link
Owner

@diego3g diego3g left a comment

Choose a reason for hiding this comment

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

Visually, this PR is awesome, I don't have any points on how this could be better designed, great job!

About the implementation, I'll leave some comments on the code so we can make it even better!

Also, can you please remove yarn.lock and install the extensions using pnpm install as we are not using Yarn on this application?

@@ -1,13 +1,15 @@
import '../styles/global.css'
import '../styles/global.css';
Copy link
Owner

Choose a reason for hiding this comment

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

Can you take a look at why your editor added this semicolons at the end of these lines?


import { Menu } from '@/components/Menu'
import { Header } from '@/components/Header'
import { Explorer } from '@/components/Explorer'
import { Footer } from '@/components/Footer'
import { Tabs } from '@/components/Tabs'
import { TabsProvider } from '@/hooks/useTabs'
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of useTabs, maybe we could call this useOpenFiles on the hook as we are storing what files are open.

I always try to look to the future and tabs is a generic name that we can use in other places of the application.

@@ -29,20 +31,22 @@ export default function RootLayout({
return (
<html lang="en" className={inter.className}>
<head />
<body className="bg-[#7F7FD5] bg-app">
<body className="bg-[#7F7FD5] bg-app vsc-initialized">
Copy link
Owner

Choose a reason for hiding this comment

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

What is vsc-initialized?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have some chrome extension that adds this class to the body, and I was having some hydration erros popup on console, so i added to focus on what was really wrong and forgot to remove it afterwards... 🤦

<div className="z-10 relative h-screen p-20 flex items-center justify-center">
<div className="bg-[#232135] overflow-hidden border border-[#72707D] w-full max-w-[1480px] aspect-video shadow-md shadow-black/20 rounded-lg grid grid-rows-layout">
<Header />
<TabsProvider>
Copy link
Owner

Choose a reason for hiding this comment

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

This could also be something like OpenFilesProvider

<div className="h-full relative">
{children}
<div className="h-full relative flex flex-col">
<Tabs />
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
<Tabs />
<OpenFilesTabs />

export function Header() {
const { getActiveTabName } = useTabs();
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of a function, I think this should be a variable like currentOpenFile

return (
<div className="flex items-center justify-between px-3">
<div className="flex items-center gap-2">
<button type="button" className="w-3 h-3 bg-[#ED6A5E] rounded-full" />
<button type="button" className="w-3 h-3 bg-[#F4BF4F] rounded-full" />
<button type="button" className="w-3 h-3 bg-[#61C554] rounded-full" />
</div>
<span className="text-[#908caa] text-sm">
{getActiveTabName()} — fala-Dev
Copy link
Owner

Choose a reason for hiding this comment

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

Can we show nothing at all if no file is open? (instead of showing only - fala-Dev)

import { usePathname } from 'next/navigation';
import Link from 'next/link';

export function OpenEditorsSubMenu() {
Copy link
Owner

Choose a reason for hiding this comment

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

To keep the name convention I'm suggesting, we could rename this to OpenFilesSubMenu

index: number;
};

export function RemoveTab({ isActive, index }: RemoveTabProps) {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
export function RemoveTab({ isActive, index }: RemoveTabProps) {
export function CloseFileButton({ isActive, index }: RemoveTabProps) {

import { explorerFiles } from '@/components/Explorer';

type TabsType = {
children: React.ReactNode[];
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think we should store the data here as ReactNode, we should instead probably only store a reference to the open file, not all of its props.

We can have somewhere a file with the list of all files we have in the explorer (we already have that at components/Explorer/index.tsx), something like:

export const explorerFiles = {
  '/vscode/general': {
    icon: <SomeIcon />
    title: 'General',
    // any other prop
  }
}

And inside the context, when we open a file, we should save only the file reference, something like:

const openFiles = ['/vscode/general', '/vscode/settings']

What do you think?

@Majortheus
Copy link
Contributor Author

Did some changes, most to make the code more close to the suggestions proposed, there are probably more stuff to fix, and I'm happy to do it.

Looking forward for the new review, this is my first public PR, and it's been reviewed by the person I think I learned the most about coding and JS, very glad a I'm able to amaze you and learn a lot, specially about Next.js 13. 😄

@pedro-santos-sky
Copy link

Amazing job, congrats @Majortheus 👏 👏 !!!

Copy link
Owner

@diego3g diego3g left a comment

Choose a reason for hiding this comment

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

Much better! Just some small changes to make it even better :)

Comment on lines 33 to 40
<a
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
closeFile(index);
}}
className="w-[20px] h-[20px] flex justify-center items-center rounded hover:bg-[#817c9c26]"
>
Copy link
Owner

Choose a reason for hiding this comment

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

Can this be a button so we don't need to add preventDefault or stopPropagation?

export function OpenFilesProvider({ children }: { children: React.ReactNode }) {
const pathName = usePathname();

const [openFiles, setOpenFiles] = useState<string[]>(() => {
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of string[] here, we can use something like Array<keyof typeof explorerFiles> so openFiles will always include only existent files. This will also remove the necessity to add this if and this one.

return;
}

setOpenFiles([...openFiles, file]);
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
setOpenFiles([...openFiles, file]);
setOpenFiles(state => [...state, file]);

Comment on lines +43 to +49
const currentOpenFile = () => {
const openFileHref = openFiles.find((openFile) => pathName === openFile);
if (openFileHref) {
return explorerFiles[openFileHref];
}
return null;
};
Copy link
Owner

Choose a reason for hiding this comment

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

This doesn't have to be a function.

const currentOpenFile = useMemo(() => {
  const openFileHref = openFiles.find((openFile) => pathName === openFile);

  if (openFileHref) {
    return explorerFiles[openFileHref];
  }
  
  return null;
}, [openFiles, pathName])

@diego3g
Copy link
Owner

diego3g commented Feb 22, 2023

Hello @Majortheus, great job!

I'm having some issues while trying to open more than one file, can you take a look at it?

  • When I open a file, it closes the others;
  • The "Open Editors" submenu closes when it navigates;
CleanShot.2023-02-22.at.11.12.35.mp4

@Majortheus
Copy link
Contributor Author

I tested with Vercel preview link and yep that's happening, but I remember testing before doing the last commit, so I tested in my machine and... it's working as intended... how fun aheuaheu, I will take a closer look, if you have any pointers, pls gimme it, I already tried to use pnpm build and pnpm start instead of dev, but it didn't make any changes, I don't have any idea on why that's happening though.

2023-02-22-11-50-00.mp4

@Majortheus
Copy link
Contributor Author

Hmmm I don't know what to do anymore, I tried to undo all the changes before this bug, if you look the deploy before the changes I did today, it was working normal, but the first deploy after it started happening, so I undo all changes and it's happening still, I have no clue...

image
This deploy is working https://fala-5b58z0knk-rocketseat.vercel.app/

Any deploy afterwards it's not, I will take a break, to reset, I will try again later.

@RaczoOBY
Copy link

I've been looking at some other PRs, and every single new PR has a curious behavior atfer 21/02.
Even if we check out the commit "fix names and auto formatting" and redeploy it, the from next/link is causing hard reloads.

@diego3g
Copy link
Owner

diego3g commented Feb 23, 2023

@Majortheus @RaczoOBY probably some problem with Vercel? 🤔

@diego3g
Copy link
Owner

diego3g commented Feb 23, 2023

I tested it on my local environment and it works properly. I think there ir something wrong with preview deployments on Vercel so I will merge this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants