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

Autogenerated filename #127

Merged
merged 13 commits into from
Feb 10, 2024
4 changes: 3 additions & 1 deletion pages/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import firebase from 'firebase/app';
import { SharingPermissions } from '../src/components/SharingPermissions';
import va from '@vercel/analytics';

import { generateRandomFileName } from '../src/fileName';

function classNames(...classes: any[]) {
return classes.filter(Boolean).join(' ');
}
Expand All @@ -27,7 +29,7 @@ export default function NewFilePage() {
const { userData, firebaseUser } = useNullableUserContext();
const router = useRouter();
const [lang, setLang] = useState<Language>('cpp');
const [fileName, setFileName] = useState('');
const [fileName, setFileName] = useState(generateRandomFileName());
const [defaultPerimssion, setDefaultPermission] = useState<
AsynchronousAI marked this conversation as resolved.
Show resolved Hide resolved
AsynchronousAI marked this conversation as resolved.
Show resolved Hide resolved
'READ_WRITE' | 'READ' | 'PRIVATE' | null
>(null);
Expand Down
11 changes: 11 additions & 0 deletions src/fileName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const adjectives = ['awesome', 'fantastic', 'amazing', 'cool', 'brilliant'];
const nouns = ['project', 'repo', 'work', 'code', 'app'];

export default function generateRandomFileName() {
const randomAdjective =
adjectives[Math.floor(Math.random() * adjectives.length)];
const randomNoun = nouns[Math.floor(Math.random() * nouns.length)];
const randomNumber = Math.floor(Math.random() * 100);

return `${randomAdjective}-${randomNoun}-${randomNumber}`;
}
Loading