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

New templates Heat Pump installation #150

Merged
merged 29 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f08a8b3
Template for Ductless heat pump
sudhacheran Aug 3, 2023
458b68b
Merge branch 'main' into new_templates_heatpump_installation
sudhacheran Aug 8, 2023
535728e
Updates
sudhacheran Aug 8, 2023
a9c935a
updates
sudhacheran Aug 8, 2023
8877e70
fileupload functionality
sudhacheran Aug 10, 2023
abd4aa3
Merge branch 'main' into new_templates_heatpump_installation
sudhacheran Aug 10, 2023
a22f11b
Modified changes
sudhacheran Aug 10, 2023
98deff9
Adding second template
sudhacheran Aug 11, 2023
9ce842f
updated templates
sudhacheran Aug 14, 2023
22101f1
This includes changes for the following Issues
sudhacheran Aug 15, 2023
ff714b9
lint fix and changes from template review
sudhacheran Aug 16, 2023
a76d92d
Hint in Number Input
sudhacheran Aug 16, 2023
518e0ad
Change for Issue - Append a pdf to a project report #155
sudhacheran Aug 18, 2023
62af140
css addtion
sudhacheran Aug 18, 2023
a51eb52
CSS changes for H2
sudhacheran Aug 21, 2023
1869cb2
removed PORT change
sudhacheran Aug 21, 2023
8fad2bd
FileRenderer to PDFRenderer name change
sudhacheran Aug 21, 2023
72da608
Ductless template
sudhacheran Aug 22, 2023
190aa92
Merge branch 'main' into new_templates_heatpump_installation
sudhacheran Aug 22, 2023
4f9c3f9
Merge branch 'main' into new_templates_heatpump_installation
sudhacheran Aug 22, 2023
e7fc60b
Changes based on Ductless template Review
sudhacheran Aug 22, 2023
869de6e
linting fixes
sudhacheran Aug 22, 2023
9884aac
Merge branch 'main' into new_templates_heatpump_installation
sudhacheran Aug 24, 2023
390988b
Updated as per the review comments
sudhacheran Aug 24, 2023
b9846e7
BETA Version text
sudhacheran Aug 24, 2023
1742de4
beta text styling
sudhacheran Aug 24, 2023
595dc62
code comments text changed
sudhacheran Aug 24, 2023
5d7c890
store.tsx - syncing with main
sudhacheran Aug 24, 2023
f89ce7c
linting fix
sudhacheran Aug 24, 2023
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"react-bootstrap": "^2.7.2",
"react-dom": "^18.2.0",
"react-icons": "^4.7.1",
"react-pdf": "^7.3.3",
"react-refresh": "^0.11.0",
"react-router-bootstrap": "^0.26.2",
"react-router-dom": "^6.12.0",
Expand Down Expand Up @@ -105,7 +106,7 @@
"workbox-webpack-plugin": "^6.4.1"
},
"scripts": {
"start": "HTTPS=true node scripts/start.js",
"start": "HTTPS=true PORT=3006 node scripts/start.js",
sudhacheran marked this conversation as resolved.
Show resolved Hide resolved
"build": "TSC_COMPILE_ON_ERROR=true node scripts/build.js",
"test": "node scripts/test.js",
"lint": "NODE_ENV=development BABEL_ENV=development eslint 'src/**/*.{js,jsx,ts,tsx}'",
Expand Down
31 changes: 30 additions & 1 deletion public/print.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ h3 {

#back-button {
padding: 1rem;
background-color: green;
}

#back-button-link {
Expand Down Expand Up @@ -175,4 +176,32 @@ h3 {
/* stylizes tab component here to avoid putting styles in editor*/
.tab-content {
margin-top: 1rem;
}
}

/* custom label style */
.custom-label {
color: gray;
font-size: .9rem;
}

/* custom button style */
.custom-button {
background-color: gray;
font-size: .9rem;
border-color: gray;
}
.custom-button:hover{
background-color: gray;
border-color: gray;
color: black
}
.form-text{
margin-left:.50em;
margin-top:.25rem;
font-size:.875em;
color:var(--bs-secondary-color);
font-style: italic;
}
.react-pdf__Page__textContent{
display: none;
}
31 changes: 30 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ h3 {

#back-button {
padding: 1rem;
background-color: green;
}

#back-button-link {
Expand Down Expand Up @@ -175,4 +176,32 @@ h3 {
/* stylizes tab component here to avoid putting styles in editor*/
.tab-content {
margin-top: 1rem;
}
}

/* custom label style */
.custom-label {
color: gray;
font-size: .9rem;
}

/* custom button style */
.custom-button {
background-color: gray;
font-size: .9rem;
border-color: gray;
}
.custom-button:hover{
background-color: gray;
border-color: gray;
color: black
}
.form-text{
margin-left:.50em;
margin-top:.25rem;
font-size:.875em;
color:var(--bs-secondary-color);
font-style: italic;
}
.react-pdf__Page__textContent{
display: none;
}
109 changes: 109 additions & 0 deletions src/components/file_input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import React, { useEffect, useRef, useState } from 'react'
import type { ChangeEvent, FC, MouseEvent } from 'react'
import { Button, Card, Image } from 'react-bootstrap'
import Collapsible from './collapsible'
import type FileMetadata from '../types/file_metadata.types'
import DateTimeStr from './date_time_str'

interface FileInputProps {
children: React.ReactNode
label: string
metadata: FileMetadata
file: Blob | undefined
upsertFile: (file: Blob, fileName: string) => void
}

/**
* Component for File input
*
* @param children Content (most commonly markdown text) describing the File requirement
* @param label Label for the File requirement
* @param file Blob containing the File itself
* @param upsertFile Function used to update/insert a file into the store
*/
const FileInput: FC<FileInputProps> = ({
children,
label,
file,
metadata,
sudhacheran marked this conversation as resolved.
Show resolved Hide resolved
upsertFile,
}) => {
// Create references to the hidden file inputs
const hiddenFileUploadInputRef = useRef<HTMLInputElement>(null)

const handleFileInputButtonClick = (
event: MouseEvent<HTMLButtonElement>,
) => {
hiddenFileUploadInputRef.current &&
hiddenFileUploadInputRef.current.click()
}

const handleFileInputChange = (event: ChangeEvent<HTMLInputElement>) => {
if (event.target.files) {
const file = event.target.files[0]
const fileName = file.name
upsertFile(file, fileName)
}
}

// Button text based on whether there is a File or not
const buttonText = !file ? 'Add File' : 'Replace File'

return (
<>
<Card className="input-card">
<Card.Body>
<label className="custom-label"> {label} </label>
<Card.Text as="div" className="custom-label">
{children}
</Card.Text>
<div>
{file && (
<>
<Card className="input-card">
<Card.Body>
File Name:{' '}
<a
href={URL.createObjectURL(file)}
target="_blank"
>
{metadata?.filename}
</a>
<br />
<small>
Timestamp:&npsp;
{metadata?.timestamp ? (
<DateTimeStr
date={metadata.timestamp}
/>
) : (
''
)}
</small>
<br />
</Card.Body>
</Card>
</>
)}
<Button
onClick={handleFileInputButtonClick}
variant="outline-primary"
>
{buttonText}
</Button>
</div>

<input
accept="application/pdf"
onChange={handleFileInputChange}
ref={hiddenFileUploadInputRef}
className="photo-upload-input"
type="file"
/>
</Card.Body>
</Card>
</>
)
}

export default FileInput
44 changes: 44 additions & 0 deletions src/components/file_input_wrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { FC } from 'react'
import { StoreContext } from './store'
import FileInput from './file_input'

interface FileInputWrapperProps {
children: React.ReactNode
id: string
label: string
}

/**
* A component that wraps a FileInput component in order to tie it to the data store
*
* @param children Content (most commonly markdown text) to be passed on as the FileInput children
* @param id An identifier for the store attachment that represents the information of the file
* @param label The label of the PhotoInput component
*/
const FileInputWrapper: FC<FileInputWrapperProps> = ({
children,
id,
label,
}) => {
return (
<StoreContext.Consumer>
{({ attachments, upsertAttachment }) => {
charliepnnl marked this conversation as resolved.
Show resolved Hide resolved
const upsertFile = (img_file: Blob, fileName: string) => {
upsertAttachment(img_file, id, fileName)
}
return (
<FileInput
label={label}
metadata={attachments[id]?.metadata}
file={attachments[id]?.blob}
upsertFile={upsertFile}
>
{children}
</FileInput>
)
}}
</StoreContext.Consumer>
)
}

export default FileInputWrapper
44 changes: 44 additions & 0 deletions src/components/file_renderer.tsx
sudhacheran marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useState } from 'react'
import type { FC } from 'react'
import type FileMetadata from '../types/file_metadata.types'
import { Document, Page } from 'react-pdf'
import { pdfjs } from 'react-pdf'

pdfjs.GlobalWorkerOptions.workerSrc = new URL(
'pdfjs-dist/build/pdf.worker.min.js',
import.meta.url,
).toString();

interface FileRendererProps {
children: React.ReactNode
label: string
metadata: FileMetadata
sudhacheran marked this conversation as resolved.
Show resolved Hide resolved
file: Blob
}

/**
* Component for File input
*
* @param children Content (most commonly markdown text) describing the File requirement
* @param label Label for the File requirement
* @param file Blob containing the file itself
* @param upsertFile Function used to update/insert a file into the store
*/
const FileRenderer: FC<FileRendererProps> = ({ children, label, file, metadata }) => {
const [numPages, setNumPages] = useState(0);

return ( file && (
<div>
<h1>{label}: {metadata?.filename}</h1>
<Document file={file}
onLoadSuccess={({ numPages })=>setNumPages(numPages)}
renderMode="canvas">
{Array.apply(null, Array(numPages))
.map((x, i)=>i+1)
.map(page => <Page key={page} pageNumber={page} renderTextLayer={false} renderAnnotationLayer={false} />)}
</Document>
</div>)
)
}

export default FileRenderer
38 changes: 38 additions & 0 deletions src/components/file_renderer_wrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { FC } from 'react'
import { StoreContext } from './store'
import FileRenderer from './file_renderer'


const MAX_FILE_SIZE = 5 // in MB

interface FileRendererWrapperProps {
children: React.ReactNode
id: string
label: string
}

/**
* A component that wraps a FileRenderer component in order to tie it to the data store
*
* @param children Content (most commonly markdown text) to be passed on as the children
* @param id An identifier for the store attachment that represents the File details
* @param label The label the FileRenderer component
*/
const FileRenderedWrapper: FC<FileRendererWrapperProps> = ({ children, id, label }) => {
return (
<StoreContext.Consumer>
{({ attachments, upsertAttachment }) => {
sudhacheran marked this conversation as resolved.
Show resolved Hide resolved
return (
<FileRenderer
children={children}
label={label}
metadata={attachments[id]?.metadata}
file={attachments[id]?.blob}
/>
)
}}
</StoreContext.Consumer>
)
}

export default FileRenderedWrapper
4 changes: 4 additions & 0 deletions src/components/mdx_wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import PageBreak from './page_break'
import ProjectInfoInputs from '../templates/reusable/project_info_inputs.mdx'
import ProjectInfoReport from '../templates/reusable/project_info_report.mdx'
import PrintSectionWrapper from './print_section wrapper'
import FileInputWrapper from './file_input_wrapper'
import FileRendererWrapper from './file_renderer_wrapper'

const components = {
Collapsible,
Expand All @@ -45,6 +47,8 @@ const components = {
PageBreak: PageBreak,
ProjectInfoInputs: ProjectInfoInputs,
ProjectInfoReport: ProjectInfoReport,
FileInput: FileInputWrapper,
FileRenderer: FileRendererWrapper,
}

interface MdxWrapperProps {
Expand Down
Loading