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

Add vercel toolbar #96

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@
],
"editor.quickSuggestions": {
"strings": true
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
6 changes: 5 additions & 1 deletion apps/maestros/app/(maestros)/monorepos/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import {
import Link from 'next/link';
import { Analytics } from '@repo/analytics';
import { Twitter, SidebarOpen, Music } from 'lucide-react';
import { Fragment } from 'react';
import { Fragment, Suspense } from 'react';
import { linkStyles } from '../navLinks';
import { Toolbar } from './toolbar';
import { inter } from '#/app/fonts';
import { buildMeta, metadataBaseURI } from '#/app/metadata';
import '#/app/globals.css';
Expand Down Expand Up @@ -162,6 +163,9 @@ export default function RootLayout({
</ThemeWrapper>
</AuthSessionProvider>
<Analytics />
<Suspense>
<Toolbar />
</Suspense>
</body>
</html>
);
Expand Down
81 changes: 81 additions & 0 deletions apps/maestros/app/(maestros)/monorepos/toolbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use client';

import { VercelToolbar } from '@vercel/toolbar/next';
import { useEffect, useState } from 'react';

const konamiKeyCodes = [
'ArrowUp',
'ArrowUp',
'ArrowDown',
'ArrowDown',
'ArrowLeft',
'ArrowRight',
'ArrowLeft',
'ArrowRight',
'b',
'a',
];

type State =
| {
complete: false;
sequence: string[];
}
| {
complete: true;
};

const LOCAL_STORAGE_KEY = 'konami-state';

export function Toolbar() {
const [state, setState] = useState<State>({ complete: false, sequence: [] });

useEffect(() => {
if (state.complete) {
console.log('Konami code complete!');
localStorage.setItem(LOCAL_STORAGE_KEY, 'yes');
return;
}

const storedState = localStorage.getItem(LOCAL_STORAGE_KEY);

if (storedState === 'yes') {
setState({ complete: true });
}

function onKeyDown(e: KeyboardEvent) {
setState((prevState) => {
// This check is to please the typescript compiler
if (prevState.complete) return prevState;

const newSequence = [...prevState.sequence, e.key];
if (arrayStartsWith(konamiKeyCodes, newSequence)) {
if (newSequence.length === konamiKeyCodes.length) {
return { complete: true };
}
return { complete: false, sequence: newSequence };
}

return { complete: false, sequence: [] };
});
}

window.addEventListener('keydown', onKeyDown);

return () => {
window.removeEventListener('keydown', onKeyDown);
};
}, [state.complete]);

return state.complete ? <VercelToolbar /> : null;
}

function arrayStartsWith<T>(arr: T[], prefix: T[]) {
if (arr.length < prefix.length) return false;

for (let i = 0; i < prefix.length; i++) {
if (arr[i] !== prefix[i]) return false;
}

return true;
}
3 changes: 2 additions & 1 deletion apps/maestros/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { withContentlayer } = require('next-contentlayer');
const withVercelToolbar = require('@vercel/toolbar/plugins/next')();

/** @type {import('next').NextConfig} */
const moduleExports = {
Expand All @@ -8,4 +9,4 @@ const moduleExports = {
typescript: { ignoreBuildErrors: true },
};

module.exports = withContentlayer(moduleExports);
module.exports = withVercelToolbar(withContentlayer(moduleExports));
1 change: 1 addition & 0 deletions apps/maestros/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@repo/db": "workspace:*",
"@repo/ui": "workspace:*",
"@vercel/og": "^0.0.27",
"@vercel/toolbar": "^0.1.5",
"bright": "^0.8.2",
"class-variance-authority": "^0.6.1",
"contentlayer": "latest",
Expand Down
Loading