CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/account/default-file-name-generator.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
// Return a default filename with the given ext (or not extension if ext not given)
7
// this is just a wrapper for backwards compatibility
8
import { redux } from "@cocalc/frontend/app-framework";
9
import { DEFAULT_NEW_FILENAMES, NEW_FILENAMES } from "@cocalc/util/db-schema";
10
import { NewFilenames } from "../project/utils";
11
12
const new_filenames_generator = new NewFilenames(undefined, true);
13
14
export function default_filename(ext?: string, project_id?: string): string {
15
const account_store = redux.getStore("account");
16
const type =
17
account_store?.getIn(["other_settings", NEW_FILENAMES]) ??
18
DEFAULT_NEW_FILENAMES;
19
new_filenames_generator.set_ext(ext);
20
21
if (project_id != undefined) {
22
const avoid = redux
23
.getProjectActions(project_id)
24
.get_filenames_in_current_dir();
25
return new_filenames_generator.gen(type, avoid);
26
} else {
27
return new_filenames_generator.gen(type);
28
}
29
}
30
31