Skip to content

Commit

Permalink
feat: 差分を表示するようにしました (#10)
Browse files Browse the repository at this point in the history
* feat: pdf を表示するコンポーネントを作成しました

* chore: pdf を見やすくしました

* feat: 差分を表示するようにしました

---------

Co-authored-by: Keisuke Ishigami <[email protected]>
  • Loading branch information
kei01234kei and kei01234kei authored Feb 15, 2024
1 parent 1feb685 commit 005e7b3
Show file tree
Hide file tree
Showing 175 changed files with 1,411 additions and 73 deletions.
5 changes: 5 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
const nextConfig = {
reactStrictMode: true,
transpilePackages: ['@recordex/smartcontract'],
// 参考: https://github.com/wojtekmaj/react-pdf?tab=readme-ov-file#nextjs
webpack: (config) => {
config.resolve.alias.canvas = false;
return config;
},
};

module.exports = nextConfig;
1,200 changes: 1,174 additions & 26 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
"jotai": "^2.5.0",
"next": "14.0.3",
"react": "^18",
"react-dom": "^18"
"react-dom": "^18",
"react-pdf": "^7.7.0"
},
"devDependencies": {
"@types/google.maps": "^3.54.5",
"@types/node": "^20",
"@types/pdfjs-dist": "^2.10.378",
"@types/react": "^18",
"@types/react-dom": "^18",
"@typescript-eslint/eslint-plugin": "^6.9.0",
Expand All @@ -45,8 +47,10 @@
"eslint-plugin-unused-imports": "^3.0.0",
"husky": "^8.0.3",
"lint-staged": "^15.0.2",
"pdfjs-dist": "^4.0.379",
"prettier": "^3.0.3",
"typescript": "^5"
"typescript": "^5",
"webpack": "^5.90.1"
},
"lint-staged": {
"src/**/*": "npm run fix"
Expand Down
Binary file added public/cmaps/78-EUC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/78-EUC-V.bcmap
Binary file not shown.
Binary file added public/cmaps/78-H.bcmap
Binary file not shown.
Binary file added public/cmaps/78-RKSJ-H.bcmap
Binary file not shown.
Binary file added public/cmaps/78-RKSJ-V.bcmap
Binary file not shown.
Binary file added public/cmaps/78-V.bcmap
Binary file not shown.
Binary file added public/cmaps/78ms-RKSJ-H.bcmap
Binary file not shown.
Binary file added public/cmaps/78ms-RKSJ-V.bcmap
Binary file not shown.
Binary file added public/cmaps/83pv-RKSJ-H.bcmap
Binary file not shown.
Binary file added public/cmaps/90ms-RKSJ-H.bcmap
Binary file not shown.
Binary file added public/cmaps/90ms-RKSJ-V.bcmap
Binary file not shown.
Binary file added public/cmaps/90msp-RKSJ-H.bcmap
Binary file not shown.
Binary file added public/cmaps/90msp-RKSJ-V.bcmap
Binary file not shown.
Binary file added public/cmaps/90pv-RKSJ-H.bcmap
Binary file not shown.
Binary file added public/cmaps/90pv-RKSJ-V.bcmap
Binary file not shown.
Binary file added public/cmaps/Add-H.bcmap
Binary file not shown.
Binary file added public/cmaps/Add-RKSJ-H.bcmap
Binary file not shown.
Binary file added public/cmaps/Add-RKSJ-V.bcmap
Binary file not shown.
Binary file added public/cmaps/Add-V.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-CNS1-0.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-CNS1-1.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-CNS1-2.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-CNS1-3.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-CNS1-4.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-CNS1-5.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-CNS1-6.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-CNS1-UCS2.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-GB1-0.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-GB1-1.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-GB1-2.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-GB1-3.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-GB1-4.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-GB1-5.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-GB1-UCS2.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-Japan1-0.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-Japan1-1.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-Japan1-2.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-Japan1-3.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-Japan1-4.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-Japan1-5.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-Japan1-6.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-Japan1-UCS2.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-Korea1-0.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-Korea1-1.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-Korea1-2.bcmap
Binary file not shown.
Binary file added public/cmaps/Adobe-Korea1-UCS2.bcmap
Binary file not shown.
Binary file added public/cmaps/B5-H.bcmap
Binary file not shown.
Binary file added public/cmaps/B5-V.bcmap
Binary file not shown.
Binary file added public/cmaps/B5pc-H.bcmap
Binary file not shown.
Binary file added public/cmaps/B5pc-V.bcmap
Binary file not shown.
Binary file added public/cmaps/CNS-EUC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/CNS-EUC-V.bcmap
Binary file not shown.
Binary file added public/cmaps/CNS1-H.bcmap
Binary file not shown.
Binary file added public/cmaps/CNS1-V.bcmap
Binary file not shown.
Binary file added public/cmaps/CNS2-H.bcmap
Binary file not shown.
3 changes: 3 additions & 0 deletions public/cmaps/CNS2-V.bcmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
�RCopyright 1990-2009 Adobe Systems Incorporated.
All rights reserved.
See ./LICENSE�CNS2-H
Binary file added public/cmaps/ETHK-B5-H.bcmap
Binary file not shown.
Binary file added public/cmaps/ETHK-B5-V.bcmap
Binary file not shown.
Binary file added public/cmaps/ETen-B5-H.bcmap
Binary file not shown.
Binary file added public/cmaps/ETen-B5-V.bcmap
Binary file not shown.
3 changes: 3 additions & 0 deletions public/cmaps/ETenms-B5-H.bcmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
�RCopyright 1990-2009 Adobe Systems Incorporated.
All rights reserved.
See ./LICENSE� ETen-B5-H` ^
Binary file added public/cmaps/ETenms-B5-V.bcmap
Binary file not shown.
Binary file added public/cmaps/EUC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/EUC-V.bcmap
Binary file not shown.
Binary file added public/cmaps/Ext-H.bcmap
Binary file not shown.
Binary file added public/cmaps/Ext-RKSJ-H.bcmap
Binary file not shown.
Binary file added public/cmaps/Ext-RKSJ-V.bcmap
Binary file not shown.
Binary file added public/cmaps/Ext-V.bcmap
Binary file not shown.
Binary file added public/cmaps/GB-EUC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/GB-EUC-V.bcmap
Binary file not shown.
4 changes: 4 additions & 0 deletions public/cmaps/GB-H.bcmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
�RCopyright 1990-2009 Adobe Systems Incorporated.
All rights reserved.
See ./LICENSE!!��]aX!!]`�21�> �p �z�$]��"R�d�-U�7�*�4�%�+ �Z �{�/�%�<�9K�b�1]�.�"� �`]�,�"]�
�"]�h�"]�F�"]�$�"]��"]�`�"]�>�"]��"]�z�"]�X�"]�6�"]��"]�r�"]�P�"]�.�"]� �"]�j�"]�H�"]�&�"]��"]�b�"]�@�"]��"]�|�"]�Z�"]�8�"]��"]�t�"]�R�"]�0�"]��"]�l�"]�J�"]�(�"]��"]�d�"]�B�"]� �"X�~�']�W�"]�5�"]��"]�q�"]�O�"]�-�"]� �"]�i�"]�G�"]�%�"]��"]�a�"]�?�"]��"]�{�"]�Y�"]�7�"]��"]�s�"]�Q�"]�/�"]��"]�k�"]�I�"]�'�"]��"]�c�"]�A�"]��"]�}�"]�[�"]�9
Expand Down
Binary file added public/cmaps/GB-V.bcmap
Binary file not shown.
Binary file added public/cmaps/GBK-EUC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/GBK-EUC-V.bcmap
Binary file not shown.
Binary file added public/cmaps/GBK2K-H.bcmap
Binary file not shown.
Binary file added public/cmaps/GBK2K-V.bcmap
Binary file not shown.
Binary file added public/cmaps/GBKp-EUC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/GBKp-EUC-V.bcmap
Binary file not shown.
Binary file added public/cmaps/GBT-EUC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/GBT-EUC-V.bcmap
Binary file not shown.
Binary file added public/cmaps/GBT-H.bcmap
Binary file not shown.
Binary file added public/cmaps/GBT-V.bcmap
Binary file not shown.
Binary file added public/cmaps/GBTpc-EUC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/GBTpc-EUC-V.bcmap
Binary file not shown.
Binary file added public/cmaps/GBpc-EUC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/GBpc-EUC-V.bcmap
Binary file not shown.
Binary file added public/cmaps/H.bcmap
Binary file not shown.
Binary file added public/cmaps/HKdla-B5-H.bcmap
Binary file not shown.
Binary file added public/cmaps/HKdla-B5-V.bcmap
Binary file not shown.
Binary file added public/cmaps/HKdlb-B5-H.bcmap
Binary file not shown.
Binary file added public/cmaps/HKdlb-B5-V.bcmap
Binary file not shown.
Binary file added public/cmaps/HKgccs-B5-H.bcmap
Binary file not shown.
Binary file added public/cmaps/HKgccs-B5-V.bcmap
Binary file not shown.
Binary file added public/cmaps/HKm314-B5-H.bcmap
Binary file not shown.
Binary file added public/cmaps/HKm314-B5-V.bcmap
Binary file not shown.
Binary file added public/cmaps/HKm471-B5-H.bcmap
Binary file not shown.
Binary file added public/cmaps/HKm471-B5-V.bcmap
Binary file not shown.
Binary file added public/cmaps/HKscs-B5-H.bcmap
Binary file not shown.
Binary file added public/cmaps/HKscs-B5-V.bcmap
Binary file not shown.
Binary file added public/cmaps/Hankaku.bcmap
Binary file not shown.
Binary file added public/cmaps/Hiragana.bcmap
Binary file not shown.
Binary file added public/cmaps/KSC-EUC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/KSC-EUC-V.bcmap
Binary file not shown.
Binary file added public/cmaps/KSC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/KSC-Johab-H.bcmap
Binary file not shown.
Binary file added public/cmaps/KSC-Johab-V.bcmap
Binary file not shown.
Binary file added public/cmaps/KSC-V.bcmap
Binary file not shown.
Binary file added public/cmaps/KSCms-UHC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/KSCms-UHC-HW-H.bcmap
Binary file not shown.
Binary file added public/cmaps/KSCms-UHC-HW-V.bcmap
Binary file not shown.
Binary file added public/cmaps/KSCms-UHC-V.bcmap
Binary file not shown.
Binary file added public/cmaps/KSCpc-EUC-H.bcmap
Binary file not shown.
Binary file added public/cmaps/KSCpc-EUC-V.bcmap
Binary file not shown.
Binary file added public/cmaps/Katakana.bcmap
Binary file not shown.
36 changes: 36 additions & 0 deletions public/cmaps/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
%%Copyright: -----------------------------------------------------------
%%Copyright: Copyright 1990-2009 Adobe Systems Incorporated.
%%Copyright: All rights reserved.
%%Copyright:
%%Copyright: Redistribution and use in source and binary forms, with or
%%Copyright: without modification, are permitted provided that the
%%Copyright: following conditions are met:
%%Copyright:
%%Copyright: Redistributions of source code must retain the above
%%Copyright: copyright notice, this list of conditions and the following
%%Copyright: disclaimer.
%%Copyright:
%%Copyright: Redistributions in binary form must reproduce the above
%%Copyright: copyright notice, this list of conditions and the following
%%Copyright: disclaimer in the documentation and/or other materials
%%Copyright: provided with the distribution.
%%Copyright:
%%Copyright: Neither the name of Adobe Systems Incorporated nor the names
%%Copyright: of its contributors may be used to endorse or promote
%%Copyright: products derived from this software without specific prior
%%Copyright: written permission.
%%Copyright:
%%Copyright: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
%%Copyright: CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
%%Copyright: INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
%%Copyright: MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
%%Copyright: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
%%Copyright: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
%%Copyright: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
%%Copyright: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
%%Copyright: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
%%Copyright: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
%%Copyright: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
%%Copyright: OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
%%Copyright: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%%Copyright: -----------------------------------------------------------
Binary file added public/cmaps/NWP-H.bcmap
Binary file not shown.
Binary file added public/cmaps/NWP-V.bcmap
Binary file not shown.
Binary file added public/cmaps/RKSJ-H.bcmap
Binary file not shown.
Binary file added public/cmaps/RKSJ-V.bcmap
Binary file not shown.
Binary file added public/cmaps/Roman.bcmap
Binary file not shown.
Binary file added public/cmaps/UniCNS-UCS2-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniCNS-UCS2-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniCNS-UTF16-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniCNS-UTF16-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniCNS-UTF32-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniCNS-UTF32-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniCNS-UTF8-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniCNS-UTF8-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniGB-UCS2-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniGB-UCS2-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniGB-UTF16-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniGB-UTF16-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniGB-UTF32-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniGB-UTF32-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniGB-UTF8-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniGB-UTF8-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS-UCS2-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS-UCS2-HW-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS-UCS2-HW-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS-UCS2-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS-UTF16-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS-UTF16-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS-UTF32-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS-UTF32-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS-UTF8-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS-UTF8-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS2004-UTF16-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS2004-UTF16-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS2004-UTF32-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS2004-UTF32-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS2004-UTF8-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJIS2004-UTF8-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJISPro-UCS2-HW-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJISPro-UCS2-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJISPro-UTF8-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJISX0213-UTF32-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJISX0213-UTF32-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJISX02132004-UTF32-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniJISX02132004-UTF32-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniKS-UCS2-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniKS-UCS2-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniKS-UTF16-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniKS-UTF16-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniKS-UTF32-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniKS-UTF32-V.bcmap
Binary file not shown.
Binary file added public/cmaps/UniKS-UTF8-H.bcmap
Binary file not shown.
Binary file added public/cmaps/UniKS-UTF8-V.bcmap
Binary file not shown.
Binary file added public/cmaps/V.bcmap
Binary file not shown.
Binary file added public/cmaps/WP-Symbol.bcmap
Binary file not shown.
73 changes: 73 additions & 0 deletions src/app/_components/PDFViewer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use client';

import { useState } from 'react';
import { pdfjs, Document, Page } from 'react-pdf';
import { Button } from '@mui/material';
import 'react-pdf/dist/Page/AnnotationLayer.css';
import 'react-pdf/dist/Page/TextLayer.css';

// PDF.jsのワーカーの設定
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js`;

interface PDFViewerProps {
file: string;
}

const options = {
cMapUrl: '/cmaps/',
cMapPacked: true,
};

const PDFViewer: React.FC<PDFViewerProps> = ({ file }) => {
const [numPages, setNumPages] = useState<number | null>(null);
const [pageNumber, setPageNumber] = useState(1); // 現在のページ番号

const onDocumentLoadSuccess = ({ numPages }: { numPages: number }) => {
setNumPages(numPages);
};

const nextPage = () => {
if (numPages === null) return; // numPagesがnullなら何もしない
setPageNumber((prevPageNumber) =>
prevPageNumber < numPages ? prevPageNumber + 1 : prevPageNumber,
);
};

const previousPage = () => {
if (numPages === null) return; // numPagesがnullなら何もしない
setPageNumber((prevPageNumber) =>
prevPageNumber > 1 ? prevPageNumber - 1 : prevPageNumber,
);
};

return (
<>
<Button
onClick={previousPage}
disabled={pageNumber <= 1}
variant='outlined'
sx={{ mr: 4 }}
>
前のページ
</Button>
ページ {pageNumber} / {numPages}
<Button
onClick={nextPage}
disabled={pageNumber >= (numPages ?? 0)}
variant='outlined'
sx={{ ml: 4 }}
>
次のページ
</Button>
<Document
file={file}
onLoadSuccess={onDocumentLoadSuccess}
options={options}
>
<Page pageNumber={pageNumber} />
</Document>
</>
);
};

export default PDFViewer;
123 changes: 88 additions & 35 deletions src/app/_components/RecordFileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ import FileUploadButton from '@/app/_components/FileUpload';
import { useState } from 'react';
import useUser from '@/app/_hooks/useUser';
import { useRouter } from 'next/navigation';
import { createRecord } from '@/app/files/record/_hooks/createRecord';
import {
createRecord,
PostRecordResponse,
} from '@/app/files/record/_hooks/createRecord';
import PDFViewer from '@/app/_components/PDFViewer';
import Carousel from '@/app/_components/Carousel';

const RecordFileInput = () => {
const [activeStep, setActiveStep] = useState(0);

const [isLoading, setIsLoading] = useState(false);

const [blob, setBlob] = useState<File>();
Expand All @@ -22,14 +29,32 @@ const RecordFileInput = () => {

const router = useRouter();

const onCheckDiffPDF = async () => {
if (!token || !blob) {
return;
}
setIsLoading(true);
setTimeout(() => {
setIsLoading(false);
setActiveStep(activeStep + 1);
}, 2000);
};

const onRecordClick = async () => {
if (!token || !blob) {
return;
}
console.log(blob);
setIsLoading(true);
const response = await createRecord(token, blob);
console.log(response);
let response: PostRecordResponse;
try {
response = await createRecord(token, blob);
console.log(response);
} catch (e) {
setIsLoading(false);
console.error(e);
return;
}
setIsLoading(false);
router.push('/');
};
Expand All @@ -45,39 +70,67 @@ const RecordFileInput = () => {
<Typography variant='h2' sx={{ mb: 4 }}>
記録の作成
</Typography>
<Box sx={{ width: '100%', p: 1, boxSizing: 'border-box' }}>
<Typography variant='h3' gutterBottom>
ファイルの選択
</Typography>
<Stack
sx={{
background: mainTheme.palette.primary.light,
height: 400,
justifyContent: 'center',
}}
>
<FileUploadButton
label='ここからファイルを選択してください'
file={blob}
setFile={(blob) => setBlob(blob)}
/>
</Stack>
<Box m={1}>
<Typography>・1度に記録できるファイルは1つのみです</Typography>
</Box>
</Box>
<Stack direction='row' justifyContent='space-between'>
<Button
variant='contained'
color='secondary'
sx={{ mt: 4 }}
onClick={onRecordClick}
disabled={!blob}
>
{/*TODO ここを差分を表示する。にする*/}
記録する
</Button>
<Stack direction='row' justifyContent='space-between' mb={4}>
<div>
{activeStep !== 0 && (
<Button
variant='contained'
sx={{ mt: 4 }}
onClick={() => setActiveStep(activeStep - 1)}
>
前へ
</Button>
)}
</div>
<div>
{activeStep !== 1 && (
<Button
variant='contained'
sx={{ mt: 4 }}
onClick={onCheckDiffPDF}
disabled={!blob}
>
差分を確認する
</Button>
)}
{activeStep === 1 && (
<Button
variant='contained'
color='secondary'
sx={{ mt: 4 }}
onClick={onRecordClick}
>
記録する
</Button>
)}
</div>
</Stack>
<Carousel pageIndex={activeStep}>
<Box sx={{ width: '100%', p: 1, boxSizing: 'border-box' }}>
<Typography variant='h3' gutterBottom>
ファイルの選択
</Typography>
<Stack
sx={{
background: mainTheme.palette.primary.light,
height: 400,
justifyContent: 'center',
}}
>
<FileUploadButton
label='ここからファイルを選択してください'
file={blob}
setFile={(blob) => setBlob(blob)}
/>
</Stack>
<Box m={1}>
<Typography>・1度に記録できるファイルは1つのみです</Typography>
</Box>
</Box>
<Box sx={{ width: '100%', p: 1, boxSizing: 'border-box' }}>
<PDFViewer file='https://storage.googleapis.com/recordex/diff.pdf' />
</Box>
</Carousel>
</Box>
</Paper>
);
Expand Down
29 changes: 19 additions & 10 deletions src/app/files/record/_hooks/createRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,24 @@ export const createRecord = async (
),
);
}
// ブロックチェーンにファイルのハッシュ値を記録
const addFile = await recordContract.addFile(
file.name,
fileHash,
recordedNewestFileHash,
);
console.log(
`トランザクションの送信に成功しました。network -> ${signer.provider._network.name}, transactionHash -> ${addFile.hash})`,
);
let addFile: ethers.ContractTransactionResponse;
try {
// ブロックチェーンにファイルのハッシュ値を記録
addFile = await recordContract.addFile(
file.name,
fileHash,
recordedNewestFileHash,
);
console.log(
`recordContract へのトランザクションの送信に成功しました。network -> ${signer.provider._network.name}, transactionHash -> ${addFile.hash})`,
);
} catch (e) {
return Promise.reject(
new Error(
`recordContract.addFile 関数を実行中にエラーが発生しました。: ${e}`,
),
);
}
const formData = new FormData();
// ファイルとトランザクションハッシュを FormData に追加
formData.append('file', file);
Expand All @@ -71,7 +80,7 @@ export const createRecord = async (

type PostRecordRequest = FormData;

type PostRecordResponse = {
export type PostRecordResponse = {
file_name: string;
transaction_hash: string;
};

0 comments on commit 005e7b3

Please sign in to comment.