Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit/issues #23

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion backend/algorithms/sort/selectionSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ export const selectionSort = (unsortedArray: number[]): SelectionSortState => {
}
}

console.log(selectionSort([59,24, 3,6,7,2,8,49,32,20]))
//console.log(selectionSort([59,24, 3,6,7,2,8,49,32,20]))
3 changes: 2 additions & 1 deletion backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ import { selectionSort } from "./algorithms/sort/selectionSort";

app.post("/algorithms/sort/selection", (req, res) => {
const node = req.body.array;
console.log(node);
console.log('recieved rquest with:', node);
const algoOutput = selectionSort(node);
console.log('sending back sorted array:', algoOutput)
res.status(200).json(algoOutput);
});

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/app/components/sort/SelectionSort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ const SelectionSortAnimation: React.FC<SelectionSortAnimationProps> = ({
}, [animationIndex, isFinished, isRunning, stateHistory.length])

const handleSelectionSort = () => {
// ideally this will call the bubbleSort function, which will pass state for every position change
// ideally this will call the selectionSort function, which will pass state for every position change
// every position change will update the state of sortedArray, which should get reflected in a change in the divs
// you can add a slight time delay to ensure the visualisation flows
setIsRunning(true)
setAnimationIndex(0)
setIsRunning(true)

}

const handleReset = () => {
Expand Down
26 changes: 25 additions & 1 deletion frontend/src/utils/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,31 @@ import type {
TraversalStep
} from "@/types/typesSearch"

const SERVER_URL = 'https://algorithm-visualisations-express-production.up.railway.app'
const DEPLOYED_SERVER_URL = 'https://algorithm-visualisations-express-production.up.railway.app'

async function selectServerUrl() {
const hasNetworkConnection = await axios({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The network connectivity check is incorrect. hasNetworkConnection will always be truthy if the request doesn't throw an error. Consider using a try-catch block to handle errors and determine connectivity.

method: "GET",
url: `${DEPLOYED_SERVER_URL}`
})

console.log('can we access the remote server:', hasNetworkConnection)

if (hasNetworkConnection) {
return DEPLOYED_SERVER_URL
} else {
return 'http://localhost:8080'
}

}

// It's not clear to me why this promise is getting rejected?
const TEST_URL = selectServerUrl()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TEST_URL is assigned a promise instead of the resolved value. Use await selectServerUrl() to get the resolved value.

console.log('server', TEST_URL)

const SERVER_URL = 'http://localhost:8080'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SERVER_URL is hardcoded to 'http://localhost:8080'. Consider using the result from selectServerUrl() to dynamically set the server URL based on connectivity.




// Search: DFS -> take in a graph and a target and return a set
export async function getDFS(graph: Graph<string>, currentVertex: string, target: string|null): Promise<TraversalStep[] | null> {
Expand Down