Skip to content

Commit

Permalink
Shift Title and Tabs to routingTools to prevent circular references
Browse files Browse the repository at this point in the history
  • Loading branch information
HildoBijl committed Feb 9, 2024
1 parent 3feeab0 commit 2c40791
Show file tree
Hide file tree
Showing 25 changed files with 41 additions and 95 deletions.
2 changes: 1 addition & 1 deletion frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { WebSocketLink } from '@apollo/client/link/ws'
import { SubscriptionClient } from 'subscriptions-transport-ws'

import { graphqlAddress, graphqlWebsocketAddress } from './settings'
import App from './ui/layout/App'
import { App } from './ui/layout'

// The websocket link, for subscriptions.
const wsClient = new SubscriptionClient(
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ui/admin/UserInspection.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { skillTree, includePrerequisitesAndLinks, processSkill, getDefaultSkillD

import { useUserQuery } from 'api/admin'
import { Par, HorizontalSlider } from 'ui/components'
import { TitleItem } from 'ui/layout/Title'
import { TitleItem } from 'ui/routingTools'
import { SkillFlask } from 'ui/eduTools'

export function UserInspection() {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ui/eduTools/course/components/CourseName.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { useParams } from 'react-router-dom'

import { TitleItem } from 'ui/layout/Title'
import { TitleItem } from 'ui/routingTools'

import { courses } from '../../courses'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { exercises } from 'step-wise/eduTools'

import { TranslationFile, TranslationSection, useTranslator } from 'i18n'
import { LoadingNote, ErrorNote } from 'ui/components/flow'
import { TitleItem } from 'ui/layout/Title'
import { TitleItem } from 'ui/routingTools'

import { ExerciseContainer } from './ExerciseContainer'

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ui/eduTools/skills/SkillPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { skillTree } from 'step-wise/eduTools'

import { TranslationFile, useTranslator } from 'i18n'
import { LoadingNote } from 'ui/components'
import { TabPages, tabData } from 'ui/layout/tabs'
import { TabPages, tabData } from 'ui/routingTools'

import { ExercisePage } from '../exercises'

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ui/eduTools/skills/components/SkillName.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'

import { skillTree } from 'step-wise/eduTools'

import { TitleItem } from 'ui/layout/Title'
import { TitleItem } from 'ui/routingTools'

import { useSkillId } from '../util'

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/ui/layout/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const withApolloProvider = WrappedComponent => props => (
</ApolloProvider>
)

function App() {
function AppWithoutProvider() {
return (
<div id="app">
<div id="appInner">
Expand All @@ -38,4 +38,5 @@ function App() {
)
}

export default withApolloProvider(App)
const App = withApolloProvider(AppWithoutProvider)
export { App }
7 changes: 3 additions & 4 deletions frontend/src/ui/layout/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import Container from '@material-ui/core/Container'

import { TranslationFile } from 'i18n'

import { GroupIndicator } from 'ui/pages/groups/Indicator'
import { Title, TabBar } from 'ui/routingTools'
import { GroupIndicator } from 'ui/pages'

import Menu from './Menu'
import Title from './Title'
import { TabBar } from './tabs'

const useStyles = makeStyles((theme) => ({
toolbar: {
Expand All @@ -25,7 +24,7 @@ const useStyles = makeStyles((theme) => ({
},
}))

export default function Header({ Indicator }) {
export function Header({ Indicator }) {
const theme = useTheme()
const classes = useStyles()
const [titleCollapsed, setTitleCollapsed] = useState(false)
Expand Down
56 changes: 0 additions & 56 deletions frontend/src/ui/layout/LinkBar.js

This file was deleted.

6 changes: 3 additions & 3 deletions frontend/src/ui/layout/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from 'react'

import { useRoute } from 'ui/routingTools'
import { ModalManager, OfflineNotification, RecommendLogIn } from 'ui/components'
import { TabProvider } from 'ui/routingTools'
import { FieldController } from 'ui/form'

import PageContainer from './PageContainer'
import Header from './Header'
import { TabProvider } from './tabs'
import { PageContainer } from './PageContainer'
import { Header } from './Header'

export function Page() {
// Determine the contents.
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ui/layout/PageContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const useStyles = makeStyles((theme) => ({
},
}))

export default function PageContainer({ children }) {
export function PageContainer({ children }) {
const theme = useTheme()
const classes = useStyles()
return <Container maxWidth={theme.appWidth} className={classes.pageContainer}>{children}</Container>
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/ui/layout/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { default as App } from './App'
export { default as Header } from './Header.js'
export { default as LinkBar } from './LinkBar.js'
export { default as Page } from './Page.js'
export * from './App'
export * from './Header.js'
export * from './Page.js'
7 changes: 0 additions & 7 deletions frontend/src/ui/layout/tabs/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/ui/pages/Groups/Indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useNavigate } from 'react-router-dom'
import { makeStyles } from '@material-ui/core/styles'
import Tooltip from '@material-ui/core/Tooltip'

import { TranslationFile, TranslationSection, Translation, WordList } from 'i18n'
import { usePrevious } from 'util/index' // Unit test import issue: should be 'util' but this fails unit tests.
import { useActiveGroup, useOtherMembers } from 'api/group'
import { TranslationFile, TranslationSection, Translation, WordList } from 'i18n'
import { usePaths } from 'ui/routingTools'

import { translationPath } from './support'
Expand Down
1 change: 1 addition & 0 deletions frontend/src/ui/pages/Groups/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './NewGroup'
export * from './Groups'
export * from './Indicator'
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const useStyles = makeStyles((theme) => ({

// Set up the heading in the default breadcrumbs format.
const TitleContext = createContext()
export default function Title({ className, setTitleCollapsed }) {
export function Title({ className, setTitleCollapsed }) {
const classes = useStyles()
const fullTitleRef = useRef()
const partialTitleRef = useRef()
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/ui/routingTools/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './util'
export * from './routes'
export * from './route'
export * from './Title'
export * from './tabs'
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useTheme } from '@material-ui/core/styles'
import AppBar from '@material-ui/core/AppBar'
import Container from '@material-ui/core/Container'

import Tabs from './Tabs'
import { Tabs } from './Tabs'

export default function TabBar() {
export function TabBar() {
const theme = useTheme()
return (
<AppBar position="static" color="secondary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import React from 'react'
import { makeStyles } from '@material-ui/core/styles'

import { useTranslator } from 'i18n'
import tabData from './tabData'

import { tabData } from './tabData'

const useStyles = makeStyles((theme) => ({
tab: {
Expand All @@ -27,7 +28,7 @@ const useStyles = makeStyles((theme) => ({
},
}))

export default function TabLabel({ tab, showLabel, showIcon }) {
export function TabLabel({ tab, showLabel, showIcon }) {
const translate = useTranslator()

// Extract data (icon, title) on the tab.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useRoute, insertParametersIntoPath } from 'ui/routingTools'
import { getOrderedTabs, useTab } from './util'
import { useTabs, useTabContext } from './TabProvider'

export default function TabPages({ pages, initialPage, updateUrl = true }) {
export function TabPages({ pages, initialPage, updateUrl = true }) {
const urlTab = useTab()
const tabs = useConsistentValue(getOrderedTabs(pages))
const tabContext = useTabs(tabs, urlTab || initialPage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useConsistentValue, useLatest, useUpdater } from 'util/index' // Unit t
import { getOrderedTabs } from './util'

const TabContext = createContext()
export default function TabProvider({ children }) {
export function TabProvider({ children }) {
const [tab, setTab] = useState()
const [tabs, setTabs] = useState([])
const tabIndex = tabs.length === 0 || !tabs.includes(tab) ? 0 : tabs.indexOf(tab)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import MuiTab from '@material-ui/core/Tab'
import { useDimension, useResizeListener } from 'util/index' // Unit test import issue: should be 'util' but this fails unit tests.

import { useTabContext } from './TabProvider'
import TabLabel from './TabLabel'
import { TabLabel } from './TabLabel'

// Define limits on tab width where tabs switch their contents.
const lowerTabWidthLimit = 110 // Below this there is only an icon. Above this there is text.
Expand All @@ -19,7 +19,7 @@ const useStyles = makeStyles((theme) => ({
},
}))

export default function Tabs() {
export function Tabs() {
const theme = useTheme()
const classes = useStyles()
const { tabs, tabIndex, setTabIndex } = useTabContext()
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/ui/routingTools/tabs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './TabProvider'
export * from './tabData'
export * from './TabPages'
export * from './Tabs'
export * from './TabLabel'
export * from './TabBar'
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ applyMapping(tabData, (tab, id) => {
})

// Export the result.
export default tabData
export { tabData }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useParams } from 'react-router-dom'

import { sortByIndices } from 'step-wise/util'

import tabData from './tabData'
import { tabData } from './tabData'

export function getOrderedTabs(pages) {
pages = Array.isArray(pages) ? pages : Object.keys(pages) // Ensure pages is an array of page indices.
Expand Down

0 comments on commit 2c40791

Please sign in to comment.