Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<html>
<head>
<meta charset="utf-8" />
<meta name="og:title" property="og:title" content="Sorting Algorithms Visualier">
<meta name="og:title" property="og:title" content="Sorting Algorithm Visualizer">
<meta name="site" content="Sorting Algorithm Visualizer" />
<meta name="author" content="Bikram Karki" />
<title>Sorting Algorithms Visualier</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
</html>
25 changes: 7 additions & 18 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
import React, { useEffect } from 'react'
import React from 'react'
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom'

// style
import './styles/app.scss'

// components
import { NavBar } from './components/shared'
import { Home, Algorithms, About } from './pages'
import Modal from './components/shared/Modal'

const App: React.FC = () => {
useEffect(() => {
alert(
`Caution!\nThe application shows flashing colors.\n Please, use it in color mode 'off' if you are affected by it.`
)
}, [])
return (
<div className='app'>
<Router>
<NavBar>
<Link to='/algorithms'>ALGORITHMS</Link>
<Link to='/about'>ABOUT</Link>
</NavBar>
<Modal />
<Switch>
<Route path='/algorithms'>
<Algorithms />
</Route>
<Route path='/about'>
<About />
</Route>
<Route path='/'>
<Home />
</Route>
<Route exact path='/algorithms' component={Algorithms} />
<Route exact path='/about' component={About} />
<Route exact path='/' component={Home} />
</Switch>
</Router>
</div>
</div >
)
}

Expand Down
2 changes: 0 additions & 2 deletions src/components/Algorithms/ContentContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react'

// components
import Section from './Section'

// utils
import { ITableOfContent } from '../../utils'

interface IProps {
Expand Down
5 changes: 1 addition & 4 deletions src/components/Algorithms/Section.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React from 'react'

// components
import { Header } from '../shared'

// utils
import { ITableOfContent } from '../../utils'

import { Header } from '../shared'
interface IProps {
content: ITableOfContent
}
Expand Down
8 changes: 3 additions & 5 deletions src/components/Algorithms/SideMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React from 'react'

// components
import { Header } from '../shared'

// utils
import { ITableOfContent } from '../../utils'

import { Header } from '../shared'

interface IProps {
tableOfContent: ITableOfContent[]
selected: string
onClick: (name: string) => any
onClick: (name: string) => void
}

const AlgorithmsTabs: React.FC<IProps> = ({
Expand Down
10 changes: 2 additions & 8 deletions src/components/Home/Bar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useRef } from 'react'
import React from 'react'

// utils
import { BarStatus } from '../../utils'

interface IProps {
Expand All @@ -13,12 +12,7 @@ const Bar: React.FC<IProps> = ({ value, status }: IProps) => {
height: value * 2,
backgroundColor: `var(--${status})`
}
// const renderCount = useRef(0)
return (
<div className='bar' style={barStyle}>
{/* {renderCount.current++} */}
</div>
)
return (<div className='bar' style={barStyle} />)
}

export default React.memo(Bar)
5 changes: 1 addition & 4 deletions src/components/Home/BarContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React from 'react'

// components
import BarComponent from './Bar'

// utils
import { Bar } from '../../utils'

import BarComponent from './Bar'
interface IProps {
step: Bar[]
}
Expand Down
1 change: 0 additions & 1 deletion src/components/Home/Legend.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'

// utils
import { BarStatus } from 'src/utils'

const Legend: React.FC<{ type: BarStatus }> = ({ type }) => {
Expand Down
9 changes: 3 additions & 6 deletions src/components/Home/LegendContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import React, { useMemo, useRef } from 'react'
import React, { useMemo } from 'react'
import { useSelector } from 'react-redux'

// components
import Legend from './Legend'
import { Header } from '../shared'

// utils
import { BarStatus } from '../../utils'
import { getColorMode } from '../../store/slice/sorting'

import Legend from './Legend'
import { Header } from '../shared'

const getLegends = (colorMode: boolean) => {
if (colorMode) {
Expand Down
2 changes: 0 additions & 2 deletions src/components/Home/MainPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react'

// hooks'
import useSort from '../../hooks/useSort'

// components
import BarContainer from './BarContainer'
import Controls from './Controls'
import LegendContainer from './LegendContainer'
Expand Down
10 changes: 3 additions & 7 deletions src/components/Home/OptionContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React, { ReactEventHandler, useCallback, useMemo, useRef } from 'react'
import React, { ReactEventHandler, useCallback, useMemo } from 'react'
import { useDispatch, useSelector } from 'react-redux'

// components
import { Header, Dropdown } from '../shared'

// js
import {
changeAlgorithm,
changeAnimationSpeed,
Expand All @@ -13,6 +9,8 @@ import {
} from '../../store/slice/sorting'
import { RootState } from '../../store'

import { Header, Dropdown } from '../shared'

const SizeOption = 'Size'
const AlgorithmOption = 'Algorithm'
const ModeOption = 'Color mode'
Expand Down Expand Up @@ -93,7 +91,6 @@ const OptionContainer: React.FC = () => {
},
[dispatch]
)
// const rerender = useRef(0)

const options = useMemo(() => {
return getMenuOptions(allAlgorithms)
Expand All @@ -113,7 +110,6 @@ const OptionContainer: React.FC = () => {
/>
</Header>
))}
{/* {rerender.current++} */}
</div>
)
}, [handleChangeEvent, options])
Expand Down
3 changes: 2 additions & 1 deletion src/components/Home/SidePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { ReactEventHandler, useState } from 'react'
import { useDispatch } from 'react-redux'


import { changeAlgorithm } from '../../store/slice/sorting'
import { Header, Dropdown } from '../shared'

// WIP

const bubbleSortCode = `
let bubbleSort = (inputArr) => {
let len = inputArr.length;
Expand Down
30 changes: 13 additions & 17 deletions src/components/shared/Dropdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef } from 'react'
import React from 'react'

type IProps = {
name?: string
Expand All @@ -11,23 +11,19 @@ type IProps = {
}

const Dropdown: React.FC<IProps> = ({ name, options, onChange, value }) => {
// const ref = useRef(0)
return (
<>
<select
name={name}
className='dropdown'
onChange={onChange}
defaultValue={value}
>
{options.map(({ key, value }) => (
<option key={key} value={value}>
{key}
</option>
))}
</select>
{/* {ref.current++} */}
</>
<select
name={name}
className='dropdown'
onChange={onChange}
defaultValue={value}
>
{options.map(({ key, value }) => (
<option key={key} value={value}>
{key}
</option>
))}
</select>
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

interface IProps {
children: any
children: React.ReactNode
className?: string
}

Expand Down
42 changes: 42 additions & 0 deletions src/components/shared/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { FC, useEffect, useState } from 'react';

const localStorageKey = 'modal-has-been-shown'

const Modal: FC = () => {
const [show, setShow] = useState<boolean>();

useEffect(() => {
if (window) {
const localStorageValue = localStorage.getItem(localStorageKey)
if (!localStorageValue) {
setShow(true)
}
}
}, []);

const handleModalClose = (): void => {
setShow(false)
localStorage.setItem(localStorageKey, 'true')
}

if (!show) {
return null
}

return <div className='modal'>
<div className='modal__content'>
<div className='modal__content__header'>
<strong>Caution!</strong>
</div>
<div className='modal__content__content'>
<p>The application shows flashing colors.</p>
<p>Please, keep the color mode option <strong>&quot;off&quot;</strong> if you are affected by it.</p>
</div>
<div className='modal__content__footer'>
<button type="button" onClick={handleModalClose}>Close</button>
</div>
</div>
</div>
}

export default Modal;
1 change: 0 additions & 1 deletion src/components/shared/NavBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'
import { Link } from 'react-router-dom'

// components
import { Header } from '..'

interface IProps {
Expand Down
1 change: 1 addition & 0 deletions src/components/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as Header } from './Header'
export { default as NavBar } from './NavBar'
export { default as Dropdown } from './Dropdown'
export { default as Modal } from './Modal'
7 changes: 2 additions & 5 deletions src/hooks/useSort.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable no-console */
import { useCallback, useEffect, useState } from 'react'
import { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'

// utils
import { Bar } from '../utils/Bar'
import { RootState } from '../store'
import {
Expand Down Expand Up @@ -44,7 +41,7 @@ const useSort = (): {
if (currentStep > 0) {
sort()
}
return pause
return sort
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [animationSpeed])

Expand Down
6 changes: 2 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'

// components
import App from './App'

// store
import store from './store'

import App from './App'

ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
Expand Down
6 changes: 2 additions & 4 deletions src/pages/Algorithms/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react'

// components
import { ITableOfContent } from '../../utils'

import {
Algorithm,
ContentContainer,
Expand All @@ -9,9 +10,6 @@ import {
Visualization
} from '../../components/Algorithms'

// utils
import { ITableOfContent } from '../../utils'

const tableOfContent: ITableOfContent[] = [
{ id: 'algorithm', title: 'Algorithm', component: Algorithm },
{
Expand Down
Loading