From 14ef40029dbda1c60495ebb01cc6369cf6ce45af Mon Sep 17 00:00:00 2001 From: Srinath Narayanan Date: Fri, 31 Jul 2020 12:31:05 -0700 Subject: [PATCH] Added session based view updation for gallery notebooks (#120) --- .../NotebookViewer/NotebookViewerComponent.tsx | 5 +++-- src/Shared/StorageUtility.ts | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Explorer/Controls/NotebookViewer/NotebookViewerComponent.tsx b/src/Explorer/Controls/NotebookViewer/NotebookViewerComponent.tsx index 6658bca43..024d3c90e 100644 --- a/src/Explorer/Controls/NotebookViewer/NotebookViewerComponent.tsx +++ b/src/Explorer/Controls/NotebookViewer/NotebookViewerComponent.tsx @@ -19,6 +19,7 @@ import { DialogComponent, DialogProps } from "../DialogReactComponent/DialogComp import { NotebookMetadataComponent } from "./NotebookMetadataComponent"; import "./NotebookViewerComponent.less"; import Explorer from "../../Explorer"; +import { SessionStorageUtility } from "../../../Shared/StorageUtility"; export interface NotebookViewerComponentProps { container?: Explorer; @@ -88,13 +89,13 @@ export class NotebookViewerComponent extends React.Component< this.notebookComponentBootstrapper.setContent("json", notebook); this.setState({ content: notebook, showProgressBar: false }); - if (this.props.galleryItem) { + if (this.props.galleryItem && !SessionStorageUtility.getEntry(this.props.galleryItem.id)) { const response = await this.props.junoClient.increaseNotebookViews(this.props.galleryItem.id); if (!response.data) { throw new Error(`Received HTTP ${response.status} while increasing notebook views`); } - this.setState({ galleryItem: response.data }); + SessionStorageUtility.setEntry(this.props.galleryItem?.id, "true"); } } catch (error) { this.setState({ showProgressBar: false }); diff --git a/src/Shared/StorageUtility.ts b/src/Shared/StorageUtility.ts index 657bf8d6e..64803e8f6 100644 --- a/src/Shared/StorageUtility.ts +++ b/src/Shared/StorageUtility.ts @@ -44,7 +44,11 @@ export class SessionStorageUtility { } public static getEntryNumber(key: StorageKey): number { - return StringUtility.toNumber(localStorage.getItem(StorageKey[key])); + return StringUtility.toNumber(sessionStorage.getItem(StorageKey[key])); + } + + public static getEntry(key: string): string | null { + return sessionStorage.getItem(key); } public static removeEntry(key: StorageKey): void { @@ -55,6 +59,10 @@ export class SessionStorageUtility { sessionStorage.setItem(StorageKey[key], value); } + public static setEntry(key: string, value: string): void { + sessionStorage.setItem(key, value); + } + public static setEntryNumber(key: StorageKey, value: number): void { sessionStorage.setItem(StorageKey[key], value.toString()); }