ywana-core8 0.1.61 → 0.1.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.1.61",
3
+ "version": "0.1.62",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
package/src/site/site.js CHANGED
@@ -253,13 +253,12 @@ const SiteMenu = ({ iconSrc, title, children, min }) => {
253
253
  * SitePage
254
254
  */
255
255
  const SitePage = ({ children, init }) => {
256
-
257
256
  const context = useContext(SiteContext)
258
257
  const { page } = context
259
-
260
- const [renderedPage, setRenderedPage] = useState(page)
261
- const [transitionClass, setTransitionClass] = useState('')
262
-
258
+
259
+ const [displayedPage, setDisplayedPage] = useState(page)
260
+ const [isExiting, setIsExiting] = useState(false)
261
+
263
262
  useEffect(() => {
264
263
  if (init) {
265
264
  context.goto(init)
@@ -269,23 +268,25 @@ const SitePage = ({ children, init }) => {
269
268
  }, [])
270
269
 
271
270
  useEffect(() => {
272
- if (page !== renderedPage) {
273
- setTransitionClass(`page-out`)
274
- setTimeout(() => {
275
- setTransitionClass(`page-in`)
276
- setRenderedPage(page)
277
- setTimeout(() => {
278
- setTransitionClass('')
279
- }, 300)
271
+ if (page !== displayedPage) {
272
+ setIsExiting(true)
273
+
274
+ // Esperamos a que la animación de salida termine
275
+ const timeout = setTimeout(() => {
276
+ setDisplayedPage(page)
277
+ setIsExiting(false)
280
278
  }, 300)
281
- setRenderedPage(page)
279
+
280
+ return () => clearTimeout(timeout)
282
281
  }
283
282
  }, [page])
284
283
 
285
- const currentPage = Children.toArray(children).filter(child => child.props ? child.props.id === renderedPage : false)
284
+ const allChildren = React.Children.toArray(children)
285
+ const current = allChildren.find(child => child.props?.id === displayedPage)
286
+
286
287
  return (
287
- <main className={`site-page-container ${transitionClass}`}>
288
- {currentPage}
288
+ <main className={`site-page-container ${isExiting ? 'page-out' : 'page-in'}`}>
289
+ {current}
289
290
  </main>
290
291
  )
291
292
  }