Skip to content

Commit

Permalink
Autogenerated filename (#127)
Browse files Browse the repository at this point in the history
* Add filename generator

* Placeholder names

* Update new.tsx

* Update new.tsx

* Delete src/fileName.ts

* Update new.tsx

* Update new.tsx

* Create generateRandomFileName.ts

* Update new.tsx

* Update new.tsx

* Update new.tsx

Co-authored-by: Nathan Wang <[email protected]>

* Update pages/new.tsx

Co-authored-by: Nathan Wang <[email protected]>

---------

Co-authored-by: Nathan Wang <[email protected]>
  • Loading branch information
AsynchronousAI and thecodingwizard authored Feb 10, 2024
1 parent bde52dc commit d1a84d8
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
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}`;
}

0 comments on commit d1a84d8

Please sign in to comment.