<commit_before>// ==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 qs from "query-string";
import * as React from "react";
import { RouteComponentProps, withRouter } from "react-router-dom";

import { CatalogView} from "readium-desktop/common/views/catalog";

import LibraryLayout from "readium-desktop/renderer/components/layout/LibraryLayout";
import { withApi } from "readium-desktop/renderer/components/utils/api";
import { TranslatorProps } from "readium-desktop/renderer/components/utils/translator";
import Header, { DisplayType } from "./Header";

import GridView from "./GridView";
import ListView from "./ListView";

interface CatalogProps extends TranslatorProps, RouteComponentProps {
    catalog?: CatalogView;
    tags?: string[];
    requestCatalog: any;
}

export class Catalog extends React.Component<CatalogProps, undefined> {
    public render(): React.ReactElement<{}> {
        const { __ } = this.props;
        let DisplayView: any = GridView;
        let displayType = DisplayType.Grid;

        if (this.props.location) {
            const parsedResult = qs.parse(this.props.location.search);

            if (parsedResult.displayType === DisplayType.List) {
                DisplayView = ListView;
                displayType = DisplayType.List;
            }
        }

        const secondaryHeader = <Header displayType={ displayType } />;

        return (
            <LibraryLayout secondaryHeader={secondaryHeader} title={__("header.books")}>
                    { this.props.catalog &&
                        <DisplayView catalogEntries={ this.props.catalog.entries }
                        tags={this.props.tags}/>
                    }
            </LibraryLayout>
        );
    }
}

export default withApi(
    withRouter(Catalog),
    {
        operations: [
            {
                moduleId: "catalog",
                methodId: "get",
                callProp: "requestCatalog",
                resultProp: "catalog",
                onLoad: true,
            },
            {
                moduleId: "publication",
                methodId: "getAllTags",
                resultProp: "tags",
                onLoad: true,
            },
        ],
        refreshTriggers: [
            {
                moduleId: "publication",
                methodId: "import",
            },
            {
                moduleId: "publication",
                methodId: "importOpdsEntry",
            },
            {
                moduleId: "publication",
                methodId: "delete",
            },
            {
                moduleId: "catalog",
                methodId: "addEntry",
            },
            {
                moduleId: "publication",
                methodId: "updateTags",
            },
        ],
    },
);
<commit_msg>fix: catalog refresh (recent publications) when reading location changes (PR #635 Fixes #555)<commit_after>// ==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 qs from "query-string";
import * as React from "react";
import { RouteComponentProps, withRouter } from "react-router-dom";

import { CatalogView} from "readium-desktop/common/views/catalog";

import LibraryLayout from "readium-desktop/renderer/components/layout/LibraryLayout";
import { withApi } from "readium-desktop/renderer/components/utils/api";
import { TranslatorProps } from "readium-desktop/renderer/components/utils/translator";
import Header, { DisplayType } from "./Header";

import GridView from "./GridView";
import ListView from "./ListView";

interface Props extends TranslatorProps, RouteComponentProps {
    catalog?: CatalogView;
    tags?: string[];
    requestCatalog: any;
}

export class Catalog extends React.Component<Props> {
    public render(): React.ReactElement<{}> {
        const { __ } = this.props;
        let DisplayView: any = GridView;
        let displayType = DisplayType.Grid;

        if (this.props.location) {
            const parsedResult = qs.parse(this.props.location.search);

            if (parsedResult.displayType === DisplayType.List) {
                DisplayView = ListView;
                displayType = DisplayType.List;
            }
        }

        const secondaryHeader = <Header displayType={ displayType } />;

        return (
            <LibraryLayout secondaryHeader={secondaryHeader} title={__("header.books")}>
                    { this.props.catalog &&
                        <DisplayView catalogEntries={ this.props.catalog.entries }
                        tags={this.props.tags}/>
                    }
            </LibraryLayout>
        );
    }
}

export default withApi(
    withRouter(Catalog),
    {
        operations: [
            {
                moduleId: "catalog",
                methodId: "get",
                callProp: "requestCatalog",
                resultProp: "catalog",
                onLoad: true,
            },
            {
                moduleId: "publication",
                methodId: "getAllTags",
                resultProp: "tags",
                onLoad: true,
            },
        ],
        refreshTriggers: [
            {
                moduleId: "publication",
                methodId: "import",
            },
            {
                moduleId: "publication",
                methodId: "importOpdsEntry",
            },
            {
                moduleId: "publication",
                methodId: "delete",
            },
            {
                moduleId: "catalog",
                methodId: "addEntry",
            },
            {
                moduleId: "publication",
                methodId: "updateTags",
            },
            {
                moduleId: "reader",
                methodId: "setLastReadingLocation",
            },
        ],
    },
);

{'fraction_non_alphanumeric': 0.10540287320424735, 'fraction_numerical': 0.0021861336664584633, 'mean_word_length': 1.7607758620689655, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1359045', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1560, 'n_words': 405}