Skip to content

Commit

Permalink
interecitpitng routes
Browse files Browse the repository at this point in the history
  • Loading branch information
dinoDanic committed Mar 4, 2024
1 parent 94e3f21 commit c8d27d0
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 8 deletions.
1 change: 1 addition & 0 deletions apps/bible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [ ] Intercepting Routes
- [ ] Barrel exports
- [ ] Eslint, Prettier - airbnb?
- [ ] husky
- [ ] Card, Layout How to find reusable components
- [ ] Types, Naming Types. component Task type = Task?
- [ ] Spreding props, when to and when not to <Task key={task.id} {...task} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Heading } from '@/components/typography/heading'

export default function Loading() {
return <Heading level="4">Loading todo by id in modal..</Heading>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use client'

import { type ElementRef, useEffect, useRef } from 'react'
import { useRouter } from 'next/navigation'
import { createPortal } from 'react-dom'

export function Modal({ children }: { children: React.ReactNode }) {
const router = useRouter()
const dialogRef = useRef<ElementRef<'dialog'>>(null)

useEffect(() => {
if (!dialogRef.current?.open) {
dialogRef.current?.showModal()
}
}, [])

function onDismiss() {
router.back()
}

return createPortal(
<div className="modal-backdrop">
<dialog ref={dialogRef} className="modal" onClose={onDismiss}>
{children}
<button onClick={onDismiss} className="close-button" />
</dialog>
</div>,
document.getElementById('modal-root')!
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { sleep } from '@/lib/utils'

export default async function TodoByIdModalPage() {
await sleep(2000)
return <div>i am todo modal</div>
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Default() {
return null
}
3 changes: 3 additions & 0 deletions apps/bible/app/bible/routing/intercepting-routes/default.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Default() {
return null
}
15 changes: 15 additions & 0 deletions apps/bible/app/bible/routing/intercepting-routes/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { PropsWithChildren, ReactNode } from 'react'

type Props = PropsWithChildren & {
modal: ReactNode
}

export default function InterceptingRoutesLayout({ children, modal }: Props) {
return (
<div>
{children}
{modal}
<div id="modal-root" />
</div>
)
}
5 changes: 5 additions & 0 deletions apps/bible/app/bible/routing/intercepting-routes/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Heading } from '@/components/typography/heading'

export default function Loading() {
return <Heading level="4">Loading todos...</Heading>
}
21 changes: 18 additions & 3 deletions apps/bible/app/bible/routing/intercepting-routes/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
const InterceptingRoutes = () => {
return <div>hi</div>
import { Stack } from '@/components/primitives/stack'
import { todo } from '@/module/todo'
import Link from 'next/link'

const InterceptingRoutesPage = async () => {
const { todos } = await todo.api.getTodos()
return (
<Stack>
{todos.map((item) => {
return (
<Link href={`/bible/routing/intercepting-routes/todo/${item.id}`} key={item.id}>
<todo.components.TodoCard {...item} />
</Link>
)
})}
</Stack>
)
}

export default InterceptingRoutes
export default InterceptingRoutesPage
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Heading } from '@/components/typography/heading'

export default function Loading() {
return <Heading level="4">Loading todo by id in page..</Heading>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { sleep } from '@/lib/utils'

export default async function TodoByIdPage() {
await sleep(2000)
return <div>hi</div>
}

0 comments on commit c8d27d0

Please sign in to comment.