Skip to content

Commit

Permalink
feat: make seed always fresh
Browse files Browse the repository at this point in the history
  • Loading branch information
BigJk committed Sep 8, 2024
1 parent d507195 commit 7aa7352
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions frontend/src/js/types/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ type Generator = BasicInfo & {
count?: number;
};

function seed() {
return Math.ceil(Math.random() * 999999999).toString();
}

const sanitizeConfig = (g: Generator, configs: any) => {
// Create base config
if (configs === undefined) {
configs = {
seed: 'TEST_SEED',
seed: seed(),
};
}

// Set seed if uninitialized
if (configs.seed === undefined) {
configs.seed = 'TEST_SEED';
configs.seed = seed();
}

// Set default values for initialized fields
Expand Down Expand Up @@ -53,4 +57,4 @@ function createEmptyGenerator(): Generator {
}

export default Generator;
export { sanitizeConfig, createEmptyGenerator };
export { sanitizeConfig, createEmptyGenerator, seed };
4 changes: 2 additions & 2 deletions frontend/src/js/ui/components/editor/generator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import m from 'mithril';

import { fillConfigValues } from 'js/types/config';
import Generator, { sanitizeConfig } from 'js/types/generator';
import Generator, { sanitizeConfig, seed } from 'js/types/generator';
import { createNunjucksCompletionProvider } from 'js/core/monaco/completion-nunjucks';
import { settings } from 'js/core/store';

Expand Down Expand Up @@ -156,7 +156,7 @@ export default (): m.Component<GeneratorEditorProps> => {
name: 'Seed',
description: 'The seed used to generate the template',
type: 'Seed',
default: 'TEST_SEED',
default: seed(),
},
...(attrs.generator ? attrs.generator.config : []),
],
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/js/ui/views/generator/single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import HorizontalProperty from '../../components/horizontal-property';
import { openPromptModal } from '../../components/modals/prompt';

import { buildId } from 'js/types/basic-info';
import Generator, { sanitizeConfig } from 'js/types/generator';
import Generator, { sanitizeConfig, seed } from 'js/types/generator';
import * as API from 'js/core/api';
import store from 'js/core/store';

Expand Down Expand Up @@ -245,7 +245,7 @@ export default (): m.Component<SingleGeneratorProps> => {
name: 'Seed',
description: 'The seed used to generate the template',
type: 'Seed',
default: 'TEST_SEED',
default: seed(),
},
...(state.generator ? state.generator.config : []),
],
Expand Down Expand Up @@ -299,7 +299,7 @@ export default (): m.Component<SingleGeneratorProps> => {
intend: 'primary',
onClick: () => {
loadSavedConfig(key);
state.config.seed = Math.ceil(Math.random() * 999999999).toString();
state.config.seed = seed();
},
},
'Load + New Seed',
Expand Down

0 comments on commit 7aa7352

Please sign in to comment.