parent
5acfea4c43
commit
c0c8eb6afb
@ -1,35 +1,50 @@ |
||||
import { useSolidAuth } from "@ldo/solid-react"; |
||||
import React from "react"; |
||||
import React, { Fragment } from "react"; |
||||
import type { FunctionComponent } from "react"; |
||||
import { createBrowserRouter, RouterProvider } from "react-router-dom"; |
||||
import { createBrowserRouter, Outlet, RouterProvider } from "react-router-dom"; |
||||
import { Blog } from "./blog/Blog"; |
||||
import { PostPage } from "./post/PostPage"; |
||||
import { Header } from "./Header"; |
||||
import { MainContainerProvider } from "./MainContainerProvider"; |
||||
|
||||
const router = createBrowserRouter([ |
||||
{ |
||||
path: "/", |
||||
element: <Blog />, |
||||
}, |
||||
{ |
||||
path: "/media/:uri", |
||||
element: <PostPage />, |
||||
}, |
||||
]); |
||||
import { Profile } from "./profile/Profile"; |
||||
|
||||
export const Layout: FunctionComponent = () => { |
||||
const { session, ranInitialAuthCheck } = useSolidAuth(); |
||||
if (!ranInitialAuthCheck) { |
||||
return <p>Loading</p>; |
||||
} |
||||
const { session } = useSolidAuth(); |
||||
return ( |
||||
<div> |
||||
<Header /> |
||||
<hr /> |
||||
<MainContainerProvider> |
||||
{session.isLoggedIn ? <RouterProvider router={router} /> : undefined} |
||||
{session.isLoggedIn ? <Outlet /> : <Fragment />} |
||||
</MainContainerProvider> |
||||
</div> |
||||
); |
||||
}; |
||||
|
||||
const router = createBrowserRouter([ |
||||
{ |
||||
element: <Layout />, |
||||
children: [ |
||||
{ |
||||
path: "/", |
||||
element: <Blog />, |
||||
}, |
||||
{ |
||||
path: "/media/:uri", |
||||
element: <PostPage />, |
||||
}, |
||||
{ |
||||
path: "/profile", |
||||
element: <Profile />, |
||||
}, |
||||
], |
||||
}, |
||||
]); |
||||
|
||||
export const Router: FunctionComponent = () => { |
||||
const { ranInitialAuthCheck } = useSolidAuth(); |
||||
if (!ranInitialAuthCheck) { |
||||
return <p>Loading</p>; |
||||
} |
||||
return <RouterProvider router={router} />; |
||||
}; |
||||
|
@ -0,0 +1,34 @@ |
||||
import { |
||||
useLdo, |
||||
useResource, |
||||
useSolidAuth, |
||||
useSubject, |
||||
} from "@ldo/solid-react"; |
||||
import type { ChangeEvent } from "react"; |
||||
import React, { useCallback, type FunctionComponent } from "react"; |
||||
import { SolidProfileShapeShapeType } from "../.ldo/solidProfile.shapeTypes"; |
||||
|
||||
export const Profile: FunctionComponent = () => { |
||||
const { session } = useSolidAuth(); |
||||
const profile = useSubject(SolidProfileShapeShapeType, session.webId); |
||||
const webIdResource = useResource(session.webId); |
||||
const { changeData, commitData } = useLdo(); |
||||
|
||||
const onNameChange = useCallback( |
||||
async (e: ChangeEvent<HTMLInputElement>) => { |
||||
if (profile && webIdResource) { |
||||
const cProfile = changeData(profile, webIdResource); |
||||
cProfile.fn = e.target.value; |
||||
await commitData(cProfile); |
||||
} |
||||
}, |
||||
[profile, webIdResource], |
||||
); |
||||
|
||||
return ( |
||||
<> |
||||
<label>Name</label> |
||||
<input type="text" value={profile?.fn || ""} onChange={onNameChange} /> |
||||
</> |
||||
); |
||||
}; |
Loading…
Reference in new issue