Skip to content

Commit

Permalink
Merge pull request #400 from systemli/switch-ui-to-mui
Browse files Browse the repository at this point in the history
💄 Switch UI Library from Semantic UI to MUI
  • Loading branch information
0x46616c6b authored Jan 25, 2023
2 parents 11298ec + c8b2531 commit e73f0be
Show file tree
Hide file tree
Showing 92 changed files with 5,069 additions and 2,740 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": "error",
"no-console": "error",
"react/jsx-no-bind": "warn",
"react/jsx-no-bind": "off",
"react/jsx-sort-props": [
"warn",
{
Expand Down
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const config: Config.InitialOptions = {
testEnvironment: 'jsdom',
preset: 'ts-jest',
moduleNameMapper: {
'react-markdown': '<rootDir>/src/__mocks_/react-markdown.js',
'react-leaflet': '<rootDir>/src/__mocks__/react-leaflet.tsx',
'^.+.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
'jest-transform-stub',
},
Expand All @@ -15,7 +15,7 @@ const config: Config.InitialOptions = {
'.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
'jest-transform-stub',
},
transformIgnorePatterns: ['<rootDir>/node_modules/(?!react-markdown/)'],
transformIgnorePatterns: ['<rootDir>/node_modules/(?!react-leaflet)'],
setupFilesAfterEnv: ['./jest-setup.ts'],
collectCoverageFrom: ['src/**/*.{ts,tsx}'],
}
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
"scripts": {
"start": "webpack serve --config webpack.dev.config.ts",
"test": "jest",
"build": "webpack --config webpack.prod.config.ts",
"postinstall": "semantic-ui-css-patch"
"build": "webpack --config webpack.prod.config.ts"
},
"dependencies": {
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@fontsource/roboto": "^4.5.8",
"@fortawesome/fontawesome-svg-core": "^6.2.0",
"@fortawesome/free-brands-svg-icons": "^6.2.0",
"@fortawesome/free-solid-svg-icons": "^6.2.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@semantic-ui-react/css-patch": "^1.1.2",
"@mui/icons-material": "^5.10.9",
"@mui/material": "^5.10.10",
"@tanstack/react-query": "^4.10.3",
"@tanstack/react-query-devtools": "^4.11.0",
"jwt-decode": "^3.1.2",
Expand All @@ -38,6 +41,8 @@
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.2.1",
"@types/jwt-decode": "^3.1.0",
"@types/leaflet": "^1.9.0",
Expand Down Expand Up @@ -75,15 +80,14 @@
"jest-environment-jsdom": "^29.3.1",
"jest-fetch-mock": "^3.0.3",
"jest-transform-stub": "^2.0.0",
"jwt-encode": "^1.0.1",
"postcss": "^8.4.16",
"postcss-loader": "^7.0.1",
"postcss-remove-google-fonts": "^1.2.0",
"prettier": "^2.7.1",
"react-dev-utils": "^12.0.1",
"resolve": "^1.22.1",
"resolve-url-loader": "^5.0.0",
"semantic-ui-css": "^2.5.0",
"semantic-ui-react": "^2.1.3",
"style-loader": "^3.3.1",
"terser-webpack-plugin": "^5.3.3",
"ts-jest": "^29.0.3",
Expand Down
73 changes: 39 additions & 34 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,53 @@ import TickerView from './views/TickerView'
import UsersView from './views/UsersView'
import ProtectedRoute from './components/ProtectedRoute'
import NotFoundView from './views/NotFoundView'
import 'semantic-ui-css/semantic.min.css'
import './index.css'
import '../leaflet.config.js'
import { FeatureProvider } from './components/useFeature'
import ThemeProvider from './theme/ThemeProvider'
import '../leaflet.config.js'

const App: FC = () => {
const queryClient = new QueryClient({
defaultOptions: { queries: { staleTime: 60 * 1000 } },
})

return (
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AuthProvider>
<FeatureProvider>
<Routes>
<Route
element={<ProtectedRoute outlet={<HomeView />} role="user" />}
path="/"
/>
<Route
element={<ProtectedRoute outlet={<TickerView />} role="user" />}
path="/ticker/:tickerId"
/>
<Route
element={<ProtectedRoute outlet={<UsersView />} role="admin" />}
path="/users"
/>
<Route
element={
<ProtectedRoute outlet={<SettingsView />} role="admin" />
}
path="/settings"
/>
<Route element={<LoginView />} path="/login" />
<Route element={<NotFoundView />} path="*" />
</Routes>
</FeatureProvider>
</AuthProvider>
</BrowserRouter>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
<ThemeProvider>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AuthProvider>
<FeatureProvider>
<Routes>
<Route
element={<ProtectedRoute outlet={<HomeView />} role="user" />}
path="/"
/>
<Route
element={
<ProtectedRoute outlet={<TickerView />} role="user" />
}
path="/ticker/:tickerId"
/>
<Route
element={
<ProtectedRoute outlet={<UsersView />} role="admin" />
}
path="/users"
/>
<Route
element={
<ProtectedRoute outlet={<SettingsView />} role="admin" />
}
path="/settings"
/>
<Route element={<LoginView />} path="/login" />
<Route element={<NotFoundView />} path="*" />
</Routes>
</FeatureProvider>
</AuthProvider>
</BrowserRouter>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</ThemeProvider>
)
}

Expand Down
13 changes: 13 additions & 0 deletions src/__mocks__/react-leaflet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react'

export function MapContainer({ children }: { children: React.ReactNode }) {
return <>{children}</>
}

export function Marker({ children }: { children: React.ReactNode }) {
return <>{children}</>
}

export function TileLayer({ children }: { children: React.ReactNode }) {
return <>{children}</>
}
15 changes: 15 additions & 0 deletions src/components/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { CircularProgress, Stack, Typography } from '@mui/material'
import React, { FC } from 'react'

const Loader: FC = () => {
return (
<Stack alignItems="center" justifyContent="center" sx={{ m: 10 }}>
<CircularProgress size="3rem" />
<Typography component="span" sx={{ pt: 2 }} variant="h5">
Loading
</Typography>
</Stack>
)
}

export default Loader
20 changes: 20 additions & 0 deletions src/components/common/NamedListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { FC } from 'react'
import { Box, Typography } from '@mui/material'

interface Props {
title: string
children: React.ReactNode
}

const NamedListItem: FC<Props> = ({ title, children }) => {
return (
<Box sx={{ mb: 1 }}>
<Typography color="GrayText" component="span" variant="body2">
{title}
</Typography>
{children}
</Box>
)
}

export default NamedListItem
23 changes: 23 additions & 0 deletions src/components/common/TabPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Box } from '@mui/material'
import React, { FC } from 'react'

interface Props {
children?: React.ReactNode
index: number
value: number
}

const TabPanel: FC<Props> = ({ children, index, value }) => {
return (
<div
aria-labelledby={`simple-tab-${index}`}
hidden={value !== index}
id={`simple-tabpanel-${index}`}
role="tabpanel"
>
{value === index && <Box sx={{ py: 2 }}>{children}</Box>}
</div>
)
}

export default TabPanel
35 changes: 35 additions & 0 deletions src/components/message/AttachmentPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { FC } from 'react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { IconButton, ImageListItem } from '@mui/material'
import { Upload } from '../../api/Upload'
import { faXmarkSquare } from '@fortawesome/free-solid-svg-icons'

interface Props {
onDelete: (upload: Upload) => void
upload: Upload
}

const AttachmentPreview: FC<Props> = ({ onDelete, upload }) => {
const handleDelete = () => {
onDelete(upload)
}

return (
<ImageListItem sx={{ position: 'relative' }}>
<img
src={upload.url}
style={{
objectFit: 'cover',
}}
/>
<IconButton
onClick={handleDelete}
sx={{ position: 'absolute', right: 0 }}
>
<FontAwesomeIcon icon={faXmarkSquare} />
</IconButton>
</ImageListItem>
)
}

export default AttachmentPreview
33 changes: 33 additions & 0 deletions src/components/message/AttachmentsPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ImageList } from '@mui/material'
import React, { FC } from 'react'
import { Upload } from '../../api/Upload'
import AttachmentPreview from './AttachmentPreview'

interface Props {
attachments: Upload[]
onDelete: (upload: Upload) => void
}

const AttachmentsPreview: FC<Props> = ({ attachments, onDelete }) => {
const images = attachments.map((upload, key) => {
return (
<AttachmentPreview
key={key}
onDelete={() => onDelete(upload)}
upload={upload}
/>
)
})

if (images.length === 0) {
return null
}

return (
<ImageList cols={3} sx={{ mt: 1 }}>
{images}
</ImageList>
)
}

export default AttachmentsPreview
Loading

0 comments on commit e73f0be

Please sign in to comment.