Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF Viewer: embedded viewer options #6800

Merged
merged 8 commits into from
Sep 5, 2022
Merged

Conversation

asrient
Copy link
Contributor

@asrient asrient commented Sep 1, 2022

This is a the newer version of previously opened PR #6750.
I created a new PR since my updates were on a separate branch and the merge conflicts were too must to handle for this.
This should not be an issue since code review has not yet started for this feature.

Features added to the viewer

  • Print pdf.
  • Download pdf.
  • Current active page indicator.

Screenshot

Screen Shot 2022-09-01 at 6 13 49 PM

hoverColor?: string;
}

export function Button({ onClick, icon, name, size, color, hoverColor }: ButtonProps) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be private, so don't export

import { useRef, useEffect, MutableRefObject } from 'react';
import { ScaledSize } from '../pdfSource';
import { useRef, useEffect, MutableRefObject, useState } from 'react';
import { ScaledSize, PdfData } from '../pdfSource';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing about computers is that pretty much everything is "data" so creating a SomethingData class doesn't mean much. What is PdfData? Isn't it a wrapper around the PDF document? Then call it "PdfDocument". Also please create a separate file for it called PdfDocument.ts. Put ScaledSize in a separate types.ts file.


export interface ScrollSaver {
container: MutableRefObject<HTMLElement>;
scaledSize: ScaledSize;
pdfId: string;
rememberScroll: boolean;
onActivePageChange?: (activePage: number)=> void;
pdf: PdfData;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pdf => pdfDocument


export interface ScrollSaver {
container: MutableRefObject<HTMLElement>;
scaledSize: ScaledSize;
pdfId: string;
rememberScroll: boolean;
onActivePageChange?: (activePage: number)=> void;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make "onActivePageChange" required. As much as possible avoid optional stuff, especially when it's not really optional in your code (since you always set it).


export interface ScrollSaver {
container: MutableRefObject<HTMLElement>;
scaledSize: ScaledSize;
pdfId: string;
rememberScroll: boolean;
onActivePageChange?: (activePage: number)=> void;
pdf: PdfData;
pageGap?: number;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it required

return <MiniViewerApp pdfPath={url} isDarkTheme={appearance === 'dark'} anchorPage={anchorPage ? Number(anchorPage) : null} pdfId={pdfId} />;
return <MiniViewerApp pdfPath={url}
isDarkTheme={appearance === 'dark'}
anchorPage={anchorPage ? Number(anchorPage) : null}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert anchorPage to a number (or null) at the point where you get the attribute (so above). Otherwise you have to cast it to int everywhere.

};

public printPdf = () => {
const frame = document.createElement('iframe');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass "document" to the PdfData (now PdfDocument) class and make it a private property. In general class code shouldn't access the DOM directly or any global variable, as that makes it more difficult to test the code.

Comment on lines 26 to 31
icon?: IconDefinition;
onClick?: ()=> void;
name?: string;
size?: number;
color?: string;
hoverColor?: string;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these all optional? You're setting al of them every time so make them required. Required properties are easier to deal with, especially when refactoring code. Optional properties are good mostly for public APIs, but for internal code it's rarely needed and doesn't help much.

@laurent22
Copy link
Owner

Ok let's merge

@laurent22 laurent22 merged commit 1504cb7 into laurent22:dev Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants