Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/common/redux/actions/publication/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { IPublicationCheckerState } from "../../states/publicationsChecker";
export const ID = "PUBLICATION_CHECKER";

export interface Payload extends IPublicationCheckerState {
open: boolean;
}

export function build(s: IPublicationCheckerState):
Action<typeof ID, Payload> {

return {
type: ID,
payload: JSON.parse(JSON.stringify(s)),
payload: { ...JSON.parse(JSON.stringify(s)), open: true },
};
}
build.toString = () => ID; // Redux StringableActionCreator
Expand Down
4 changes: 4 additions & 0 deletions src/common/redux/states/renderer/libraryRootState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { IOpdsHeaderState, IOpdsSearchState } from "./opds";
import { CatalogView } from "readium-desktop/common/views/catalog";
import { IWizardState } from "../wizard";
import { ISettingsState } from "../settings";
import { IPublicationCheckerState } from "../publicationsChecker";

export interface ILibraryRootState extends IRendererCommonRootState {
opds: {
Expand All @@ -36,4 +37,7 @@ export interface ILibraryRootState extends IRendererCommonRootState {
}
wizard: IWizardState;
settings: ISettingsState;
publicationIntegrityChecker: {
open: true;
} & IPublicationCheckerState | { open: false };
}
2 changes: 2 additions & 0 deletions src/renderer/library/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { CustomizationProfileDialog } from "readium-desktop/renderer/common/comp
// globalScssStyle.__LOAD_FILE_SELECTOR_NOT_USED_JUST_TO_TRIGGER_WEBPACK_SCSS_FILE__;

import { shell } from "electron";
import { PublicationCheckerModal } from "./PublicationCheckerModal";

(window as any).__shell_openExternal = (url: string) => url && /^https?:\/\//.test(url) ? shell.openExternal(url) : Promise.resolve(); // needed after markdown marked parsing for sanitizing the external anchor href

Expand Down Expand Up @@ -230,6 +231,7 @@ export default class App extends React.Component<{}, undefined> {
<LoaderMainLoad />
<ToastManager />
<WizardModal />
<PublicationCheckerModal />
<CustomizationProfileDialog />
</div>;
}}
Expand Down
152 changes: 152 additions & 0 deletions src/renderer/library/components/PublicationCheckerModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// ==LICENSE-BEGIN==
// Copyright 2017 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.
// ==LICENSE-END==

import * as stylesModals from "readium-desktop/renderer/assets/styles/components/modals.scss";
import * as stylesButtons from "readium-desktop/renderer/assets/styles/components/buttons.scss";

import * as React from "react";
import * as Dialog from "@radix-ui/react-dialog";
import classNames from "classnames";
import { useTranslator } from "readium-desktop/renderer/common/hooks/useTranslator";
import { useDispatch } from "readium-desktop/renderer/common/hooks/useDispatch";
// import { publicationActions as publicationActionsCommon, wizardActions } from "readium-desktop/common/redux/actions";

import { useSelector } from "readium-desktop/renderer/common/hooks/useSelector";
import { ILibraryRootState } from "readium-desktop/common/redux/states/renderer/libraryRootState";
import { publicationActions } from "../redux/actions";
import { IPublicationCheckerState } from "readium-desktop/common/redux/states/publicationsChecker";
import { useApi } from "readium-desktop/renderer/common/hooks/useApi";

export const PublicationCheckerModal = () => {
const [__] = useTranslator();
const dispatch = useDispatch();
const publicationCheckerState = useSelector((state: ILibraryRootState) => state.publicationIntegrityChecker);
const [, deletePublication] = useApi(undefined, "publication/delete");
const [, openPublicationFolder] = useApi(undefined, "publication/openFolder");

const { open } = publicationCheckerState;

const {
publicationIdentifierDataBase,
approvedPublicationIdentifierDisk,
rejectedPublicationIdentifierDisk,
dump,
} = open ? publicationCheckerState : {} as IPublicationCheckerState;

const publicationIdentifierDisk = [...approvedPublicationIdentifierDisk, ...rejectedPublicationIdentifierDisk];
const publicationIdentifierNotFoundOnDiskButFoundOnDataBase: string[] = publicationIdentifierDataBase?.filter((id) => !publicationIdentifierDisk.includes(id)) || [];
const publicationIdentifierNotFoundOnDataBaseButFoundOnDisk: string[] = publicationIdentifierDisk?.filter((id) => !publicationIdentifierDataBase.includes(id)) || [];

return <Dialog.Root defaultOpen={open} onOpenChange={(openState: boolean) => {
if (openState == false) {
dispatch(publicationActions.closePublicationChecker.build());
}
}}
>
{/* <Dialog.Trigger asChild>
<button title={__("header.settings")}>
<h3>Visite Guidée</h3>
</button>
</Dialog.Trigger> */}
<Dialog.Portal>
<div className={stylesModals.modal_dialog_overlay}></div>
<Dialog.Content className={classNames(stylesModals.modal_dialog)} aria-describedby={undefined}>

<h1>Publication Integrity Checker</h1>

<h3>Publication vault folder Path:</h3>
<button onClick={() => openPublicationFolder()}>OPEN FOLDER</button>

<hr /><br />

<h3>Publication(s) Not Found On Disk But Found On DataBase:</h3>
{
publicationIdentifierNotFoundOnDiskButFoundOnDataBase.length ?

<>
<table>
<tr>
<th>PubID</th>
<th>Actions</th>
</tr>
{
publicationIdentifierNotFoundOnDiskButFoundOnDataBase.map((id) => {
return <>
<tr key={id}>
<td>{id}</td>
<td>
<button onClick={() => {
deletePublication(id);
}}>DELETE</button>
{/* TODO?: <button>EXPORT DATA PREFERENCE</button> */}
</td>
</tr>

</>;
})
}
</table>

</> : <></>
}

<h3>Publication(s) Not Found On DataBase But Found On Disk:</h3>
{
publicationIdentifierNotFoundOnDataBaseButFoundOnDisk.length ?

<>
<table>
<tr>
<th>PubID</th>
<th>Actions</th>
</tr>
{
publicationIdentifierNotFoundOnDataBaseButFoundOnDisk.map((id) => {
return <>
<tr key={id}>
<td>{id}</td>
<td>
<button onClick={() => {
deletePublication(id);
}}>DELETE</button>
<button onClick={() => {
openPublicationFolder(id);
}}>OPEN FOLDER</button>
</td>
</tr>

</>;
})
}
</table>

</> : <></>
}

<hr /><br />

<details>
<summary>DUMP:</summary>
<pre>{dump}</pre>
</details>

<div className={stylesModals.modal_dialog_footer}>
<Dialog.Close asChild>
<button className={stylesButtons.button_secondary_blue}>{__("dialog.cancel")}</button>
</Dialog.Close>
{/* <Dialog.Close asChild>
<button type="submit" disabled={!title || !url} className={stylesButtons.button_primary_blue} onClick={() => addAction()}>
<SVG ariaHidden svg={AddIcon} />
{__("opds.addForm.addButton")}
</button>
</Dialog.Close> */}
</div>

</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>;
};
2 changes: 2 additions & 0 deletions src/renderer/library/redux/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import * as opdsActions from "./opds";
import * as routerActions from "./router";
import * as winActions from "./win";
import * as publicationActions from "./publication";

export {
routerActions,
opdsActions,
winActions,
publicationActions,
};
27 changes: 27 additions & 0 deletions src/renderer/library/redux/actions/publication/close.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// ==LICENSE-BEGIN==
// Copyright 2017 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.
// ==LICENSE-END==

import { Action } from "readium-desktop/common/models/redux";

export const ID = "PUBLICATION_CHECKER_CLOSE";

export interface Payload {
open: false;
}

export function build():
Action<typeof ID, Payload> {

return {
type: ID,
payload: {
open: false,
},
};
}
build.toString = () => ID; // Redux StringableActionCreator
export type TAction = ReturnType<typeof build>;
12 changes: 12 additions & 0 deletions src/renderer/library/redux/actions/publication/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// ==LICENSE-BEGIN==
// Copyright 2017 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.
// ==LICENSE-END==

import * as closePublicationChecker from "./close";

export {
closePublicationChecker,
};
2 changes: 2 additions & 0 deletions src/renderer/library/redux/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { arrayReducer } from "readium-desktop/utils/redux-reducers/array.reducer
import { ICustomizationProfileHistory } from "readium-desktop/common/redux/states/customization";
import { customizationPackageWelcomeScreenReducer } from "readium-desktop/common/redux/reducers/customization/welcomeScreen";
import { customizationPackageManifestReducer } from "readium-desktop/common/redux/reducers/customization/manifest";
import { publicationIntegrityCheckerReducer } from "./publicationIntegrityChecker";

export const rootReducer = (routerReducer: Reducer<RouterState>) => { // : Reducer<Partial<ILibraryRootState>>
return combineReducers({ // ILibraryRootState
Expand Down Expand Up @@ -125,5 +126,6 @@ export const rootReducer = (routerReducer: Reducer<RouterState>) => { // : Reduc
welcomeScreen: customizationPackageWelcomeScreenReducer,
manifest: customizationPackageManifestReducer,
}),
publicationIntegrityChecker: publicationIntegrityCheckerReducer,
});
};
38 changes: 38 additions & 0 deletions src/renderer/library/redux/reducers/publicationIntegrityChecker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// ==LICENSE-BEGIN==
// Copyright 2017 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.
// ==LICENSE-END==

import { type Reducer } from "redux";

import { IPublicationCheckerState } from "readium-desktop/common/redux/states/publicationsChecker";
import { publicationActions } from "readium-desktop/common/redux/actions";
import { publicationActions as publicationActionsLibrary } from "../actions";

const initialState: {
open: true;
} & IPublicationCheckerState | { open: false } = {
open: false,
};

function publicationIntegrityCheckerReducer_(
state: {
open: true;
} & IPublicationCheckerState | { open: false } = initialState,
action: publicationActionsLibrary.closePublicationChecker.TAction | publicationActions.checker.TAction,
): {
open: true;
} & IPublicationCheckerState | { open: false } {
switch (action.type) {
case publicationActionsLibrary.closePublicationChecker.ID:
return action.payload;
case publicationActions.checker.ID:
return action.payload;
default:
return state;
}
}

export const publicationIntegrityCheckerReducer = publicationIntegrityCheckerReducer_ as Reducer<ReturnType<typeof publicationIntegrityCheckerReducer_>>;
Loading