Skip to content

Commit

Permalink
Pretty fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jho406 committed Dec 31, 2024
1 parent 4ddd00d commit d6b1ef4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
17 changes: 9 additions & 8 deletions superglue/lib/components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
NavigationProviderProps,
AllPages,
SuperglueState,
PageKey
PageKey,
} from '../types'
import { Update } from 'history'
import { useDispatch, useSelector, useStore } from 'react-redux'
Expand Down Expand Up @@ -49,8 +49,10 @@ const NavigationProvider = forwardRef(function NavigationProvider(
ref: ForwardedRef<{ navigateTo: NavigateTo }>
) {
const dispatch = useDispatch()
const pages = useSelector<RootState,AllPages>((state) => state.pages)
const superglue = useSelector<RootState,SuperglueState>((state) => state.superglue)
const pages = useSelector<RootState, AllPages>((state) => state.pages)
const superglue = useSelector<RootState, SuperglueState>(
(state) => state.superglue
)
const store = useStore()

useEffect(() => {
Expand All @@ -74,12 +76,12 @@ const NavigationProvider = forwardRef(function NavigationProvider(
// and so we have restore scroll and the set the active page
// - In cases where the response was redirected, the calculated
// navigationAction is set to 'replace', and is handled gracefully by navigateTo,
// before this method gets called.
// before this method gets called.
// That's why we're only concerned with the first case, but we gracefully warn
// if the application visit did not return the meta object like the dev was supposed to.
return visit(pageKey, { revisit: true }).then((meta) => {
if (meta) {
if (meta.navigationAction === "none") {
if (meta.navigationAction === 'none') {
dispatch(setActivePage({ pageKey }))
setWindowScroll(posX, posY)
}
Expand Down Expand Up @@ -139,10 +141,9 @@ const NavigationProvider = forwardRef(function NavigationProvider(
const navigateTo: NavigateTo = (
path,
{ action } = {
action: 'push'
action: 'push',
}
) => {

if (action === 'none') {
return false
}
Expand Down Expand Up @@ -219,7 +220,7 @@ const NavigationProvider = forwardRef(function NavigationProvider(
<NavigationContext.Provider
value={{ pageKey: currentPageKey, navigateTo, visit, remote }}
>
<Component/>
<Component />
</NavigationContext.Provider>
)
} else {
Expand Down
6 changes: 3 additions & 3 deletions superglue/lib/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
ApplicationProps,
NavigateTo,
SuperglueStore,
SetupProps
SetupProps,
} from './types'
export { superglueReducer, pageReducer, rootReducer } from './reducers'
export { getIn } from './utils/immutability'
Expand Down Expand Up @@ -83,8 +83,8 @@ export const setup = ({
store,
buildVisitAndRemote,
history,
navigatorRef
} : SetupProps) => {
navigatorRef,
}: SetupProps) => {
config.baseUrl = baseUrl

const { visit, remote } = buildVisitAndRemote(navigatorRef, store)
Expand Down
18 changes: 9 additions & 9 deletions superglue/spec/features/navigation.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Home = () => {
}

const About = () => {
const {heading} = useContent()
const { heading } = useContent()
return <h1>About Page, {heading}</h1>
}

Expand Down Expand Up @@ -200,7 +200,7 @@ describe('navigation', () => {
navigateTo('/about#title')
})
}

return (
<div>
<h1>Home Page</h1>
Expand Down Expand Up @@ -337,13 +337,13 @@ describe('navigation', () => {
}

const Home = () => {
const { visit, navigateTo} = useContext(NavigationContext)
const { visit, navigateTo } = useContext(NavigationContext)
const handleClick = () => {
visit('/about').then(() => {
navigateTo('/about', { action: 'replace' })
})
}

return (
<div>
<h1>Home Page</h1>
Expand Down Expand Up @@ -402,9 +402,9 @@ describe('navigation', () => {
const Home = () => {
const { navigateTo } = useContext(NavigationContext)
const handleClick = () => {
navigateTo('/home', {action: 'replace'})
navigateTo('/home', { action: 'replace' })
}

return (
<div>
<h1>Home Page</h1>
Expand Down Expand Up @@ -536,8 +536,8 @@ describe('navigation', () => {
const Home = () => {
useEffect(() => {
process.nextTick(() => history.back())
},[])
}, [])

return (
<div>
<h1>Home Page</h1>
Expand Down Expand Up @@ -631,7 +631,7 @@ describe('navigation', () => {
const handleClick = () => {
remote('/about?props_at=address')
}

return (
<div>
<h1>Home Page</h1>
Expand Down
24 changes: 12 additions & 12 deletions superglue/spec/lib/NavComponent.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('Nav', () => {
},
superglue: {
csrfToken: 'abc',
currentPageKey: "/home"
currentPageKey: '/home',
},
})

Expand Down Expand Up @@ -108,7 +108,7 @@ describe('Nav', () => {
},
superglue: {
csrfToken: 'abc',
currentPageKey: '/home'
currentPageKey: '/home',
},
})

Expand Down Expand Up @@ -153,7 +153,7 @@ describe('Nav', () => {
},
superglue: {
csrfToken: 'abc',
currentPageKey: '/home'
currentPageKey: '/home',
},
})
const scrollTo = vi.spyOn(window, 'scrollTo').mockImplementation(() => {})
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('Nav', () => {
},
superglue: {
csrfToken: 'abc',
currentPageKey: '/home'
currentPageKey: '/home',
},
})

Expand All @@ -235,15 +235,15 @@ describe('Nav', () => {
}
mountTimes++
}, [])

return (
<div>
<h1>Home Page</h1>
<button onClick={visit}> click </button>
</div>
)
}

const About = () => {
useEffect(() => {
visitedAbout = true
Expand Down Expand Up @@ -284,7 +284,7 @@ describe('Nav', () => {
},
superglue: {
csrfToken: 'abc',
currentPageKey: '/home'
currentPageKey: '/home',
},
})

Expand Down Expand Up @@ -336,7 +336,7 @@ describe('Nav', () => {
},
superglue: {
csrfToken: 'abc',
currentPageKey: '/about'
currentPageKey: '/about',
},
})
const scrollTo = vi
Expand Down Expand Up @@ -385,7 +385,7 @@ describe('Nav', () => {
posX: 10,
posY: 10,
})

const store = buildStore({
pages: {
'/home': {
Expand All @@ -399,7 +399,7 @@ describe('Nav', () => {
},
superglue: {
csrfToken: 'abc',
currentPageKey: '/about'
currentPageKey: '/about',
},
})
const scrollTo = vi
Expand Down Expand Up @@ -465,7 +465,7 @@ describe('Nav', () => {
},
superglue: {
csrfToken: 'abc',
currentPageKey: '/home'
currentPageKey: '/home',
},
})
const scrollTo = vi
Expand Down Expand Up @@ -520,7 +520,7 @@ describe('Nav', () => {
},
superglue: {
csrfToken: 'abc',
currentPageKey: '/home'
currentPageKey: '/home',
},
})
const scrollTo = vi
Expand Down

0 comments on commit d6b1ef4

Please sign in to comment.