Skip to content

Commit 1ba00b7

Browse files
committed
some bugs resolved"
1 parent 595f132 commit 1ba00b7

8 files changed

Lines changed: 25 additions & 177 deletions

File tree

‎src/App.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class App extends Component {
3232

3333

3434
return (
35-
<div className = "App"> {/* SG 07/11/2022 21:21 remove "dark" to enable light theme, working on a toggle button */}
35+
<div className = "App h-screen dark:bg-lightGray"> {/* SG 07/11/2022 21:21 remove "dark" to enable light theme, working on a toggle button */}
3636

3737
<AppRouter/>
3838

‎src/components/Canvas/AlgorithmSelection.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function AlgorithmSelection({strategy, options}) {
3737
onClick={() => setShowDropdown(!showDropdown)}
3838
>
3939
<p className="text-white font-semibold ml-2">{currentAlgo} Sort</p>
40-
<Triangle className={`transition-all duration-200 ease-in-out scale-[.5] ${showDropdown ? "rotate-0" : "rotate-180"}`}/>
40+
<Triangle className={`h-5 transition-all duration-200 ease-in-out scale-[.5] ${showDropdown ? "rotate-0" : "rotate-180"}`}/>
4141
</div>
4242

4343
{/* Dropdown menu */}
@@ -48,7 +48,7 @@ function AlgorithmSelection({strategy, options}) {
4848
options.setState({algorithm: "Radix"});
4949
strategy.setStrategy = Radix;
5050
localStorage.setItem("algorithm", "Radix");
51-
setShowDropdown(!showDropdown)
51+
setShowDropdown(!showDropdown);
5252
}}
5353
>
5454
<p className={`${currentAlgo === 'Radix' && 'text-black group-hover:text-white'}`}>Radix Sort</p>

‎src/components/Canvas/Canvas.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Canvas extends Component {
1414
const MARGIN = CONSTANTS.margin;
1515
const SCREEN_WIDTH = window.innerWidth;
1616
const BAR_WIDTH = Math.floor((SCREEN_WIDTH - (MARGIN*arrayLength)) / arrayLength);
17-
const HEIGHT_ADJUSTMENT = 122; // SG 07/11/2022 21:34 this is to make the canvas take up the whole screen height, avoiding height=vw for mobile responsive issues
18-
const CANVAS_HEIGHT = window.innerHeight - CONSTANTS.OFFSET + HEIGHT_ADJUSTMENT +"px";
17+
const MARGIN_BTW_CANVAS_OPTIONS = 122;
18+
const CANVAS_HEIGHT = window.innerHeight - CONSTANTS.OFFSET + MARGIN_BTW_CANVAS_OPTIONS +"px";
1919

2020

2121
return (

‎src/components/Canvas/InputField.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class InputField extends Component {
3232
return (
3333
<div className="flex flex-col dark:bg-darkGray bg-gray-100 shadow-lg shadow-gray-200" id="input-field-sort">
3434

35-
<div className={`flex items-center justify-center py-2 w-sreen gap-4 flex-wrap ${this.name[0] + ' '}`}>
35+
<div className={`flex items-center justify-center py-4 md:py-2 w-sreen gap-4 flex-wrap ${this.name[0] + ' '}`}>
3636

3737
<div className="flex flex-col justify-center items-center h-full sm:mb-0 pl-6" >
3838
<div className="flex">
@@ -47,7 +47,13 @@ class InputField extends Component {
4747
maximum={InputHandler.getAllowedMaxInputSize()}
4848
/>
4949
<button onClick={() => {
50-
this.props.InputHandler.setState({generatedArray: InputHandler.handleInputRequest(inputArrayLength)});
50+
if(inputArrayLength > 1) {
51+
this.props.InputHandler.setState({generatedArray: InputHandler.handleInputRequest(inputArrayLength)});
52+
window.scroll({ // SG 07/10/2022 18:55 for mobile devices
53+
top: 1000,
54+
behavior: 'smooth'
55+
});
56+
}
5157
}} className="bg-blue-500 p-[.7em] ml-3 rounded-md text-white font-semibold hover:scale-[1.02] hover:bg-blue-600 transition duration-200 ease-in-out dark:bg-blue-600 dark:text-white">Generate Array</button>
5258
</div>
5359
</div>

‎src/components/Canvas/options/Option.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from 'react'
22
import { CONSTANTS } from '../../../Utility/config';
33
import SlideBar from './SlideBar';
44

5-
function Option({options, mainCanvasInputHandler}) {
5+
function Option({options, mainCanvasInputHandler, algorithm}) {
66
const [open, setOpen] = useState(false);
77
const ref = useRef();
88

@@ -50,6 +50,8 @@ function Option({options, mainCanvasInputHandler}) {
5050
)
5151
}
5252

53+
// SG 07/13/2022 13:06 Making sure that only Selection sort will have the option to change the optimum key color
54+
if((algorithm === "Radix" || algorithm === "Merge") && (options.name === "CURRENT_MIN")) return null;
5355

5456
return (
5557
<div className="flex flex-col items-center relative space-y-2 cursor-pointer">
@@ -71,7 +73,7 @@ function Option({options, mainCanvasInputHandler}) {
7173
let j = JSON.parse(localStorage.getItem("options"));
7274
j[options.stateName] = color;
7375
localStorage.setItem("options", JSON.stringify(j));
74-
}
76+
}
7577
}/>
7678
))}
7779
</div>

‎src/components/Canvas/options/Options.js‎

Lines changed: 2 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -68,177 +68,18 @@ class Options extends Component {
6868
}
6969

7070
}
71-
7271

7372

74-
// componentDidUpdate(prevProps, prevState) {
75-
76-
77-
78-
// //TODO resolve performance issues where it renders too many times
79-
// if(prevState !== this.state) {
80-
// let openOption = '';
81-
// let states = Object.keys(this.state)
82-
83-
// for(let i = 0; i < states.length; i++) {
84-
// if(this.state[states[i]]) openOption = states[i];
85-
// }
86-
87-
88-
// console.log("first")
89-
// if(openOption) {
90-
// let openDropdown = document.querySelector("." + openOption);
91-
92-
// document.addEventListener('click', (event) => {
93-
// var isClickInsideElement = openDropdown.contains(event.target);
94-
// if (!isClickInsideElement) {
95-
96-
// let payload = {}
97-
// for(let i = 0; i < states.length; i++) {
98-
// payload[states[i]] = false;
99-
// }
100-
// this.setState({[openOption]: false})
101-
// // this.setState(payload);
102-
// // console.log(payload);
103-
104-
// }
105-
// });
106-
// }
107-
// }
108-
// }
109-
110-
111-
11273
render() {
113-
114-
115-
const {showProcessingColor, showDefaultBarColor, showSortedBarColor, showMinBarColor, showDelay } = this.state;
11674
const { algorithm } = this.props;
11775

11876
return (
11977
<div className="rounded-md z-10">
120-
12178
<div className="w-fit flex space-x-5">
12279
{optionItems.map((option) => (
123-
<Option options={option} mainCanvasInputHandler={this.props.options} key={option.name}/>
80+
<Option options={option} mainCanvasInputHandler={this.props.options} key={option.name} algorithm={algorithm}/>
12481
))}
125-
126-
{/* <div className="flex flex-col items-center relative space-y-2 cursor-pointer">
127-
<div className="p-2 hover:bg-gray-200 showDefaultBarColor rounded-md peer" onClick={() => this.setState({showDefaultBarColor: !showDefaultBarColor})}>
128-
<UnsortedBars className="scale-[1.2]"/>
129-
</div>
130-
<div className={`h-3 w-3 rounded-full`} style={{backgroundColor: this.props.options.state.options.defaultBarColor}}/>
131-
<div className={`options-dropdown transition-all duration-200 ease-in-out absolute bg-white dark:bg-darkGray dark:border-lightDark p-2 rounded-md border-2 top-[100%] space-y-1 ${showDefaultBarColor ? "scale-100" : "scale-0 -translate-y-[7em]"}`}>
132-
{CONSTANTS.DEFAULT.map((color) => (
133-
<div
134-
key={color}
135-
style={{backgroundColor: color}}
136-
className={`w-8 h-8 rounded-md hover:scale-[1.15] transition-all duration-200 ease-in-out ${color === 'white' && "border-2 border-gray-300"}`}
137-
onClick={() => {
138-
this.props.options.setState(prev => ({options: {...prev.options, defaultBarColor: color, }}));
139-
this.setState({showDefaultBarColor: !showDefaultBarColor})
140-
}
141-
}/>
142-
))}
143-
</div>
144-
<p className={`shadow-lg bg-white z-10 absolute top-[100%] p-2 rounded-md hidden whitespace-nowrap peer-hover:block tool-tip-options text-gray-600 font-semibold`}>Unsorted bars color</p>
145-
</div>
146-
147-
<div className="flex flex-col items-center relative space-y-2 cursor-pointer">
148-
<div className="p-2 hover:bg-gray-200 showSortedBarColor peer rounded-md z-100" onClick={() => this.setState({showSortedBarColor: !showSortedBarColor})}>
149-
<SortedBars className="scale-[1.2]"/>
150-
</div>
151-
<div className={`h-3 w-3 rounded-full`} style={{backgroundColor: this.props.options.state.options.sortedBarColor}}/>
152-
<div className={`options-dropdown transition-all duration-200 ease-in-out absolute dark:bg-darkGray dark:border-lightDark bg-white p-2 rounded-md border-2 top-[100%] space-y-1 ${showSortedBarColor ? "scale-100" : "scale-0 -translate-y-[7em]"}`}>
153-
{CONSTANTS.SORTED.map((color) => (
154-
<div
155-
key={color}
156-
style={{backgroundColor: color}}
157-
className={`w-8 h-8 rounded-md hover:scale-[1.15] transition-all duration-200 ease-in-out ${color === 'white' && "border-2 border-gray-300"}`}
158-
onClick={() => {
159-
this.props.options.setState(prev => ({options: {...prev.options, sortedBarColor: color, }}));
160-
this.setState({showSortedBarColor: !showSortedBarColor})
161-
}
162-
}/>
163-
))}
164-
</div>
165-
<p className={`shadow-lg bg-white inline z-10 absolute top-[100%] p-2 rounded-md hidden peer-hover:block tool-tip-options text-gray-600 whitespace-nowrap font-semibold`}>Sorted bars color</p>
166-
</div>
167-
168-
169-
<div className="flex flex-col items-center relative space-y-2 cursor-pointer">
170-
<div className="p-2 hover:bg-gray-200 showProcessingColor peer rounded-md" onClick={() => this.setState({showProcessingColor: !showProcessingColor})}>
171-
<CPU className="scale-[1.2]"/>
172-
</div>
173-
<div className={`h-3 w-3 rounded-full`} style={{backgroundColor: this.props.options.state.options.processingColor}}/>
174-
<div className={` options-dropdown transition-all duration-200 ease-in-out dark:bg-darkGray dark:border-lightDark absolute bg-white p-2 rounded-md border-2 top-[100%] space-y-1 ${showProcessingColor ? "scale-100" : "scale-0 -translate-y-[7em]"}`}>
175-
{CONSTANTS.PROCESSING.map((color) => (
176-
<div
177-
key={color}
178-
style={{backgroundColor: color}}
179-
className={`w-8 h-8 rounded-md hover:scale-[1.15] transition-all duration-200 ease-in-out ${color === 'white' && "border-2 border-gray-300"}`}
180-
onClick={() => {
181-
this.props.options.setState(prev => ({options: {...prev.options, processingColor: color, }}));
182-
this.setState({showProcessingColor: !showProcessingColor})
183-
}
184-
}/>
185-
))}
186-
</div>
187-
<p className={`shadow-lg bg-white inline z-10 absolute top-[100%] p-2 rounded-md hidden peer-hover:block tool-tip-options text-gray-600 whitespace-nowrap font-semibold`}>Processing bars color</p>
188-
</div>
189-
190-
191-
<div className={`${algorithm === 'Selection' ? 'block' : 'hidden'} flex flex-col items-center relative space-y-2 cursor-pointer`}>
192-
<div className="p-2 hover:bg-gray-200 showMinBarColor peer rounded-md" onClick={() => this.setState({showMinBarColor: !showMinBarColor})}>
193-
<Key className="scale-[1.2]"/>
194-
</div>
195-
<div className={`h-3 w-3 rounded-full`} style={{backgroundColor: this.props.options.state.options.currentMinBarColor}}/>
196-
<div className={`options-dropdown transition-all duration-200 ease-in-out dark:bg-darkGray dark:border-lightDark absolute bg-white p-2 rounded-md border-2 top-[100%] space-y-1 ${showMinBarColor ? "scale-100" : "scale-0 -translate-y-[7em]"}`}>
197-
{CONSTANTS.CURRENT_MIN.map((color) => (
198-
<div
199-
key={color}
200-
style={{backgroundColor: color}}
201-
className={`w-8 h-8 rounded-md hover:scale-[1.15] transition-all duration-200 ease-in-out ${color === 'white' && "border-2 border-gray-300"}`}
202-
onClick={() => {
203-
this.props.options.setState(prev => ({options: {...prev.options, currentMinBarColor: color, }}));
204-
this.setState({showMinBarColor: !showMinBarColor})
205-
}
206-
}/>
207-
))}
208-
</div>
209-
<p className={`shadow-lg bg-white inline z-10 absolute top-[100%] p-2 rounded-md hidden peer-hover:block tool-tip-options text-gray-600 whitespace-nowrap font-semibold`}>Current bar color</p>
210-
</div>
211-
212-
213-
<div className="flex flex-col items-center relative space-y-2 cursor-pointer">
214-
<div className="p-2 hover:bg-gray-200 showDelay peer rounded-md" onClick={() => this.setState({showDelay: !showDelay})}>
215-
<Speed className="scale-[1.2]"/>
216-
</div>
217-
<p className="font-semibold text-gray-500">{this.props.options.state.options?.delay}ms</p>
218-
<div className={`absolute transition-all duration-200 ease-in-out bg-white p-2 dark:bg-darkGray dark:border-lightDark rounded-md border-2 top-[100%] space-y-1 ${showDelay ? "scale-100" : "scale-0 -translate-y-[1.9em]"}`}>
219-
<div className="flex dark:bg-darkGray dark:border-lightDark flex-col items-center justify-center">
220-
<SlideBar mainCanvas={this.props.options}/>
221-
<p className="themeFont dark:text-white">{this.props.options.state.options?.delay}</p>
222-
</div>
223-
</div>
224-
<p className={`shadow-lg bg-white inline z-10 absolute top-[100%] p-2 rounded-md hidden peer-hover:block tool-tip-options text-gray-600 whitespace-nowrap font-semibold`}>Animation Delay</p>
225-
</div>
226-
227-
228-
229-
<div className={`${(algorithm === 'Selection' || algorithm === 'Radix') ? 'block' : 'hidden'} flex flex-col items-center relative space-y-2 cursor-pointer`}>
230-
<div className={`p-2 hover:bg-gray-200 peer rounded-md ${this.props.options.state.options.skipJ && "bg-gray-200"}`} onClick={() => {
231-
this.props.options.setState(prev => ({options: {...prev.options, skipJ: !this.props.options.state.options.skipJ}}))
232-
233-
}}>
234-
<Runner className="scale-[1.2]"/>
235-
</div>
236-
<p className="font-semibold text-gray-500">{this.props.options.state.options.skipJ ? "ON" : "OFF"}</p>
237-
<p className={`shadow-lg bg-white inline z-10 absolute top-[100%] p-2 rounded-md hidden peer-hover:block tool-tip-options text-gray-600 whitespace-nowrap font-semibold`}>Faster Animation</p>
238-
</div> */}
239-
240-
</div>
241-
82+
</div>
24283
</div>
24384
)
24485
}

‎src/components/Page/partial/Navbar/ThemeToggle.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const ThemeToggle = () => {
2020
}, [night])
2121

2222
return (
23-
<div className={`${night ? 'bg-gradient-to-r from-gray-900 to-gray-800' : "bg-gradient-to-r from-gray-300 to-white"} w-[3.5em] h-[36px] bg-white rounded-full relative border-[2px] border-gray-400`}
23+
<div className={`${night ? 'bg-gradient-to-r from-gray-900 to-gray-800' : "bg-gradient-to-r from-gray-300 to-white"} w-[3.5em] h-[36px] bg-white rounded-full relative border-[2px] border-gray-400 mr-[1em]`}
2424
onClick={() => {
2525
setNightMode(!night)
2626
localStorage.setItem("dark", JSON.stringify(!night));

‎src/components/Page/partial/Navbar/navbar.css‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@
2727
}
2828

2929
.nav-menu {
30-
display: grid;
31-
grid-template-columns: repeat(5, auto);
32-
grid-gap: 10px;
30+
display: flex;
3331
list-style: none;
3432
text-align: center;
35-
width: 70vw;
33+
flex: 1;
3634
justify-content: end;
37-
margin-right: 2rem;
35+
margin-right: 5em;
3836
}
3937

4038
.nav-item {
@@ -70,10 +68,11 @@
7068
display: none;
7169
}
7270

73-
@media screen and (max-width: 960px) {
71+
@media screen and (max-width: 970px) {
7472

7573
.navbar {
7674
height: 60px;
75+
justify-content: space-between;
7776
}
7877

7978
.NavbarItems {

0 commit comments

Comments
 (0)