fix: html preview exclude page note
This commit is contained in:
parent
24d679c37a
commit
c498dc3a1a
@ -15,11 +15,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { ObjDto, ObjUrlDto } from '../../model/obj/obj.dto';
|
||||
import { BrowserStorageWrapper } from '../../service/browser.storage.wrapper';
|
||||
import { ICommand } from '../../model/shared/common.dto';
|
||||
import { LinkHrefOriginStore } from '../../store/link-href-origin.store';
|
||||
import { ObjGetCommand } from '../obj/obj-get.command';
|
||||
import { ObjNoteDto } from '../../model/obj/obj-note.dto';
|
||||
import { ObjectStoreKeys } from '../../keys/object.store.keys';
|
||||
import { fnConsoleLog } from '../../fn/console.fn';
|
||||
|
||||
export class NoteGetHrefCommand implements ICommand<Promise<ObjDto<ObjNoteDto>[]>> {
|
||||
@ -31,8 +30,7 @@ export class NoteGetHrefCommand implements ICommand<Promise<ObjDto<ObjNoteDto>[]
|
||||
const out: ObjDto<ObjNoteDto>[] = [];
|
||||
|
||||
for (const id of ids) {
|
||||
const key = `${ObjectStoreKeys.OBJECT_ID}:${id}`;
|
||||
const obj = await BrowserStorageWrapper.get<ObjDto<ObjNoteDto>>(key);
|
||||
const obj = await new ObjGetCommand<ObjNoteDto>(id).execute();
|
||||
out.push(obj);
|
||||
}
|
||||
return out;
|
||||
|
27
src/common/command/obj/obj-get.command.ts
Normal file
27
src/common/command/obj/obj-get.command.ts
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2023 Michal Szczepanski.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BrowserStorageWrapper } from '../../service/browser.storage.wrapper';
|
||||
import { ICommand } from '../../model/shared/common.dto';
|
||||
import { ObjDto } from '../../model/obj/obj.dto';
|
||||
import { ObjectStoreKeys } from '../../keys/object.store.keys';
|
||||
|
||||
export class ObjGetCommand<T> implements ICommand<Promise<ObjDto<T>>> {
|
||||
constructor(private id: number) {}
|
||||
async execute(): Promise<ObjDto<T>> {
|
||||
return await BrowserStorageWrapper.get<ObjDto<T>>(`${ObjectStoreKeys.OBJECT_ID}:${this.id}`);
|
||||
}
|
||||
}
|
@ -15,10 +15,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { ObjDto, ObjPageDataDto, ObjUrlDto } from '../../../model/obj/obj.dto';
|
||||
import { BrowserStorageWrapper } from '../../../service/browser.storage.wrapper';
|
||||
import { ICommand } from '../../../model/shared/common.dto';
|
||||
import { LinkHrefOriginStore } from '../../../store/link-href-origin.store';
|
||||
import { ObjectStoreKeys } from '../../../keys/object.store.keys';
|
||||
import { ObjGetCommand } from '../obj-get.command';
|
||||
import { fnConsoleLog } from '../../../fn/console.fn';
|
||||
|
||||
export class ObjGetHrefCommand implements ICommand<Promise<ObjDto<ObjPageDataDto>[]>> {
|
||||
@ -27,11 +26,9 @@ export class ObjGetHrefCommand implements ICommand<Promise<ObjDto<ObjPageDataDto
|
||||
async execute(): Promise<ObjDto<ObjPageDataDto>[]> {
|
||||
const pinIds = (await LinkHrefOriginStore.hrefIds(this.data.href)).reverse();
|
||||
fnConsoleLog('WorkerPinManager->pinGetHref', this.data.href, 'ids->', pinIds);
|
||||
// await this.test();
|
||||
const out: ObjDto<ObjPageDataDto>[] = [];
|
||||
for (const id of pinIds) {
|
||||
const key = `${ObjectStoreKeys.OBJECT_ID}:${id}`;
|
||||
const obj = await BrowserStorageWrapper.get<ObjDto<ObjPageDataDto>>(key);
|
||||
const obj = await new ObjGetCommand<ObjPageDataDto>(id).execute();
|
||||
out.push(obj);
|
||||
}
|
||||
return out;
|
||||
|
@ -15,13 +15,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { ObjDto, ObjPageDataDto, ObjTypeDto, ObjUrlDto } from '../../../model/obj/obj.dto';
|
||||
import { BrowserStorageWrapper } from '../../../service/browser.storage.wrapper';
|
||||
import { ICommand } from '../../../model/shared/common.dto';
|
||||
import { LinkHrefOriginStore } from '../../../store/link-href-origin.store';
|
||||
import { ObjGetCommand } from '../obj-get.command';
|
||||
import { ObjNoteDto } from '../../../model/obj/obj-note.dto';
|
||||
import { ObjPageDto } from '../../../model/obj/obj-pin.dto';
|
||||
import { ObjTaskDto } from '../../../model/obj/obj-task.dto';
|
||||
import { ObjectStoreKeys } from '../../../keys/object.store.keys';
|
||||
|
||||
export class ObjGetOriginCommand implements ICommand<Promise<ObjDto<ObjPageDataDto>[]>> {
|
||||
constructor(private data: ObjUrlDto) {}
|
||||
@ -30,8 +29,7 @@ export class ObjGetOriginCommand implements ICommand<Promise<ObjDto<ObjPageDataD
|
||||
const pinIds = (await LinkHrefOriginStore.originIds(this.data.origin)).reverse();
|
||||
const out: ObjDto<ObjPageDataDto>[] = [];
|
||||
for (const id of pinIds) {
|
||||
const key = `${ObjectStoreKeys.OBJECT_ID}:${id}`;
|
||||
const obj = await BrowserStorageWrapper.get<ObjDto<ObjPageDataDto>>(key);
|
||||
const obj = await new ObjGetCommand<ObjPageDataDto>(id).execute();
|
||||
if (!obj) {
|
||||
await LinkHrefOriginStore.delHrefOriginId(this.data, id);
|
||||
continue;
|
||||
|
@ -15,11 +15,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { ObjDto, ObjUrlDto } from '../../model/obj/obj.dto';
|
||||
import { BrowserStorageWrapper } from '../../service/browser.storage.wrapper';
|
||||
import { ICommand } from '../../model/shared/common.dto';
|
||||
import { LinkHrefOriginStore } from '../../store/link-href-origin.store';
|
||||
import { ObjGetCommand } from '../obj/obj-get.command';
|
||||
import { ObjPagePinDto } from '../../model/obj/obj-pin.dto';
|
||||
import { ObjectStoreKeys } from '../../keys/object.store.keys';
|
||||
import { fnConsoleLog } from '../../fn/console.fn';
|
||||
|
||||
export class PinGetHrefCommand implements ICommand<Promise<ObjDto<ObjPagePinDto>[]>> {
|
||||
@ -31,8 +30,7 @@ export class PinGetHrefCommand implements ICommand<Promise<ObjDto<ObjPagePinDto>
|
||||
const out: ObjDto<ObjPagePinDto>[] = [];
|
||||
|
||||
for (const id of pinIds) {
|
||||
const key = `${ObjectStoreKeys.OBJECT_ID}:${id}`;
|
||||
const obj = await BrowserStorageWrapper.get<ObjDto<ObjPagePinDto>>(key);
|
||||
const obj = await new ObjGetCommand<ObjPagePinDto>(id).execute();
|
||||
// TODO revisit visible flag in pin.manager.ts in content scripts
|
||||
if (!obj.local?.visible) continue;
|
||||
out.push(obj);
|
||||
|
@ -14,10 +14,11 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { ObjDataDto, ObjDto } from '../../model/obj/obj.dto';
|
||||
import { BrowserStorageWrapper } from '../../service/browser.storage.wrapper';
|
||||
import { ICommand } from '../../model/shared/common.dto';
|
||||
import { LogManager } from '../../popup/log.manager';
|
||||
import { ObjDto } from '../../model/obj/obj.dto';
|
||||
import { ObjGetCommand } from '../obj/obj-get.command';
|
||||
import { ObjectStoreKeys } from '../../keys/object.store.keys';
|
||||
|
||||
export class SyncClearServerCommand implements ICommand<Promise<void>> {
|
||||
@ -37,7 +38,7 @@ export class SyncClearServerCommand implements ICommand<Promise<void>> {
|
||||
private async clearList(list: number[]): Promise<void> {
|
||||
for (const id of list) {
|
||||
LogManager.log(`SyncClearServerCommand->clearList ${id}`);
|
||||
const obj = await this.getObject(id);
|
||||
const obj = await new ObjGetCommand<ObjDataDto>(id).execute();
|
||||
if (!obj) {
|
||||
LogManager.log(`Problem reading object ${id}`);
|
||||
continue;
|
||||
@ -51,10 +52,6 @@ export class SyncClearServerCommand implements ICommand<Promise<void>> {
|
||||
await BrowserStorageWrapper.set(`${ObjectStoreKeys.OBJECT_ID}:${id}`, obj);
|
||||
}
|
||||
|
||||
private async getObject(id: number): Promise<ObjDto | undefined> {
|
||||
return BrowserStorageWrapper.get<ObjDto | undefined>(`${ObjectStoreKeys.OBJECT_ID}:${id}`);
|
||||
}
|
||||
|
||||
private async getListId(): Promise<number> {
|
||||
const value = await BrowserStorageWrapper.get<number | undefined>(ObjectStoreKeys.OBJECT_LIST_ID);
|
||||
return value || 1;
|
||||
|
@ -59,7 +59,7 @@ export class EditBarSnapshotButton implements HtmlComponent<HTMLElement> {
|
||||
const o = this.model.object;
|
||||
const obj: ObjDto<ObjPageDto> = {
|
||||
...o,
|
||||
data: { snapshot: o.data.snapshot, draw: [], comments: { data: [] } }
|
||||
data: { snapshot: o.data.snapshot, draw: { data: [] }, comments: { data: [] } }
|
||||
};
|
||||
obj.type = ObjTypeDto.PageElementSnapshot;
|
||||
|
||||
|
@ -26,16 +26,14 @@ import {
|
||||
} from '../../../common/command/obj/content/obj-get-snapshot-content.command';
|
||||
import React, { FunctionComponent, useEffect, useRef, useState } from 'react';
|
||||
import { BrowserApi } from '../../../common/service/browser.api.wrapper';
|
||||
import { BrowserStorageWrapper } from '../../../common/service/browser.storage.wrapper';
|
||||
import CircularProgress from '@mui/material/CircularProgress';
|
||||
import ClearIcon from '@mui/icons-material/Clear';
|
||||
import DownloadIcon from '@mui/icons-material/Download';
|
||||
import IconButton from '@mui/material/IconButton';
|
||||
import { IframeHtmlFactory } from '../../../common/factory/iframe-html.factory';
|
||||
import { ObjDto } from '../../../common/model/obj/obj.dto';
|
||||
import { ObjGetCommand } from '../../../common/command/obj/obj-get.command';
|
||||
import { ObjPageDto } from '../../../common/model/obj/obj-pin.dto';
|
||||
import { ObjSnapshotDto } from '../../../common/model/obj/obj-snapshot.dto';
|
||||
import { ObjectStoreKeys } from '../../../common/keys/object.store.keys';
|
||||
import { fnConsoleLog } from '../../../common/fn/console.fn';
|
||||
import { fnSleep } from '../../../common/fn/sleep.fn';
|
||||
import { fnUid } from '../../../common/fn/uid.fn';
|
||||
@ -80,7 +78,7 @@ export const HtmlPreviewComponent: FunctionComponent<Props> = (props) => {
|
||||
setTimeout(async () => {
|
||||
setIsPreLoading(true);
|
||||
setIsLoading(true);
|
||||
const obj = await BrowserStorageWrapper.get<ObjDto<ObjPageDto>>(`${ObjectStoreKeys.OBJECT_ID}:${id}`);
|
||||
const obj = await new ObjGetCommand<ObjPageDto>(id).execute();
|
||||
setSnapshot(obj.data.snapshot);
|
||||
let c: ObjSnapshotData | undefined = undefined;
|
||||
if (obj.data.snapshot.contentId > 0) {
|
||||
|
@ -23,6 +23,9 @@ import { BoardDrawer } from './components/board/board/board-drawer';
|
||||
import { BoardMenu } from './components/board/board/board-menu';
|
||||
import { HtmlPreviewComponent } from './components/html-preview/html-preview.component';
|
||||
import { MuiThemeFactory } from '../common/components/react/mui-theme.factory';
|
||||
import { ObjGetCommand } from '../common/command/obj/obj-get.command';
|
||||
import { ObjPageDto } from '../common/model/obj/obj-pin.dto';
|
||||
import { ObjTypeDto } from '../common/model/obj/obj.dto';
|
||||
import { OptionsMessageHandler } from './options-message.handler';
|
||||
import { SettingsComponent } from './components/settings/settings.component';
|
||||
import ThemeProvider from '@mui/material/styles/ThemeProvider';
|
||||
@ -56,10 +59,32 @@ const OptionsUI: FunctionComponent = () => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleHashChange = () => {
|
||||
const handleHashChange = async () => {
|
||||
const view = getView();
|
||||
setCurrentView(view);
|
||||
setShowPreview(view === CurrentView.OBJ_DETAILS);
|
||||
if (view === CurrentView.OBJ_DETAILS) {
|
||||
await renderDetails();
|
||||
} else {
|
||||
setShowPreview(false);
|
||||
}
|
||||
};
|
||||
|
||||
const renderDetails = async () => {
|
||||
try {
|
||||
const idhash = window.location.hash.split('/')[1];
|
||||
const id = parseInt(idhash);
|
||||
// TODO optimize - don't get it twice once here, second inside object
|
||||
const obj = await new ObjGetCommand<ObjPageDto>(id).execute();
|
||||
if ([ObjTypeDto.PageElementPin, ObjTypeDto.PageElementSnapshot, ObjTypeDto.PageSnapshot].includes(obj.type)) {
|
||||
setShowPreview(true);
|
||||
} else {
|
||||
fnConsoleLog('TODO Implement !!!!');
|
||||
window.location.hash = '';
|
||||
}
|
||||
} catch (e) {
|
||||
fnConsoleLog('handleHashChange->error', e);
|
||||
window.location.hash = '';
|
||||
}
|
||||
};
|
||||
|
||||
const handleDrawer = () => {
|
||||
|
@ -14,10 +14,11 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { ObjDataDto, ObjDto } from '../../../common/model/obj/obj.dto';
|
||||
import { ObjRangeRequest, ObjRangeResponse } from 'src/common/model/obj-request.model';
|
||||
import { BrowserStorageWrapper } from '../../../common/service/browser.storage.wrapper';
|
||||
import { ICommand } from '../../../common/model/shared/common.dto';
|
||||
import { ObjDto } from '../../../common/model/obj/obj.dto';
|
||||
import { ObjGetCommand } from '../../../common/command/obj/obj-get.command';
|
||||
import { ObjRangeIdCommand } from '../../../common/command/obj/id/obj-range-id.command';
|
||||
import { ObjectStoreKeys } from '../../../common/keys/object.store.keys';
|
||||
import { OptionsSearchIdsCommand } from './options-search-ids.command';
|
||||
@ -51,8 +52,7 @@ export class OptionsObjGetRangeCommand implements ICommand<Promise<ObjRangeRespo
|
||||
|
||||
const data: ObjDto[] = [];
|
||||
for (const objId of ids) {
|
||||
const objKey = `${ObjectStoreKeys.OBJECT_ID}:${objId}`;
|
||||
const obj = await BrowserStorageWrapper.get<ObjDto>(objKey);
|
||||
const obj = await new ObjGetCommand<ObjDataDto>(objId).execute();
|
||||
if (!obj) {
|
||||
fnConsoleLog('Empty object !!!!!!!!!!!', objId);
|
||||
continue;
|
||||
@ -68,8 +68,7 @@ export class OptionsObjGetRangeCommand implements ICommand<Promise<ObjRangeRespo
|
||||
const data = await new ObjRangeIdCommand(listId, from, limit, true).execute();
|
||||
|
||||
for (let i = 0; i < data.ids.length; i++) {
|
||||
const key = `${ObjectStoreKeys.OBJECT_ID}:${data.ids[i]}`;
|
||||
const obj = await BrowserStorageWrapper.get<ObjDto>(key);
|
||||
const obj = await new ObjGetCommand<ObjDataDto>(data.ids[i]).execute();
|
||||
out.push(obj);
|
||||
}
|
||||
return {
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
import { BrowserStorageWrapper } from '../../../common/service/browser.storage.wrapper';
|
||||
import { ICommand } from '../../../common/model/shared/common.dto';
|
||||
import { ObjDto } from '../../../common/model/obj/obj.dto';
|
||||
import { ObjGetCommand } from '../../../common/command/obj/obj-get.command';
|
||||
import { ObjectStoreKeys } from '../../../common/keys/object.store.keys';
|
||||
|
||||
export class SyncFirstDateCommand implements ICommand<Promise<number>> {
|
||||
@ -31,7 +31,7 @@ export class SyncFirstDateCommand implements ICommand<Promise<number>> {
|
||||
i++;
|
||||
}
|
||||
// get object timestamp
|
||||
const obj = await BrowserStorageWrapper.get<ObjDto>(`${ObjectStoreKeys.OBJECT_ID}:${id}`);
|
||||
const obj = await new ObjGetCommand(id).execute();
|
||||
return obj.createdAt;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user