Skip to content

Commit

Permalink
added time stamping to proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
Dexagod committed Oct 6, 2020
1 parent c06f260 commit 1a67642
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
17 changes: 15 additions & 2 deletions src/Components/InProgressViewerComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Value } from '@solid/react';

import ns from "../util/NameSpaces"
import useContracts from '../hooks/useContracts'
import { availableViews } from '../util/Util'
import { availableViews, formatDate } from '../util/Util'

const InProgressViewerComponent = (props) => {

Expand All @@ -22,21 +22,34 @@ const InProgressViewerComponent = (props) => {
const split = status.split('/')
return split[split.length - 1]
}

const getContractDate = (date) => {
if (!date) {
return "no date set"
} else {
return new Date(date).toLocaleString()
}
}
console.log('contracts', contracts)

const sortedContracts = contracts.sort( (a, b) => { if(!b) { return a } else if (!a) { return b } else { return new Date(a.created) - new Date(b.created) }})
return (
<div id="InProgressViewerComponent" className='container'>
<h4>Running Procedures</h4>
<br />
<Row className='propertyview pageheader' key={'header'}>
<Col md={3}><label className="leftaligntext"><b>Contract type</b></label></Col>
<Col md={2}><label className="leftaligntext">Current status</label></Col>
<Col md={2}><label className="leftaligntext">Created at</label></Col>
<Col md={3}><label className="leftaligntext">Creator</label></Col>
<Col md={2}><label className="centeraligntext">Action</label></Col>
</Row>
{contracts.map(contract => {
{sortedContracts.map(contract => {
return (
<Row className='propertyview ' key={contract.id}>
<Col md={3}><label className="leftaligntext"><b>marriage proposal</b></label></Col>
<Col md={2}><label className="leftaligntext">{getContractStatus(contract.status)}</label></Col>
<Col md={2}><label className="leftaligntext">{getContractDate(contract.created)}</label></Col>
<Col md={3}><label className="leftaligntext"><a href={contract.creator}><Value src={`[${contract.creator}].name`}/></a></label></Col>
<Col md={2}><Button onClick={() => viewMarriage(contract)} className='centeraligntext'>see progress</Button></Col>
</Row>
Expand Down
2 changes: 1 addition & 1 deletion src/Components/MarriageViewComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const MarriageViewComponent = (props) => {
async function submitMarriageProposal() {
// For demo purposes outside of the workshop also, we will have the user function as the official also
if (! await validateOfficial()) return;
const submission = await submitProposal(props.webId, props.contractId, official)
const submission = submitProposal(props.webId, props.contractId, official)
props.setview(availableViews.running)
}

Expand Down
9 changes: 7 additions & 2 deletions src/Components/NotificationsViewerComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Value } from '@solid/react';
import ns from "../util/NameSpaces"

import { availableViews, getContractData } from '../util/Util'
import { deleteFile } from '../util/FileUtil';

const NotificationsViewerComponent = (props) => {

Expand All @@ -19,7 +20,7 @@ const NotificationsViewerComponent = (props) => {
<h4> Notifications </h4>
<br />
<Row className='propertyview pageheader' key={'header'}>
<Col md={2}><label className="leftaligntext"><b>Type</b></label></Col>
<Col md={1}><label className="leftaligntext"><b>Type</b></label></Col>
<Col md={2}><label className="leftaligntext">Sender</label></Col>
<Col md={2}><label className="leftaligntext">Time received</label></Col>
<Col md={4}><label className="leftaligntext">Summary</label></Col>
Expand Down Expand Up @@ -66,7 +67,7 @@ const NotificationCard = (props) => {
return (
<div className={`NotificationCard`}>
<Row className='propertyview' key={notification.metadata.id}>
<Col md={2}><label className='leftaligntext'><b>{notification.type && notification.type.split('#')[1]}</b></label></Col>
<Col md={1}><label className='leftaligntext'><b>{notification.type && notification.type.split('#')[1]}</b></label></Col>
<Col md={2}><label className='leftaligntext'><a href={notification.actor}><Value src={`[${notification.actor}].name`}/></a></label></Col>
<Col md={2}><label className='leftaligntext'><b>{notification.metadata.modified && notification.metadata.modified.toLocaleString()}</b></label></Col>
<Col md={4}><label className='leftaligntext'>{notification.summary}</label></Col>
Expand Down Expand Up @@ -98,4 +99,8 @@ const NotificationCard = (props) => {
async function viewRejections() {
props.setview(availableViews.running)
}

async function deleteNotification(notificationId) {
const result = await deleteFile(notificationId)
}
}
9 changes: 9 additions & 0 deletions src/hooks/useNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const TIMEOUT = 10 * 1000
// const { default: data } = require('@solid/query-ldflex');

const useNotifications = function(webId) {
console.log('useNotifications')
const [notifications, setNotifications] = useState([]);
useEffect(() => {
let mounted = true;
Expand All @@ -29,10 +30,15 @@ const useNotifications = function(webId) {
// TODO:: dont fetch notifications that have already been fetched

async function updateNotifications(webId, currentNotifications){
console.log('timing')
if(webId){
console.time("fetchnew")
const newNotificationsMetadata = await checkNewNotifications(webId, currentNotifications.map(n => n.metadata.id))
console.timeEnd("fetchnew")
if(newNotificationsMetadata && newNotificationsMetadata.length) {
console.time("fetchNotifs")
const newNotifications = (await fetchNotifications(newNotificationsMetadata)) || []
console.timeEnd("fetchNotifs")
fireUpdateEvents(newNotifications)
return newNotifications
}
Expand Down Expand Up @@ -72,6 +78,7 @@ const useNotifications = function(webId) {
* This should be placed somewhere else in the future
*/
async function fireUpdateEvents(updatedNotifications){
console.time("update")
const currentContracts = await getProfileContracts(webId)
for (const notification of updatedNotifications) {
const itemId = notification.type === ns.as('Announce') ? notification.object && notification.object.object : notification.target
Expand All @@ -93,6 +100,8 @@ const useNotifications = function(webId) {
}
}
}

console.timeEnd("update")
}

async function checkContractSubmittedStatus(proposalId) {
Expand Down
3 changes: 2 additions & 1 deletion src/util/MarriageController.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ const getCertificateName = () => {
async function createMarriagePropsalBody(proposalData, creatorId){
const quadList = [ quad(namedNode(''), namedNode(ns.rdf('type')), namedNode(ns.demo('MarriageProposal'))),
quad(namedNode(''), namedNode(ns.dct('creator')), namedNode(creatorId)),
quad(namedNode(''), namedNode(ns.demo('status')), namedNode(ns.demo('proposal'))),]
quad(namedNode(''), namedNode(ns.dct('created')), literal(new Date().toISOString(), namedNode(ns.xsd('dateTime')))),
quad(namedNode(''), namedNode(ns.demo('status')), namedNode(ns.demo('proposal'))) ]
for (let spouse of proposalData.filter(e => e.type === 'spouse'))
quadList.push(quad(namedNode(''), namedNode(ns.dbo('spouse')), namedNode(spouse.webId)))
for (let witness of proposalData.filter(e => e.type === 'witness'))
Expand Down
1 change: 1 addition & 0 deletions src/util/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export async function getContractData(id) {
id: id,
type: getQuadObjVal(await datastore.getQuads(id, ns.rdf('type'))),
creator: getQuadObjVal(await datastore.getQuads(id, ns.dct('creator'))),
created: getQuadObjVal(await datastore.getQuads(id, ns.dct('created'))),
certified_by: getQuadObjVal(await datastore.getQuads(id, ns.demo('certified_by'))),
status: getQuadObjVal(await datastore.getQuads(id, ns.demo('status'))),
spouse: getQuadObjList(await datastore.getQuads(id, ns.dbo('spouse'))).map(e => {return({id: e})}),
Expand Down

0 comments on commit 1a67642

Please sign in to comment.