mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 11:53:49 +00:00
refactor: last project may not exist
This commit is contained in:
committed by
Carlos Valente
parent
d94c1d4252
commit
c944e77bc1
@@ -4,7 +4,7 @@ import { JSONFile } from 'lowdb/node';
|
||||
import { appStatePath, isTest } from '../../setup/index.js';
|
||||
|
||||
interface Config {
|
||||
lastLoadedProject: string;
|
||||
lastLoadedProject?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -19,7 +19,7 @@ class AppState {
|
||||
constructor(appStatePath: string) {
|
||||
this.pathToFile = appStatePath;
|
||||
const adapter = new JSONFile<Config>(this.pathToFile);
|
||||
this.config = new Low<Config>(adapter, null);
|
||||
this.config = new Low<Config>(adapter, {});
|
||||
}
|
||||
|
||||
private async init() {
|
||||
@@ -41,7 +41,7 @@ class AppState {
|
||||
return lastLoaded === projectName;
|
||||
}
|
||||
|
||||
async getLastLoadedProject(): Promise<string> {
|
||||
async getLastLoadedProject(): Promise<string | undefined> {
|
||||
const data = await this.get();
|
||||
return data.lastLoadedProject;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ export async function getProjectList(): Promise<ProjectFileListResponse> {
|
||||
|
||||
return {
|
||||
files,
|
||||
lastLoadedProject: removeFileExtension(lastLoadedProject),
|
||||
lastLoadedProject: lastLoadedProject ? removeFileExtension(lastLoadedProject) : '',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user