-
Notifications
You must be signed in to change notification settings - Fork 40
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
feat: add tabs #10
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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! |
There was a problem hiding this 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?
src/app/layout.tsx
Outdated
@@ -1,13 +1,15 @@ | |||
import '../styles/global.css' | |||
import '../styles/global.css'; |
There was a problem hiding this comment.
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?
src/app/layout.tsx
Outdated
|
||
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' |
There was a problem hiding this comment.
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.
src/app/layout.tsx
Outdated
@@ -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"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is vsc-initialized
?
There was a problem hiding this comment.
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... 🤦
src/app/layout.tsx
Outdated
<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> |
There was a problem hiding this comment.
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
src/app/layout.tsx
Outdated
<div className="h-full relative"> | ||
{children} | ||
<div className="h-full relative flex flex-col"> | ||
<Tabs /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<Tabs /> | |
<OpenFilesTabs /> |
src/components/Header.tsx
Outdated
export function Header() { | ||
const { getActiveTabName } = useTabs(); |
There was a problem hiding this comment.
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
src/components/Header.tsx
Outdated
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 |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
src/components/Tabs/RemoveTab.tsx
Outdated
index: number; | ||
}; | ||
|
||
export function RemoveTab({ isActive, index }: RemoveTabProps) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function RemoveTab({ isActive, index }: RemoveTabProps) { | |
export function CloseFileButton({ isActive, index }: RemoveTabProps) { |
src/hooks/useTabs.tsx
Outdated
import { explorerFiles } from '@/components/Explorer'; | ||
|
||
type TabsType = { | ||
children: React.ReactNode[]; |
There was a problem hiding this comment.
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?
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. 😄 |
Amazing job, congrats @Majortheus 👏 👏 !!! |
There was a problem hiding this 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 :)
<a | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
closeFile(index); | ||
}} | ||
className="w-[20px] h-[20px] flex justify-center items-center rounded hover:bg-[#817c9c26]" | ||
> |
There was a problem hiding this comment.
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[]>(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return; | ||
} | ||
|
||
setOpenFiles([...openFiles, file]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setOpenFiles([...openFiles, file]); | |
setOpenFiles(state => [...state, file]); |
const currentOpenFile = () => { | ||
const openFileHref = openFiles.find((openFile) => pathName === openFile); | ||
if (openFileHref) { | ||
return explorerFiles[openFileHref]; | ||
} | ||
return null; | ||
}; |
There was a problem hiding this comment.
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])
Hello @Majortheus, great job! I'm having some issues while trying to open more than one file, can you take a look at it?
CleanShot.2023-02-22.at.11.12.35.mp4 |
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 |
… more commits will come...
… more commits will come...
… more commits will come...
… for all the deploys
… all changes that broke deployed env
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...
Any deploy afterwards it's not, I will take a break, to reset, I will try again later. |
I've been looking at some other PRs, and every single new PR has a curious behavior atfer 21/02. |
@Majortheus @RaczoOBY probably some problem with Vercel? 🤔 |
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. |
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: