Skip to content

Commit

Permalink
Merge pull request #911 from trey-wallis/dev
Browse files Browse the repository at this point in the history
8.15.10
  • Loading branch information
decaf-dev authored Dec 17, 2023
2 parents b8a5bb1 + ced9e99 commit 39e2966
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 12 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"fundingUrl": {
"Buymeacoffee": "https://www.buymeacoffee.com/treywallis"
},
"version": "8.15.9"
"version": "8.15.10"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-dataloom",
"version": "8.15.9",
"version": "8.15.10",
"description": "Weave together data from diverse sources into different views. Inspired by Excel Spreadsheets and Notion.so.",
"main": "main.js",
"scripts": {
Expand Down
5 changes: 2 additions & 3 deletions src/data/main-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const handleFileRename = async (
await file.vault.modify(loomFile, serializeState(updatedState));

EventManager.getInstance().emit(
"app-refresh",
"app-refresh-by-state",
loomFile.path,
-1, //update all looms that match this path
updatedState
Expand All @@ -62,8 +62,7 @@ export const handleFileRename = async (
}
if (totalLinksUpdated > 0) {
new Notice(
`Updated ${totalLinksUpdated} link${
totalLinksUpdated > 1 ? "s" : ""
`Updated ${totalLinksUpdated} link${totalLinksUpdated > 1 ? "s" : ""
} in ${numFilesUpdated} loom file${numFilesUpdated > 1 ? "s" : ""}.`
);
}
Expand Down
10 changes: 10 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ export default class DataLoomPlugin extends Plugin {
)
);

this.registerEvent(
this.app.vault.on("modify", async (file: TAbstractFile) => {
if (file instanceof TFile) {
if (file.extension === LOOM_EXTENSION) {
EventManager.getInstance().emit("app-refresh-by-file", file, this.manifest.version);
}
}
})
);

this.registerSourceEvents();
}

Expand Down
2 changes: 1 addition & 1 deletion src/obsidian/dataloom-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default class DataLoomView extends TextFileView {

//Trigger an event to refresh the other open views of this file
EventManager.getInstance().emit(
"app-refresh",
"app-refresh-by-state",
this.file.path,
appId,
state
Expand Down
7 changes: 6 additions & 1 deletion src/obsidian/embedded/embedded-app-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ const handleSave = async (
await app.vault.modify(file, serialized);

//Trigger an event to refresh the other open views of this file
EventManager.getInstance().emit("app-refresh", file.path, appId, state);
EventManager.getInstance().emit(
"app-refresh-by-state",
file.path,
appId,
state
);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/obsidian/modal/import-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class ImportModal extends Modal {

//Trigger an event to refresh the other open views of this file
EventManager.getInstance().emit(
"app-refresh",
"app-refresh-by-state",
this.loomFile.path,
"", //No app id. Target all views of this file
state
Expand Down
1 change: 1 addition & 0 deletions src/react/loom-app/app/hooks/use-source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const useSource = () => {
return JSON.stringify(columns.map((column) => column.frontmatterKey));
}, [columns]);

//TODO fix double update on file modify
const updateRowsFromSources = React.useCallback(
(fromObsidianEvent = true) => {
logger("updateRowsFromSources called");
Expand Down
48 changes: 46 additions & 2 deletions src/react/loom-app/loom-state-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { useLogger } from "src/shared/logger";
import { sortRows } from "src/shared/loom-state/sort-rows";
import { useAppMount } from "src/react/loom-app/app-mount-provider";
import EventManager from "src/shared/event/event-manager";
import { TFile } from "obsidian";
import { deserializeState } from "src/data/serialize-state";

interface Props {
initialState: LoomState;
Expand Down Expand Up @@ -75,6 +77,8 @@ export default function LoomStateProvider({
const logger = useLogger();
const { reactAppId, loomFile, app } = useAppMount();

const [error, setError] = React.useState<unknown>(null);

// React.useEffect(() => {
// const jsonSizeInBytes = new TextEncoder().encode(
// JSON.stringify(history)
Expand Down Expand Up @@ -114,11 +118,47 @@ export default function LoomStateProvider({
}
}

EventManager.getInstance().on("app-refresh", handleRefreshEvent);
EventManager.getInstance().on(
"app-refresh-by-state",
handleRefreshEvent
);
return () =>
EventManager.getInstance().off("app-refresh", handleRefreshEvent);
EventManager.getInstance().off(
"app-refresh-by-state",
handleRefreshEvent
);
}, [reactAppId, loomFile, app]);

React.useEffect(() => {
async function handleRefreshEvent(file: TFile, pluginVersion: string) {
if (file.path === loomFile.path) {
const fileData = await app.vault.read(loomFile);

try {
const state = deserializeState(fileData, pluginVersion);
setLoomState({
state,
shouldSaveToDisk: false,
shouldSaveFrontmatter: false,
time: Date.now(),
});
} catch (err) {
setError(err);
}
}
}

EventManager.getInstance().on(
"app-refresh-by-file",
handleRefreshEvent
);
return () =>
EventManager.getInstance().off(
"app-refresh-by-file",
handleRefreshEvent
);
}, [loomFile, app]);

function handleToggleSearchBar() {
setSearchBarVisible((prevState) => !prevState);
}
Expand Down Expand Up @@ -199,6 +239,10 @@ export default function LoomStateProvider({
[position, history, loomState]
);

if (error) {
throw error;
}

return (
<LoomStateContext.Provider
value={{
Expand Down
3 changes: 2 additions & 1 deletion src/shared/event/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export type DataLoomEvent =
| "delete-column"
| "add-row"
| "delete-row"
| "app-refresh"
| "app-refresh-by-state"
| "app-refresh-by-file"
| "file-frontmatter-change"
| "file-delete"
| "folder-delete"
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,6 @@
"8.15.6": "1.4.0",
"8.15.7": "1.4.0",
"8.15.8": "1.4.0",
"8.15.9": "1.4.0"
"8.15.9": "1.4.0",
"8.15.10": "1.4.0"
}

0 comments on commit 39e2966

Please sign in to comment.