parent
c98b451c7a
commit
b616e720b2
@ -1,35 +0,0 @@ |
|||||||
import type { FunctionComponent } from "react"; |
|
||||||
import React, { useState } from "react"; |
|
||||||
|
|
||||||
interface BlurTextInputProps { |
|
||||||
value: string; |
|
||||||
onBlurText: (text: string) => void; |
|
||||||
} |
|
||||||
|
|
||||||
const BlurTextInput: FunctionComponent<BlurTextInputProps> = ({ |
|
||||||
value, |
|
||||||
onBlurText, |
|
||||||
}) => { |
|
||||||
const [isFocused, setIsFocused] = useState(false); |
|
||||||
const [text, setText] = useState(value); |
|
||||||
|
|
||||||
return ( |
|
||||||
<input |
|
||||||
type="text" |
|
||||||
value={isFocused ? text : value} |
|
||||||
onChange={(e) => setText(e.target.value)} |
|
||||||
onFocus={() => { |
|
||||||
setIsFocused(true); |
|
||||||
setText(value); |
|
||||||
}} |
|
||||||
onBlur={(e) => { |
|
||||||
setIsFocused(false); |
|
||||||
if (e.target.value !== value) { |
|
||||||
onBlurText(e.target.value); |
|
||||||
} |
|
||||||
}} |
|
||||||
/> |
|
||||||
); |
|
||||||
}; |
|
||||||
|
|
||||||
export default BlurTextInput; |
|
@ -1,37 +0,0 @@ |
|||||||
import type { FunctionComponent, PropsWithChildren } from "react"; |
|
||||||
import React, { useCallback } from "react"; |
|
||||||
import { useSolidAuth } from "@ldobjects/solid-react"; |
|
||||||
|
|
||||||
const Layout: FunctionComponent<PropsWithChildren> = ({ children }) => { |
|
||||||
const { login, session, logout } = useSolidAuth(); |
|
||||||
|
|
||||||
const loginCb = useCallback(async () => { |
|
||||||
const issuer = prompt( |
|
||||||
"Enter your Pod Provider", |
|
||||||
"https://solidcommunity.net", |
|
||||||
); |
|
||||||
if (issuer) { |
|
||||||
await login(issuer); |
|
||||||
} |
|
||||||
}, []); |
|
||||||
|
|
||||||
return ( |
|
||||||
<div> |
|
||||||
<h1>LDO Solid React Test</h1> |
|
||||||
{session.isLoggedIn ? ( |
|
||||||
<div> |
|
||||||
<p> |
|
||||||
Logged in as {session.webId}{" "} |
|
||||||
<button onClick={logout}>Log Out</button> |
|
||||||
</p> |
|
||||||
<hr /> |
|
||||||
{children} |
|
||||||
</div> |
|
||||||
) : ( |
|
||||||
<button onClick={loginCb}>Log In</button> |
|
||||||
)} |
|
||||||
</div> |
|
||||||
); |
|
||||||
}; |
|
||||||
|
|
||||||
export default Layout; |
|
@ -1,40 +0,0 @@ |
|||||||
import type { FunctionComponent } from "react"; |
|
||||||
import React from "react"; |
|
||||||
import { SolidProfileShapeShapeType } from "./ldo/solidProfile.shapeTypes"; |
|
||||||
import BlurTextInput from "./BlurTextInput"; |
|
||||||
import { |
|
||||||
useSolidAuth, |
|
||||||
useLdo, |
|
||||||
useDataResource, |
|
||||||
useSubject, |
|
||||||
} from "@ldobjects/solid-react"; |
|
||||||
|
|
||||||
const Profile: FunctionComponent = () => { |
|
||||||
const { changeData, commitData } = useLdo(); |
|
||||||
const { session } = useSolidAuth(); |
|
||||||
const webId = session.webId!; |
|
||||||
const webIdResource = useDataResource(webId); |
|
||||||
const [profile, profileError] = useSubject(SolidProfileShapeShapeType, webId); |
|
||||||
|
|
||||||
if (webIdResource.isLoading) { |
|
||||||
return <p>Loading</p>; |
|
||||||
} else if (profileError) { |
|
||||||
return <p>profileError.message</p>; |
|
||||||
} else { |
|
||||||
return ( |
|
||||||
<div> |
|
||||||
<label>Name:</label> |
|
||||||
<BlurTextInput |
|
||||||
value={profile.name || ""} |
|
||||||
onBlurText={async (text) => { |
|
||||||
const cProfile = changeData(profile, webIdResource); |
|
||||||
cProfile.name = text; |
|
||||||
await commitData(cProfile); |
|
||||||
}} |
|
||||||
/> |
|
||||||
</div> |
|
||||||
); |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
export default Profile; |
|
Loading…
Reference in new issue