mirror of
https://github.com/sechan100/daily-routine-2.git
synced 2026-07-22 12:00:31 +00:00
fix: setting값을 사용하는 단계를 추상화하고, 사용자가 설정해야하는 요소들을 단순화
- routineFolder, noteFolder등의 옵션을 없이고 DailyRoutinFolder의 경로로 단순화. 이후 모든 데이터는 해당 폴더 하위에 알아서 배치함.
This commit is contained in:
parent
e3013d1fa2
commit
d19a6bec1f
5 changed files with 41 additions and 34 deletions
|
|
@ -6,14 +6,12 @@ import { useLeaf } from "@shared/view/use-leaf";
|
|||
|
||||
|
||||
export interface DailyRoutinePluginSettings {
|
||||
routineFolderPath: string;
|
||||
noteFolderPath: string;
|
||||
dailyRoutineFolderPath: string;
|
||||
isMondayStartOfWeek: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: DailyRoutinePluginSettings = {
|
||||
routineFolderPath: "daily-routine/routines",
|
||||
noteFolderPath: "daily-routine/archive",
|
||||
dailyRoutineFolderPath: "DAILY_ROUTINE",
|
||||
isMondayStartOfWeek: true
|
||||
}
|
||||
|
||||
|
|
@ -30,34 +28,20 @@ export class DailyRoutineSettingTab extends PluginSettingTab {
|
|||
const { containerEl } = this;
|
||||
containerEl.empty();
|
||||
|
||||
// Routine Folder Path
|
||||
// DAILY ROUTINE FOLDER PATH
|
||||
new Setting(containerEl)
|
||||
.setName("Routine Folder Path")
|
||||
.setDesc("The path to the routine folder.")
|
||||
.setName("Daily Routine Folder Path")
|
||||
.setDesc("This is the path to the folder where the Daily Routine Plugin saves notes, routines, and other data.")
|
||||
.addText(text => {
|
||||
new FileSuggest(text.inputEl, "folder");
|
||||
text
|
||||
.setPlaceholder("daily-routine/routines")
|
||||
.setValue(this.plugin.settings.routineFolderPath??"")
|
||||
.setPlaceholder("DAILY_ROUTINE")
|
||||
.setValue(this.plugin.settings.dailyRoutineFolderPath??"")
|
||||
.onChange(async (value) => {
|
||||
this.save({ routineFolderPath: normalizePath(value)});
|
||||
this.save({ dailyRoutineFolderPath: normalizePath(value)});
|
||||
})
|
||||
})
|
||||
|
||||
// Routine Note Folder Path
|
||||
new Setting(containerEl)
|
||||
.setName("Routine Note Archive Path")
|
||||
.setDesc("The path to the routine note archive folder.")
|
||||
.addText(text => {
|
||||
new FileSuggest(text.inputEl, "folder");
|
||||
text
|
||||
.setPlaceholder("daily-routine/archive")
|
||||
.setValue(this.plugin.settings.noteFolderPath??"")
|
||||
.onChange(async (value) => {
|
||||
this.save({ noteFolderPath: normalizePath(value)});
|
||||
})
|
||||
});
|
||||
|
||||
// Start of Week
|
||||
new Setting(containerEl)
|
||||
.setName("Start of Week")
|
||||
|
|
@ -80,12 +64,6 @@ export class DailyRoutineSettingTab extends PluginSettingTab {
|
|||
|
||||
async save(partial: Partial<DailyRoutinePluginSettings>) {
|
||||
const settings = {...this.plugin.settings, ...partial};
|
||||
|
||||
if(settings.noteFolderPath === settings.routineFolderPath){
|
||||
new Notice("Routine folder path and routine archive folder path cannot be the same.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.plugin.settings = {...this.plugin.settings, ...partial};
|
||||
await this.plugin.saveSettings();
|
||||
useLeaf.getState().refresh();
|
||||
|
|
|
|||
26
src/app/settings/setting-provider.ts
Normal file
26
src/app/settings/setting-provider.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { plugin } from "@shared/plugin-service-locator"
|
||||
|
||||
|
||||
|
||||
const s = () => {
|
||||
return plugin().settings;
|
||||
}
|
||||
|
||||
|
||||
export const DR_SETTING = {
|
||||
routineFolderPath(){
|
||||
return `${s().dailyRoutineFolderPath}/routines`;
|
||||
},
|
||||
|
||||
noteFolderPath(){
|
||||
return `${s().dailyRoutineFolderPath}/notes`;
|
||||
},
|
||||
|
||||
dataFolderPath(){
|
||||
return `${s().dailyRoutineFolderPath}/data`;
|
||||
},
|
||||
|
||||
isMondayStartOfWeek(){
|
||||
return s().isMondayStartOfWeek;
|
||||
},
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import { TAbstractFile, TFile } from "obsidian";
|
|||
import { Day } from "@shared/period/day";
|
||||
import { FileNotFoundError } from "@shared/file/errors";
|
||||
import { doConfirm } from "@shared/components/modal/confirm-modal";
|
||||
import { DR_SETTING } from "@app/settings/setting-provider";
|
||||
|
||||
|
||||
|
||||
|
|
@ -60,7 +61,7 @@ export const NoteRepository: NoteRepository = {
|
|||
|
||||
async loadBetween(start: Day, end: Day): Promise<RoutineNote[]> {
|
||||
const notes: RoutineNote[] = [];
|
||||
const routineNoteFiles: TAbstractFile[] = fileAccessor.getFolder(plugin().settings.noteFolderPath).children.filter(file => file instanceof TFile);
|
||||
const routineNoteFiles: TAbstractFile[] = fileAccessor.getFolder(DR_SETTING.noteFolderPath()).children.filter(file => file instanceof TFile);
|
||||
for(const file of routineNoteFiles){
|
||||
if(!(file instanceof TFile)) continue;
|
||||
const day = Day.fromString(file.basename);
|
||||
|
|
@ -164,5 +165,5 @@ const parseFile = async (file: TFile): Promise<RoutineNote> => {
|
|||
* 루틴 아카이브 파일 경로를 반환합니다.
|
||||
*/
|
||||
const getRoutineArchivePath = (routineNoteTitle: string) => {
|
||||
return `${plugin().settings.noteFolderPath}/${routineNoteTitle}.md`;
|
||||
return `${DR_SETTING.noteFolderPath()}/${routineNoteTitle}.md`;
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import { fileAccessor } from "@shared/file/file-accessor";
|
|||
import { TFile } from "obsidian";
|
||||
import { routineSerializer } from "./routine-serializer";
|
||||
import { compose } from "@shared/compose";
|
||||
import { DR_SETTING } from "@app/settings/setting-provider";
|
||||
|
||||
|
||||
const ROUTINE_PATH = (routineName: string) =>{
|
||||
|
|
@ -15,7 +16,7 @@ const ROUTINE_FILE = (routineName: string) => {
|
|||
}
|
||||
|
||||
const ROUTINE_FOLDER_PATH = () => {
|
||||
const path = plugin().settings.routineFolderPath;
|
||||
const path = DR_SETTING.routineFolderPath();
|
||||
if(!path) {
|
||||
throw new Error('Routine folder path is not set.');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { moment } from "obsidian";
|
||||
import { plugin } from "../plugin-service-locator";
|
||||
import _ from "lodash";
|
||||
import { DR_SETTING } from "@app/settings/setting-provider";
|
||||
|
||||
|
||||
|
||||
|
|
@ -49,7 +50,7 @@ export class Day {
|
|||
|
||||
static getDaysOfWeek(): DayOfWeek[] {
|
||||
const weekWithoutSun = [DayOfWeek.MON, DayOfWeek.TUE, DayOfWeek.WED, DayOfWeek.THU, DayOfWeek.FRI, DayOfWeek.SAT];
|
||||
const isMondayStart = plugin().settings.isMondayStartOfWeek;
|
||||
const isMondayStart = DR_SETTING.isMondayStartOfWeek();
|
||||
return isMondayStart ? [...weekWithoutSun, DayOfWeek.SUN] : [DayOfWeek.SUN, ...weekWithoutSun];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue