Skip to content

Commit

Permalink
refactor: move Menu component to its feature
Browse files Browse the repository at this point in the history
  • Loading branch information
isqua committed Oct 23, 2023
1 parent 261dd96 commit 34ce8fe
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 106 deletions.
7 changes: 3 additions & 4 deletions src/app/Root/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Layout } from '../../components/Layout'
import { Menu } from '../../components/Menu'

import { useGetTocQuery } from '../../features/toc'
import { DocPage } from '../../components/DocPage'
import { Error } from '../../components/Error'
import { Layout } from '../../components/Layout'
import { useGetTocQuery } from '../../features/toc'
import { Menu } from '../../features/toc/ui/Menu'
import tocUrl from '/toc.json?url'

export function Root() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type PropsWithChildren } from 'react'
import { getBreadCrumbs, type PageURL, type TableOfContent } from '../../../features/toc'
import type { PropsWithChildren } from 'react'
import { getBreadCrumbs } from '../../../core/getBreadCrumbs'
import type { PageURL, TableOfContent } from '../../../types'
import { LocationContext, TocContext } from './contexts'

type MenuProviderProps = PropsWithChildren<{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createContext } from 'react'
import { type PageDescriptor, type PageURL, type TableOfContent } from '../../../features/toc'

import type { PageDescriptor, PageURL, TableOfContent } from '../../../types'

type TocContextValue = {
toc: TableOfContent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useContext } from 'react'
import { buildMenu, type PageId, type SectionHighlight } from '../../../features/toc'

import { buildMenu } from '../../../core/buildMenu'
import type { PageId, SectionHighlight } from '../../../types'
import { LocationContext, TocContext } from './contexts'

export const useMenuItems = (parentId: PageId = '', level: number = 0, highlight: SectionHighlight) => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import clsx from 'clsx'
import { useState, type PropsWithChildren } from 'react'

import type { MenuItem } from '../../../features/toc'
import { Chevron } from '../../Chevron'
import { OptionalLink } from '../../OptionalLink'
import { Skeleton } from '../../Skeleton'
import { Chevron } from '../../../../../components/Chevron'
import { OptionalLink } from '../../../../../components/OptionalLink'
import { Skeleton } from '../../../../../components/Skeleton'
import type { MenuItem } from '../../../types'
import { useIsLoading } from '../Context/hooks'

import styles from './Item.module.css'
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { act, fireEvent, screen, waitFor } from '@testing-library/react'
import { describe, expect, it } from 'vitest'

import type { TableOfContent } from '../../features/toc'
import tocFlat from '../../test/fixtures/toc/flat.json'
import tocTwoLevels from '../../test/fixtures/toc/two-levels.json'
import { renderInApp } from '../../test'
import { renderInApp } from '../../../../test'
import tocFlat from '../../../../test/fixtures/toc/flat.json'
import tocTwoLevels from '../../../../test/fixtures/toc/two-levels.json'
import type { TableOfContent } from '../../types'
import { Menu } from './Menu'

describe('components/Menu', () => {
describe('features/toc/ui/Menu', () => {
it('should render skeletons while TOC is loading', async () => {
const toc: TableOfContent = tocTwoLevels
const currentUrl = '/bar.html'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type TableOfContent } from '../../features/toc'
import { useCurrentPageUrl } from '../../hooks/useCurrentPageUrl'
import { useCurrentPageUrl } from '../../../../hooks/useCurrentPageUrl'
import type { TableOfContent } from '../../types'
import { MenuProvider } from './Context/MenuProvider'
import { Section } from './Section/Section'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type PageId, type SectionHighlight } from '../../../features/toc'
import type { PageId, SectionHighlight } from '../../../types'
import { useMenuItems } from '../Context/hooks'
import { Item, ItemToggle } from '../Item/Item'

Expand Down
Loading

0 comments on commit 34ce8fe

Please sign in to comment.