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-08-15 23:10:13 +00:00
|
|
|
import { useLocation, useMatches } from "@remix-run/react"
|
2023-07-21 01:13:02 +00:00
|
|
|
|
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()
|
|
|
|
|
2023-08-15 23:10:13 +00:00
|
|
|
const { pathname } = useLocation()
|
|
|
|
|
2023-07-21 01:13:02 +00:00
|
|
|
const matches = useMatches()
|
|
|
|
const location = React.useMemo(() => {
|
|
|
|
return matches[matches.length - 1]
|
|
|
|
}, [matches])
|
|
|
|
|
|
|
|
const path = React.useMemo(() => {
|
2023-08-15 23:10:36 +00:00
|
|
|
console.log("ThingtimeURL location", location)
|
2023-08-15 23:10:13 +00:00
|
|
|
|
|
|
|
// const sanitisation = ["/things", "/edit", "/editor", "/code", "/coder"]
|
|
|
|
|
|
|
|
// // strip the leading /path1/path2 path1 section from the path
|
|
|
|
// let pathPartOne = location?.pathname?.split("/")[2]
|
|
|
|
|
|
|
|
// // remove all sanitsation strings from path
|
|
|
|
// sanitisation.forEach((sanitisationString) => {
|
|
|
|
// pathPartOne = pathPartOne?.replace(sanitisationString, "")
|
|
|
|
// })
|
|
|
|
|
|
|
|
// strip the leading /path1/path2 path1 section from the path
|
|
|
|
const pathPartOne = location?.pathname?.split("/")[2]
|
2023-07-21 13:33:47 +00:00
|
|
|
|
|
|
|
const path = pathPartOne?.replace(/\//g, ".")
|
2023-07-21 01:13:02 +00:00
|
|
|
|
2023-08-06 10:24:18 +00:00
|
|
|
return path || "thingtime"
|
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])
|
|
|
|
|
2023-08-15 23:10:13 +00:00
|
|
|
const inEditorMode = React.useMemo(() => {
|
|
|
|
if (pathname.slice(0, 7) === "/editor") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}, [pathname])
|
|
|
|
|
|
|
|
const inEditMode = React.useMemo(() => {
|
|
|
|
if (pathname.slice(0, 5) === "/edit") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}, [pathname])
|
|
|
|
|
2023-07-21 01:13:02 +00:00
|
|
|
return (
|
|
|
|
<Flex
|
2023-08-15 23:10:13 +00:00
|
|
|
alignItems={inEditorMode ? "flex-start" : "center"}
|
2023-07-21 01:13:02 +00:00
|
|
|
justifyContent="center"
|
2023-08-15 23:10:13 +00:00
|
|
|
flexDirection={inEditorMode ? "row" : "column"}
|
2023-07-21 01:13:02 +00:00
|
|
|
maxWidth="100%"
|
|
|
|
>
|
2023-08-15 23:10:13 +00:00
|
|
|
{inEditorMode && (
|
|
|
|
<Thingtime
|
|
|
|
path={path}
|
|
|
|
thing={thing}
|
|
|
|
render
|
|
|
|
chakra
|
|
|
|
chakras={{ marginY: 200 }}
|
|
|
|
width="600px"
|
|
|
|
></Thingtime>
|
|
|
|
)}
|
2023-07-21 01:13:02 +00:00
|
|
|
<Thingtime
|
2023-08-15 23:10:13 +00:00
|
|
|
edit={inEditMode}
|
2023-07-21 01:13:02 +00:00
|
|
|
path={path}
|
|
|
|
thing={thing}
|
|
|
|
chakras={{ marginY: 200 }}
|
|
|
|
width="600px"
|
|
|
|
></Thingtime>
|
|
|
|
</Flex>
|
|
|
|
)
|
|
|
|
}
|