feat: feature/mvp-sprint-1

This commit is contained in:
Nikolaj Frey 2023-08-13 20:41:55 +10:00
parent fad185e0ec
commit 7eecc21173
3 changed files with 67 additions and 28 deletions

View File

@ -28,6 +28,7 @@ try {
const force = {
settings: {
undoLimit: 999,
// commander: {
// nav: {
// commanderActive: false,
@ -37,7 +38,14 @@ const force = {
// },
// },
},
version: 23,
// Content: {
// hidden1: "Edit this to your heart's desire.",
// "How?": "Just search for Content and edit the value to whatever you want.",
// "Example:": `Content = New Content!
// Content.Nested Content = New Nested Content!
// `,
// },
version: 24,
}
const newVersionData = {
@ -64,8 +72,9 @@ const initialValues = {
Content: {
hidden1: "Edit this to your heart's desire.",
"How?": "Just search for Content and edit the value to whatever you want.",
"Example:": `Content = New Content!
Content.Nested Content = New Nested Content!
"Example:": `
Content = New Content!
Content.Nested Content = New Nested Content!
`,
},
}
@ -253,9 +262,9 @@ export const ThingtimeProvider = (props: any): JSX.Element => {
if (parsed) {
const localIsValid =
!parsed.version || parsed.version >= force.version
let newThingtime = null
let newThingtime = smarts.merge(force, initialThingtime)
if (localIsValid) {
newThingtime = smarts.merge(force, parsed)
newThingtime = smarts.merge(parsed, newThingtime)
} else {
const withVersionUpdates = smarts.merge(newVersionData, parsed)
newThingtime = smarts.merge(force, withVersionUpdates)
@ -304,6 +313,38 @@ export const ThingtimeProvider = (props: any): JSX.Element => {
)
// setTimeout(() => {
const stringified = stringify(thingtime)
let thingtimeHistory = []
try {
const thingtimeHistoryString =
window.localStorage.getItem("thingtimeHistory")
const parsedThingtimeHistory = JSON.parse(thingtimeHistoryString)
if (parsedThingtimeHistory instanceof Array) {
thingtimeHistory = parsedThingtimeHistory
}
} catch {
// nothing
}
try {
const limit = thingtime?.settings?.undoLimit || 999
if (thingtimeHistory?.length > limit) {
thingtimeHistory = thingtimeHistory.slice(
thingtimeHistory.length - limit
)
}
thingtimeHistory.push({
timestamp: Date.now(),
value: stringify(thingtime),
})
const thingtimeHistoryNewString = JSON.stringify(thingtimeHistory)
window.localStorage.setItem(
"thingtimeHistory",
thingtimeHistoryNewString
)
} catch {
// nothing
}
window.localStorage.setItem("thingtime", stringified)
// }, 600)
} catch (err) {

View File

@ -41,11 +41,9 @@ export const Nav = (props) => {
// or if first characters of pathname are /edit replace with /things
if (pathname.slice(0, 7) === "/things") {
const newPathname = pathname.replace("/things", "/edit")
e?.preventDefault?.()
navigate(newPathname)
} else if (pathname.slice(0, 5) === "/edit") {
const newPathname = pathname.replace("/edit", "/things")
e?.preventDefault?.()
navigate(newPathname)
}
},

View File

@ -126,7 +126,7 @@ export const Thingtime = (props) => {
}, [props?.fullPath, props?.path, props?.thing])
const parentPath = React.useMemo(() => {
const parentPath = fullPath.split(".").slice(0, -1).join(".")
const parentPath = fullPath?.split(".")?.slice(0, -1)?.join(".")
if (!parentPath) {
return "thingtime"
@ -597,7 +597,7 @@ export const Thingtime = (props) => {
onClick={addNewChild}
paddingY={2}
>
<Icon size={12} name="seedling"></Icon>
<Icon size={10} name="seedling"></Icon>
{/* <Icon size={7} name="plus"></Icon>
<Icon size={7} name="plus"></Icon> */}
</Flex>
@ -647,25 +647,25 @@ export const Thingtime = (props) => {
</Box>
)}
{pathDom && (
<Flex
paddingLeft={1}
opacity={showContextIcon ? 1 : 0}
cursor="pointer"
transition="all 0.2s ease-in-out"
onClick={resetValue}
>
<Icon name="magic" size={10}></Icon>
</Flex>
)}
{pathDom && (
<Flex
paddingLeft={1}
opacity={showContextIcon ? 1 : 0}
cursor="pointer"
transition="all 0.2s ease-in-out"
onClick={deleteValue}
>
<Icon name="bin" size={8}></Icon>
<Flex flexDirection="row" columnGap={1} paddingLeft={2}>
<Flex
paddingLeft={1}
opacity={showContextIcon ? 1 : 0}
cursor="pointer"
transition="all 0.2s ease-in-out"
onClick={resetValue}
>
<Icon name="magic" size={10}></Icon>
</Flex>
<Flex
paddingLeft={1}
opacity={showContextIcon ? 1 : 0}
cursor="pointer"
transition="all 0.2s ease-in-out"
onClick={deleteValue}
>
<Icon name="bin" size={8}></Icon>
</Flex>
</Flex>
)}
</Flex>