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
2 changes: 2 additions & 0 deletions pages/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Link from 'next/link';
import firebase from 'firebase/app';
import { SharingPermissions } from '../src/components/SharingPermissions';
import va from '@vercel/analytics';
import { generateRandomFileName } from '../src/scripts/generateRandomFileName';

function classNames(...classes: any[]) {
return classes.filter(Boolean).join(' ');
Expand All @@ -28,6 +29,7 @@ export default function NewFilePage() {
const router = useRouter();
const [lang, setLang] = useState<Language>('cpp');
const [fileName, setFileName] = useState('');
useEffect(() => setFileName(generateRandomFileName()), []);
const [defaultPerimssion, setDefaultPermission] = useState<
'READ_WRITE' | 'READ' | 'PRIVATE' | null
>(null);
Expand Down
83 changes: 83 additions & 0 deletions src/scripts/generateRandomFileName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const adjectives = [
'awesome',
'fantastic',
'amazing',
'cool',
'brilliant',
'spiritual',
'amused',
'obscene',
'willing',
'smelly',
'bright',
'colossal',
'abstracted',
'understood',
'whispering',
'ignorant',
'momentous',
'black',
'agonizing',
'fluffy',
'regular',
'drunk',
'harsh',
'open',
'closed',
'entertaining',
'jobless',
'periodic',
'filthy',
'fast',
'quick',
'strong',
'typed',
'simple',
'sunny',
];
const nouns = [
'project',
'repo',
'work',
'code',
'app',
'order',
'butter',
'ticket',
'smoke',
'birds',
'rock',
'wing',
'fog',
'sky',
'water',
'cream',
'bikes',
'shoes',
'vegetable',
'cow',
'fork',
'haircut',
'rose',
'tree',
'maze',
'piano',
'ball',
'music',
'food',
'shower',
'window',
'umbrella',
'fork',
'plant',
'towel',
];

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