Skip to content

Commit

Permalink
Merge branch 'depuring-zustand-changes'
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGB committed Aug 4, 2022
2 parents 06fcedc + 604f259 commit 3f39502
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
8 changes: 8 additions & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 2.1.0 (beta)
### Shiny new things
- The dispatcher of all events was migrated to Zustand! This means a better, more stable, and more efficient way to handle events. [Zustand](https://zustand.js.org/) is a library that provides a simple, efficient, and powerful way to manage state in React. Allowing future changes as formula columns. As PoC, this version update the value of `modified` column every time a cell is changed. [ISSUE#227](https://github.com/RafaelGB/obsidian-db-folder/issues/227)
### No longer broken
- qoutes inside of source query are now controlled [ISSUE#233](https://github.com/RafaelGB/obsidian-db-folder/issues/233) [jcdeichmann](https://github.com/jcdeichmann)
- Fix centered images of all notes [ISSUE#231](https://github.com/RafaelGB/obsidian-db-folder/issues/231)
- Fix LaTeX formulas presentation incompatibility [ISSUE#228](https://github.com/RafaelGB/obsidian-db-folder/issues/228)
- now is compatible with windows pane using `activeDocument`[ISSUE#199](https://github.com/RafaelGB/obsidian-db-folder/issues/199)
# 2.0.1
### No longer broken
- Fixed selection problem with datetime columns introduced in 2.0.0.
Expand Down
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "dbfolder",
"name": "DB Folder",
"version": "2.0.1",
"version": "2.1.0",
"minAppVersion": "0.15.4",
"description": "Folder with the capability to store and retrieve data from a folder like database",
"author": "RafaelGB",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-dbfolder",
"version": "2.0.1",
"version": "2.1.0",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand Down
2 changes: 0 additions & 2 deletions src/cdm/FolderModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export interface TableColumn extends BaseColumn {
id: string;
options?: RowSelectOption[];
Cell?: any;
getHeaderProps?: any;
getResizerProps?: any;
}

export type RowDataType = {
Expand Down
1 change: 1 addition & 0 deletions src/cdm/TableStateInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface ColumnsState {
addOptionToColumn: (column: TableColumn, option: string, backgroundColor: string) => void;
alterColumnType: (column: TableColumn, input: string, parsedRows?: RowDataType[]) => void;
alterColumnLabel: (column: TableColumn, label: string) => void;
alterColumnSize: (columnSizing: Record<string, number>) => void;
}
export interface ColumnSortingState {
state: SortingState;
Expand Down
15 changes: 6 additions & 9 deletions src/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ const defaultColumn: Partial<ColumnDef<RowDataType>> = {
export function Table(tableData: TableDataType) {
/** Main information about the table */
const { view, tableStore } = tableData;
const [columns] = tableStore.columns((state) => [state.columns]);
const [columns, alterColumnSize] = tableStore.columns((state) => [
state.columns,
state.alterColumnSize,
]);
const [rows, addRow] = tableStore.data((state) => [state.rows, state.addRow]);
LOGGER.debug(
`=> Table. number of columns: ${columns.length}. number of rows: ${rows.length}`
Expand Down Expand Up @@ -197,18 +200,12 @@ export function Table(tableData: TableDataType) {
// setting new timeout
setPersistSizingTimeout(
setTimeout(() => {
Object.keys(list)
.filter((key) => list[key] !== undefined)
.map((key) => {
view.diskConfig.updateColumnProperties(key, {
width: list[key],
});
});
alterColumnSize(list);
// timeout until event is triggered after user has stopped typing
}, 1500)
);

setColumnSizing(updater);
setColumnSizing(list);
},
onColumnOrderChange: setColumnOrder,
globalFilterFn: "includesString",
Expand Down
18 changes: 18 additions & 0 deletions src/stateManagement/useColumnsStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,24 @@ const useColumnsStore = (view: DatabaseView) => {
view.diskConfig.updateColumnKey(column.id, newKey, label);
return { columns: updater.columns };
}),
alterColumnSize: (columnSizing: Record<string, number>) =>
set((updater) => {
const alteredColumns = [...updater.columns];
Object.keys(columnSizing)
.filter((key) => columnSizing[key] !== undefined)
.map((key) => {
// Persist on disk
view.diskConfig.updateColumnProperties(key, {
width: columnSizing[key],
});
// Persist on memory
const indexCol = alteredColumns.findIndex(
(col: TableColumn) => col.key === key
);
alteredColumns[indexCol].width = columnSizing[key];
});
return { columns: alteredColumns };
}),
}));
};
/**
Expand Down

0 comments on commit 3f39502

Please sign in to comment.