Skip to content

Commit

Permalink
Merge pull request #77 from pshenmic/feat/frontend-i2
Browse files Browse the repository at this point in the history
Redesign + Identities
  • Loading branch information
pshenmic authored Oct 31, 2023
2 parents ede2714 + aee62d8 commit dcc1580
Show file tree
Hide file tree
Showing 60 changed files with 1,787 additions and 966 deletions.
2 changes: 1 addition & 1 deletion packages/frontend/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
REACT_APP_API_BASE_URL=http://127.0.0.1:3005
REACT_APP_API_BASE_URL=http://127.0.0.1:3005
6 changes: 5 additions & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@chakra-ui/icons": "^2.1.1",
"@chakra-ui/react": "^2.8.1",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"dash": "^3.24.15",
"express": "^4.18.2",
"framer-motion": "^10.16.4",
"node-fetch": "^3.3.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-paginate": "^8.2.0",
"react-router-dom": "^6.12.1",
"react-scripts": "5.0.1",
"react-tabs": "^6.0.2",
"sass": "^1.69.2",
"web-vitals": "^2.1.4"
},
Expand Down
80 changes: 11 additions & 69 deletions packages/frontend/src/components/RootComponent.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,21 @@
import {Outlet, Link} from "react-router-dom";
import "./root.css";
import React, {useState} from 'react';
import * as Api from '../util/Api'
import {useNavigate} from "react-router-dom";
import ModalWindow from "./ModalWindow";
import Navbar from "../components/navbar/Navbar";
import theme from "../styles/theme";
import "../styles/theme.scss";
import { ChakraProvider} from '@chakra-ui/react'

export default function RootComponent() {
let navigate = useNavigate();

const [showModal, setShowModal] = useState(false)
const [modalText, setModalText] = useState("false")

const showModalWindow = (text, timeout) => {
setShowModal(true)
setModalText(text)

if (timeout) {
setTimeout(() => {
setShowModal(false)
setModalText("")
}, timeout)
}
}

const handleKeyPress = async (event) => {
if (event.key === 'Enter') {
try {
const searchResult = await Api.search(searchQuery)

if (searchResult?.block) {
// redirect to blocks
console.log(searchResult?.block.header.hash)
setSearchQuery("")
return navigate(`/block/${searchResult?.block.header.hash}`)
}

if (searchResult?.transaction) {
setSearchQuery("")
return navigate(`/transaction/${searchResult?.transaction.hash}`)
}

if (searchResult?.dataContract) {
setSearchQuery("")
return navigate(`/dataContract/${searchResult?.dataContract.identifier}`)
}

if (searchResult?.document) {
setSearchQuery("")
return navigate(`/document/${searchResult?.document.identifier}`)
}

showModalWindow('Not found', 6000)
} catch (e) {
showModalWindow('Not found', 6000)
}
}
}

const handleSearchInput = (event) => {
setSearchQuery(event.target.value)
}

const [searchQuery, setSearchQuery] = useState("");
export default function RootComponent() {

return (
<div>
<div className="topnav">
<Link to="/">Home</Link>
<Link to="/blocks">Blocks</Link>
<Link to="/dataContracts">Data Contracts</Link>
<input value={searchQuery} type="text" placeholder="Search..." onChange={handleSearchInput}
onKeyPress={handleKeyPress}/>
<ModalWindow open={showModal} text={modalText} setShowModal={setShowModal}/>
</div>
<ChakraProvider theme={theme}>

<Navbar/>

<Outlet/>
</div>

</ChakraProvider>
);
}
29 changes: 29 additions & 0 deletions packages/frontend/src/components/blocks/BlocksList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {Link} from "react-router-dom";
import BlocksListItem from './BlocksListItem'
import './BlocksList.scss'


function BlocksList ({blocks = [], columnsCount = 1, size = 'l'}) {
return(
<div
className={'BlocksList'}
style={{
columnCount: blocks.length > 1 ? columnsCount : 1,
}}
>
{blocks.map((block) =>
<BlocksListItem
key={block.hash}
block={block}
size={size}
/>
)}

{blocks.length === 0 &&
<div className={'documents_list__empty_message'}>There are no documents created yet.</div>
}
</div>
)
}

export default BlocksList;
3 changes: 3 additions & 0 deletions packages/frontend/src/components/blocks/BlocksList.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.BlocksList {

}
40 changes: 40 additions & 0 deletions packages/frontend/src/components/blocks/BlocksListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {Link} from 'react-router-dom'
import './BlocksListItem.scss'


function BlocksListItem ({ block }) {
const {header, txs} = block
const {hash, height, timestamp} = header

return(
<Link
to={`/block/${hash}`}
className={'BlocksListItem'}
>
{(typeof height === 'number' &&
<span className={'BlocksListItem__Height'}>{height}</span>
)}

{typeof timestamp === 'string' &&
<span className={'BlocksListItem__Timestamp'}>
{new Date(timestamp).toLocaleString()}
</span>
}

{typeof hash === 'string' &&
<span className={'BlocksListItem__Hash'}>
{hash}
</span>
}

{(typeof txs.length === 'number') &&
<span className={'BlocksListItem__Txs'}>
({txs.length} txs)
</span>
}

</Link>
)
}

export default BlocksListItem;
66 changes: 66 additions & 0 deletions packages/frontend/src/components/blocks/BlocksListItem.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
@use '../../styles/mixins.scss';

.BlocksListItem {
@include mixins.def_list_item;

&:last-child {
border-bottom: none;
}

&__Hash {
color: var(--chakra-colors-gray-200);
flex-grow: 1;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}

&__Height {
font-weight: bold;
margin-right: 8px;
word-break: keep-all;
}

&__Timestamp {
margin-right: 16px;
text-wrap: nowrap;
}

&__Txs {
margin-left: 12px;
text-wrap: nowrap;
}


@media screen and (max-width: 620px) {
flex-wrap: wrap;

&__Height {
order: 1;
margin-right: 4px;
}

&__Txs {
order: 2;
margin-left: 0;
margin-right: 6px;
}

&__Timestamp {
order: 3;
}

&__Hash {
order: 4;
flex-grow: unset;
margin-top: 2px;
}
}

@media screen and (max-width: 400px) {
&__Timestamp {
text-wrap: wrap;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import DataContractsListItem from './DataContractsListItem'
import './DataContractsList.scss'


function DataContractsList ({dataContracts = [], size = 'l'}) {
return (

<div className={'DataContractsList ' + 'DataContractsList--Size' + size.toUpperCase()}>

{dataContracts.map((dataContract, key) =>
<DataContractsListItem
key={key}
size={size}
dataContract={dataContract}
/>
)}

{dataContracts.length === 0 &&
<div className={'DataContractsList__EmptyMessage'}>There are no data contracts created yet.</div>
}

</div>

);
}

export default DataContractsList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DataContractsList {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Link} from 'react-router-dom';
import './DataContractsListItem.scss'


function DataContractsListItem ({ dataContract }) {
const {identifier, timestamp} = dataContract

return (
<Link
to={`/dataContract/${identifier}`}
className={'DataContractsListItem'}
>
<div className={'DataContractsListItem__Identifier'}>
{identifier}
</div>

{(typeof timestamp === 'string') &&
<div className={'DataContractsListItem__Timestamp'}>
{new Date(timestamp).toLocaleString()}
</div>
}
</Link>
);
}

export default DataContractsListItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@use '../../styles/mixins.scss';
@import '../../styles/variables.scss';

.DataContractsListItem {
@include mixins.def_list_item;

width: 100%;
justify-content: space-between;

&__Identifier {
text-overflow: ellipsis;
overflow: hidden;
line-height: 24px;
white-space: nowrap;
margin-right: 16px;
}

&__Timestamp {
text-wrap: nowrap;
}

.DataContractsList--SizeS &,
.DataContractsList--SizeM & {
&__Identifier {
margin-right: 16px;
}
}

@media screen and (max-width: $breakpoint-sm) {
flex-wrap: wrap;

&__Identifier {
width: 100%;
}

&__Timestamp {
text-wrap: wrap;
}
}
}
25 changes: 25 additions & 0 deletions packages/frontend/src/components/documents/DocumentsList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import DocumentsListItem from "./DocumentsListItem";
import './DocumentsList.scss'


export default function DocumentsList({documents = [], size='l'}) {
return (

<div className={'DocumentsList ' + 'DocumentsList--Size' + size.toUpperCase()}>

{documents.map((document, key) =>
<DocumentsListItem
key={key}
size={size}
document={document}
/>
)}

{documents.length === 0 &&
<div className={'DocumentsList__EmptyMessage'}>There are no documents created yet.</div>
}

</div>

);
}
Loading

0 comments on commit dcc1580

Please sign in to comment.