Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 61ac909

Browse files
committed
renaming state fixed
1 parent a5d730d commit 61ac909

File tree

2 files changed

+29
-45
lines changed

2 files changed

+29
-45
lines changed

src/components/reducers/DatabaseDispatch.tsx

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import update from "immutability-helper";
33
import {
44
ActionTypes,
55
DataTypes,
6+
DEFAULT_COLUMN_CONFIG,
67
MetadataColumns,
78
TableColumnsTemplate,
89
UpdateRowOptions,
@@ -27,9 +28,7 @@ import { Literal } from "obsidian-dataview/lib/data-model/value";
2728
import { DateTime } from "luxon";
2829

2930
export function databaseReducer(state: TableDataType, action: ActionType) {
30-
LOGGER.debug(
31-
`<=>databaseReducer action: ${action.type} value: ${action.value}`
32-
);
31+
LOGGER.debug(`<=>databaseReducer action: ${action.type}`, action);
3332
/** database configuration */
3433
const dbconfig = state.view.diskConfig.yaml.config;
3534
// Check if action exists
@@ -114,28 +113,25 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
114113
(column: any) => column.id === action.columnId
115114
);
116115
// Update configuration & row files on disk
117-
state.view.diskConfig
118-
.updateColumnKey(action.columnId, action.newKey, action.label)
119-
.then(async () => {
120-
// Once the column is updated, update the rows in case the key is changed
121-
122-
await Promise.all(
123-
state.data.map(async (row: RowDataType) => {
124-
await updateRowFileProxy(
125-
row.note.getFile(),
126-
action.columnId,
127-
action.newKey,
128-
state,
129-
UpdateRowOptions.COLUMN_KEY
130-
);
131-
})
132-
);
133-
});
134-
// Update view yaml info
135-
state.view.diskConfig.yaml.columns[action.newKey] =
136-
state.view.diskConfig.yaml.columns[action.columnId];
137-
delete state.view.diskConfig.yaml.columns[action.columnId];
138-
116+
state.view.diskConfig.updateColumnKey(
117+
action.columnId,
118+
action.newKey,
119+
action.label
120+
);
121+
async () => {
122+
// Update the rows in case the key is changed
123+
await Promise.all(
124+
state.data.map(async (row: RowDataType) => {
125+
await updateRowFileProxy(
126+
row.note.getFile(),
127+
action.columnId,
128+
action.newKey,
129+
state,
130+
UpdateRowOptions.COLUMN_KEY
131+
);
132+
})
133+
);
134+
};
139135
return update(state, {
140136
skipReset: { $set: true },
141137
// Modify column visually with the new label
@@ -167,9 +163,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
167163
view: {
168164
diskConfig: {
169165
yaml: {
170-
columns: {
171-
$set: state.view.diskConfig.yaml.columns,
172-
},
166+
$set: state.view.diskConfig.yaml,
173167
},
174168
},
175169
},
@@ -271,12 +265,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
271265
key: action.columnInfo.name,
272266
label: action.columnInfo.label,
273267
position: action.columnInfo.position,
274-
config: {
275-
isInline: false,
276-
media_height: 100,
277-
media_width: 100,
278-
enable_media_view: false,
279-
},
268+
config: DEFAULT_COLUMN_CONFIG,
280269
};
281270
// Update configuration on disk
282271
state.view.diskConfig.addColumn(action.columnInfo.name, newLeftColumn);
@@ -324,12 +313,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
324313
key: action.columnInfo.name,
325314
label: action.columnInfo.label,
326315
position: action.columnInfo.position,
327-
config: {
328-
isInline: false,
329-
media_height: 100,
330-
media_width: 100,
331-
enable_media_view: false,
332-
},
316+
config: DEFAULT_COLUMN_CONFIG,
333317
};
334318
// Update configuration on disk
335319
state.view.diskConfig.addColumn(action.columnInfo.name, newRIghtColumn);

src/services/DatabaseInfo.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ export default class DatabaseInfo {
7171
* @param oldColumnId
7272
* @param newColumnId
7373
*/
74-
async updateColumnKey(oldColumnId: string, newColumnId: string, newLabel: string): Promise<void> {
74+
updateColumnKey(oldColumnId: string, newColumnId: string, newLabel: string) {
7575
// clone current column configuration
7676
const currentCol = this.yaml.columns[oldColumnId];
7777
// update column id
78-
currentCol.label = newColumnId;
78+
currentCol.label = newLabel;
7979
currentCol.accessor = newColumnId;
8080
currentCol.key = newColumnId;
8181
delete this.yaml.columns[oldColumnId];
8282
this.yaml.columns[newColumnId] = currentCol;
8383
// save on disk
84-
await this.saveOnDisk();
84+
this.saveOnDisk();
8585
}
8686

8787
/**
@@ -119,9 +119,9 @@ export default class DatabaseInfo {
119119
await this.saveOnDisk();
120120
}
121121

122-
async addColumn(columnId: string, properties: DatabaseColumn): Promise<void> {
122+
addColumn(columnId: string, properties: DatabaseColumn) {
123123
this.yaml.columns[columnId] = properties;
124-
await this.saveOnDisk();
124+
this.saveOnDisk();
125125
}
126126

127127
async updateConfig<K extends keyof LocalSettings>(key: K, value: LocalSettings[K]): Promise<void> {

0 commit comments

Comments
 (0)