49 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-07-21 01:13:02 +00:00
import React from "react"
2023-07-21 13:33:47 +00:00
import { Flex } from "@chakra-ui/react"
2023-07-21 01:13:02 +00:00
import { useMatches } from "@remix-run/react"
2023-07-21 13:33:47 +00:00
import { Thingtime } from "./Thingtime"
import { useThingtime } from "./useThingtime"
2023-07-21 01:13:02 +00:00
2023-07-21 13:33:47 +00:00
export const ThingtimeURL = (props) => {
2023-07-21 01:13:02 +00:00
const { getThingtime } = useThingtime()
const matches = useMatches()
const location = React.useMemo(() => {
return matches[matches.length - 1]
}, [matches])
const path = React.useMemo(() => {
2023-07-21 13:33:47 +00:00
const pathPartOne = location?.params?.["*"]
const path = pathPartOne?.replace(/\//g, ".")
2023-07-21 01:13:02 +00:00
return path
2023-07-21 13:33:47 +00:00
}, [location])
2023-07-21 01:13:02 +00:00
const thing = React.useMemo(() => {
// remove /things/ from path
const ret = getThingtime(path)
return ret
}, [path, getThingtime])
return (
<Flex
alignItems="center"
justifyContent="center"
flexDirection="column"
maxWidth="100%"
>
<Thingtime
2023-07-21 13:33:47 +00:00
edit={props?.edit}
2023-07-21 01:13:02 +00:00
path={path}
thing={thing}
chakras={{ marginY: 200 }}
width="600px"
></Thingtime>
</Flex>
)
}