Rust implementation of NextGraph, a Decentralized and local-first web 3.0 ecosystem
https://nextgraph.org
byzantine-fault-tolerancecrdtsdappsdecentralizede2eeeventual-consistencyjson-ldlocal-firstmarkdownocapoffline-firstp2pp2p-networkprivacy-protectionrdfrich-text-editorself-hostedsemantic-websparqlweb3collaboration
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.8 KiB
60 lines
1.8 KiB
import { FormEvent, FunctionComponent, useCallback, useState } from "react";
|
|
import { BrowserNGLdoProvider, useLdo, dataset } from './reactMethods';
|
|
import { NGSocialContactShapeType } from "./.ldo/contact.shapeTypes.ts";
|
|
import { LdSet } from "@ldo/ldo";
|
|
|
|
export const MakeContact: FunctionComponent = () => {
|
|
const [name, setName] = useState("");
|
|
const [email, setEmail] = useState("");
|
|
|
|
const { createData, commitData } = useLdo();
|
|
|
|
const onSubmit = useCallback(
|
|
async (e: FormEvent<HTMLFormElement>) => {
|
|
e.preventDefault();
|
|
const new_name = name.trim();
|
|
const new_email = email.trim();
|
|
if (new_name.trim().length > 2 && new_email.trim().length > 6 && new_email.indexOf("@") >= 0) {
|
|
setName("");
|
|
setEmail("");
|
|
const resource = await dataset.createResource("nextgraph");
|
|
if (!resource.isError) {
|
|
//console.log("Created resource:", resource.uri);
|
|
|
|
const contact = createData(
|
|
NGSocialContactShapeType,
|
|
resource.uri.substring(0,53),
|
|
resource
|
|
);
|
|
|
|
contact.type = { "@id": "Individual" };
|
|
contact.fn = new_name;
|
|
contact.hasEmail = new_email;
|
|
const result = await commitData(contact);
|
|
if (result.isError) {
|
|
console.error(result.message);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
[name, email]
|
|
);
|
|
|
|
return (
|
|
<form onSubmit={onSubmit}>
|
|
<input
|
|
type="text"
|
|
placeholder="Enter name"
|
|
value={name}
|
|
onChange={(e) => setName(e.target.value)}
|
|
/>
|
|
<input
|
|
type="text"
|
|
placeholder="Enter email address"
|
|
value={email}
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
/>
|
|
<input type="submit" id="save" value="Save" />
|
|
</form>
|
|
);
|
|
}; |