-
{components}
+
);
};
diff --git a/src/default-popup/components/obj/obj-view.component.tsx b/src/default-popup/components/obj/obj-view.component.tsx
index 1d8f0aa..5beff7c 100644
--- a/src/default-popup/components/obj/obj-view.component.tsx
+++ b/src/default-popup/components/obj/obj-view.component.tsx
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
.
*/
-import { ObjDto } from '../../../common/model/obj/obj.dto';
+import { ObjDto, ObjPageDataDto, ObjTypeDto } from '../../../common/model/obj/obj.dto';
import React, { FunctionComponent, useEffect, useState } from 'react';
import { BusMessageType } from '../../../common/model/bus.model';
import { ObjGetHrefCommand } from '../../../common/command/obj/url/obj-get-href.command';
@@ -23,15 +23,49 @@ import { ObjListComponent } from './obj-list.component';
import { ObjPageNoteDto } from '../../../common/model/obj/obj-note.dto';
import { PopupActiveTabStore } from '../../store/popup-active-tab.store';
import { TinyDispatcher } from '@pinmenote/tiny-dispatcher';
+import { LogManager } from '../../../common/popup/log.manager';
+import { ObjPageDto } from '../../../common/model/obj/obj-page.dto';
+import { ObjPinDto } from '../../../common/model/obj/obj-pin.dto';
+import { ObjPdfDto } from '../../../common/model/obj/obj-pdf.dto';
+import { ObjGetCommand } from '../../../common/command/obj/obj-get.command';
interface Props {
editNoteCallback: (obj: ObjDto
) => void;
}
+interface FetchObjectsResult {
+ objs: ObjDto[];
+ index: number;
+}
+
+const hrefFilter = (obj: ObjDto, href?: string) => {
+ if ([ObjTypeDto.PageSnapshot, ObjTypeDto.PageElementSnapshot].includes(obj.type)) {
+ if ((obj.data as ObjPageDto).snapshot.info.url.href === href) return true;
+ } else if (obj.type === ObjTypeDto.PageElementPin) {
+ if ((obj.data as ObjPinDto).data.url.href === href) return true;
+ } else if (obj.type === ObjTypeDto.PageNote) {
+ if ((obj.data as ObjPageNoteDto).url.href === href) return true;
+ } else if (obj.type === ObjTypeDto.Pdf) {
+ if ((obj.data as ObjPdfDto).data.rawUrl === href) return true;
+ }
+ return false;
+};
+
+const fetchObjects = async (idList: number[], index: number, href?: string): Promise => {
+ LogManager.log(`aaa ${href || 'undefined'} bbb ${idList.length} ccc ${index}`);
+ if (index >= idList.length) return { objs: [], index };
+ const objs: ObjDto[] = [];
+ for (index; index < idList.length; index++) {
+ const obj = await new ObjGetCommand(idList[index]).execute();
+ if (hrefFilter(obj, href)) continue;
+ objs.push(obj);
+ }
+ return { objs, index };
+};
+
export const ObjViewComponent: FunctionComponent = (props) => {
- const [originIds, setOriginIds] = useState([]);
- const [hrefIds, setHrefIds] = useState([]);
- const [initialized, setInitialized] = useState(false);
+ const [originObjs, setOriginObjs] = useState[]>([]);
+ const [hrefObjs, setHrefObjs] = useState[]>([]);
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
@@ -42,27 +76,24 @@ export const ObjViewComponent: FunctionComponent = (props) => {
return () => {
TinyDispatcher.getInstance().removeListener(BusMessageType.POP_UPDATE_URL, urlKey);
};
- }, []);
+ }, [props]);
const initUrl = async () => {
- if (initialized) return;
+ LogManager.log('initUrl');
if (!PopupActiveTabStore.url) return;
- setInitialized(true);
- const href = await new ObjGetHrefCommand(PopupActiveTabStore.url).execute();
- const origin = await new ObjGetOriginCommand(PopupActiveTabStore.url).execute();
- setHrefIds(href);
- setOriginIds(origin);
+ const hrefIds = await new ObjGetHrefCommand(PopupActiveTabStore.url).execute();
+ const href = await fetchObjects(hrefIds, 0);
+ setHrefObjs(href.objs);
+ const originIds = await new ObjGetOriginCommand(PopupActiveTabStore.url).execute();
+ const origin = await fetchObjects(originIds, 0, PopupActiveTabStore.url.href);
+ setOriginObjs(origin.objs);
};
return (
On this page
-
+
On {PopupActiveTabStore.url?.origin}
-
+
);
};