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 = { const force = {
settings: { settings: {
undoLimit: 999,
// commander: { // commander: {
// nav: { // nav: {
// commanderActive: false, // 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 = { const newVersionData = {
@ -64,7 +72,8 @@ const initialValues = {
Content: { Content: {
hidden1: "Edit this to your heart's desire.", hidden1: "Edit this to your heart's desire.",
"How?": "Just search for Content and edit the value to whatever you want.", "How?": "Just search for Content and edit the value to whatever you want.",
"Example:": `Content = New Content! "Example:": `
Content = New Content!
Content.Nested Content = New Nested Content! Content.Nested Content = New Nested Content!
`, `,
}, },
@ -253,9 +262,9 @@ export const ThingtimeProvider = (props: any): JSX.Element => {
if (parsed) { if (parsed) {
const localIsValid = const localIsValid =
!parsed.version || parsed.version >= force.version !parsed.version || parsed.version >= force.version
let newThingtime = null let newThingtime = smarts.merge(force, initialThingtime)
if (localIsValid) { if (localIsValid) {
newThingtime = smarts.merge(force, parsed) newThingtime = smarts.merge(parsed, newThingtime)
} else { } else {
const withVersionUpdates = smarts.merge(newVersionData, parsed) const withVersionUpdates = smarts.merge(newVersionData, parsed)
newThingtime = smarts.merge(force, withVersionUpdates) newThingtime = smarts.merge(force, withVersionUpdates)
@ -304,6 +313,38 @@ export const ThingtimeProvider = (props: any): JSX.Element => {
) )
// setTimeout(() => { // setTimeout(() => {
const stringified = stringify(thingtime) 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) window.localStorage.setItem("thingtime", stringified)
// }, 600) // }, 600)
} catch (err) { } catch (err) {

View File

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

View File

@ -126,7 +126,7 @@ export const Thingtime = (props) => {
}, [props?.fullPath, props?.path, props?.thing]) }, [props?.fullPath, props?.path, props?.thing])
const parentPath = React.useMemo(() => { const parentPath = React.useMemo(() => {
const parentPath = fullPath.split(".").slice(0, -1).join(".") const parentPath = fullPath?.split(".")?.slice(0, -1)?.join(".")
if (!parentPath) { if (!parentPath) {
return "thingtime" return "thingtime"
@ -597,7 +597,7 @@ export const Thingtime = (props) => {
onClick={addNewChild} onClick={addNewChild}
paddingY={2} 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>
<Icon size={7} name="plus"></Icon> */} <Icon size={7} name="plus"></Icon> */}
</Flex> </Flex>
@ -647,6 +647,7 @@ export const Thingtime = (props) => {
</Box> </Box>
)} )}
{pathDom && ( {pathDom && (
<Flex flexDirection="row" columnGap={1} paddingLeft={2}>
<Flex <Flex
paddingLeft={1} paddingLeft={1}
opacity={showContextIcon ? 1 : 0} opacity={showContextIcon ? 1 : 0}
@ -656,8 +657,6 @@ export const Thingtime = (props) => {
> >
<Icon name="magic" size={10}></Icon> <Icon name="magic" size={10}></Icon>
</Flex> </Flex>
)}
{pathDom && (
<Flex <Flex
paddingLeft={1} paddingLeft={1}
opacity={showContextIcon ? 1 : 0} opacity={showContextIcon ? 1 : 0}
@ -667,6 +666,7 @@ export const Thingtime = (props) => {
> >
<Icon name="bin" size={8}></Icon> <Icon name="bin" size={8}></Icon>
</Flex> </Flex>
</Flex>
)} )}
</Flex> </Flex>
</Flex> </Flex>