Skip to content

Commit

Permalink
Merge branch 'main' into feat-move-docker-config
Browse files Browse the repository at this point in the history
  • Loading branch information
melMass authored Oct 27, 2023
2 parents d2121f3 + 4102c3b commit b8048e0
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/components/collab/show/TxRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const TxRow = ({ tx, index, onAdd, onRemove }: TxRowProps) => {
}
}}
onKeyDown={handleKeyDown}
onBlur={handleAdd}
/>
</td>
{onRemove && (
Expand Down
2 changes: 2 additions & 0 deletions src/components/form/MintForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export default function MintForm() {
.show(`File too big: ${data.artifact.file.size / 1e6}mb`)
return
}
const URL = window.URL || window.webkitURL
data.artifact.reader = URL.createObjectURL(data.artifact.file)
}
useMintStore.setState({ ...data, isValid: true })
navigate('preview')
Expand Down
85 changes: 62 additions & 23 deletions src/components/media-types/pdf/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const PdfComponent = memo(function ({
const [pageNumber, setPageNumber] = useState(1)
const [renderedPageNumber, setRenderedPageNumber] = useState<number>()
const [loading, setLoading] = useState(displayView)
const [showDocument, setShowDocument] = useState(true)

const [height, setHeight] = useState<number>()

Expand All @@ -43,7 +44,7 @@ export const PdfComponent = memo(function ({
}

function onDocumentLoadError(e: Error) {
throw Error(e.message, { cause: 'PDF Error' })
console.error(`PDF Error: ${e.message}`)
}

function changePage(offset: number) {
Expand All @@ -70,6 +71,32 @@ export const PdfComponent = memo(function ({
setRenderedPageNumber(pageNumber)
}

function onPassword(callback, reason) {
function callbackProxy(password) {
// Cancel button handler
if (password === null) {
// password will be null if user clicks on cancel
setShowDocument(false)
return
}
callback(password)
}

switch (reason) {
case 1: {
const password = prompt('Enter the password to open this PDF file.')
callbackProxy(password)
break
}
case 2: {
const password = prompt('Invalid password. Please try again.')
callbackProxy(password)
break
}
default:
}
}

const cover = (
<>
<ImageComponent
Expand All @@ -96,33 +123,45 @@ export const PdfComponent = memo(function ({
// })
// const loading = renderedPageNumber !== pageNumber
if (!displayView) return cover

return (
<div ref={container} className={styles.container}>
<Document
file={file}
loading={cover}
onLoadSuccess={onDocumentLoadSuccess}
onLoadError={onDocumentLoadError}
title={`PDF object ${nft.token_id}`}
options={options}
>
{renderedPageNumber && renderedPageNumber !== pageNumber && (
{!showDocument ? (
<Button
onClick={() => {
setShowDocument(true)
}}
>
Reload PDF with password
</Button>
) : (
<Document
file={file}
loading={cover}
onPassword={onPassword}
onLoadSuccess={onDocumentLoadSuccess}
onLoadError={onDocumentLoadError}
title={`PDF object ${nft.token_id}`}
options={options}
>
{renderedPageNumber && renderedPageNumber !== pageNumber && (
<Page
key={`${renderedPageNumber}`}
className={styles.previous_page}
pageNumber={renderedPageNumber}
height={height}
/>
)}
<Page
key={`${renderedPageNumber}`}
className={styles.previous_page}
pageNumber={renderedPageNumber}
key={pageNumber}
className={styles.page}
pageNumber={pageNumber}
onRenderSuccess={onRender}
height={height}
/>
)}
<Page
key={pageNumber}
className={styles.page}
pageNumber={pageNumber}
onRenderSuccess={onRender}
height={height}
/>
</Document>
{!loading && (
</Document>
)}
{!loading && showDocument && (
<div className={styles.pdfNav}>
<Button disabled={pageNumber <= 1} onClick={previousPage}>
{'Prev «'}
Expand Down
2 changes: 1 addition & 1 deletion src/components/preview/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Field = ({ title, value }) => {
value && (
<div className={styles.field}>
<strong>{title}:</strong>
{value}
<p>{value}</p>
</div>
)
)
Expand Down
14 changes: 13 additions & 1 deletion src/data/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,19 @@ export const prepareFile = async ({

// upload thumbnail image
let thumbnailUri = IPFS_DEFAULT_THUMBNAIL_URI
if (thumbnail) {
if (thumbnail && thumbnail.file?.type === 'image/gif') {
console.debug(
"GIF format detected, we will use the artifact's cid as the thumbnail to avoid uploading twice"
)
thumbnailUri = `${uri}`
if (thumbnail?.format) {
const format = JSON.parse(JSON.stringify(thumbnail.format))
format.uri = thumbnailUri
format.fileName = `thumbnail_${format.fileName}`
formats.push(format)
console.debug('thumbnail format', format)
}
} else if (thumbnail) {
const thumbnailCid = await uploadFileToIPFSProxy({
blob: new Blob([thumbnail.buffer]),
path: `thumbnail_${
Expand Down
8 changes: 5 additions & 3 deletions src/pages/config/Subjkt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,13 @@ export const Subjkt = () => {
value={subjkt}
onChange={setSubjkt}
onBlur={(e) => {
setSubjkt(e.target.value.replace(/[^a-z0-9-._]/g, ''))
if(/[^A-Za-z0-9-._]/.test(e.target.value)) {
show('Subjkt contains invalid characters. This field can only contain: letters (a-z A-Z), numbers (0-9), . (dot), - (dash), _ (underscore)')
}
}}
placeholder="can contain letters (a-z), numbers (0-9), . (dot), - (dash), _ (underscore)"
placeholder="can contain letters (a-z A-Z), numbers (0-9), . (dot), - (dash), _ (underscore)"
label="Username"
pattern="^[a-z0-9-._]*$"
pattern="^[A-Za-z0-9-._]*$"
/>
<Input
name="description"
Expand Down
2 changes: 1 addition & 1 deletion src/pages/mint/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const fields = [
type: 'file',
watch: true,
rules: {
required: 'No file selected',
required: 'You did not select a valid file',
},
},
{
Expand Down

0 comments on commit b8048e0

Please sign in to comment.