-
Notifications
You must be signed in to change notification settings - Fork 35
Onboarding Project: Maxwill #48
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
base: master
Are you sure you want to change the base?
Conversation
…Removed my global search function and inserted functionality to only search by id.
…t. Updated pagination so it can work with the adjustDisplayedRecords function.
…of records displayed. It depends on the screen height and the page.
…th page rows. App doesn't crash when resizing too low.
…rs. Finished with all the functionalities.
app.ts
Outdated
| let lastPage = firstPage + 9 | ||
| let currentFromID = 1; | ||
| let currentToID = 20; | ||
| let difference = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to only make use of 2 global variables and give them a type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to give the Type if you set the variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not have any global variables.
And you only have to set the type if they where class variables or if they were normal variables that were not assigned a value in the same line. And these variables are neither.
app.ts
Outdated
| let difference = 0 | ||
|
|
||
|
|
||
| // This function will handle retrieving the records from the api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for so much space between the code, we all love each other here
app.ts
Outdated
| async function getColumns(): Promise<Array<string>> { | ||
| try { | ||
| const data = await fetch(`${api}columns`); | ||
| const columns: Array<string> = await data.json(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const columns: Array<string> = await data.json(); | |
| const columns: string[]= JSON.parse(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always make use of .json() instead of JSON.parse() when able. But the string[] is still the correct comment.
app.ts
Outdated
| return columns; | ||
|
|
||
| } catch (error) { | ||
| console.error(error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to console log
app.ts
Outdated
| firstPage = lastPage - 9; | ||
| $(".pagination").empty(); | ||
| await pageNumbers(firstPage, lastPage); | ||
| // isFunctionRunning = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you mean to comment this out, looks like it could break if you press prev and then next
app.ts
Outdated
| } | ||
| if (firstPage === 1) { | ||
| $(".prev").css({ display: "none" }); | ||
| } else $(".prev").css({ display: "block" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no {} for else?
DevinFledermaus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of you functions make use of the same variables that you keep having to set, maybe get them all in a central place. will make lots of your functions way smaller
apiManager.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't add your .js files to this PR.
apiManager.js.map
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't add your .js.map files to this PR.
| private mainUrl: string; | ||
| constructor(mainUrl: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave an empty line between your class variables and constructor
apiManager.ts
Outdated
| return fetch(mainUrl) | ||
| .then(res => res.text()) | ||
| .then(data => JSON.parse(data)) | ||
| .catch((err) => { | ||
| throw err | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to check if your fetch was successful, as that does not get catch'd by the .catch.
Please use res.json() instead of res.text() and then JSON.parse(). (I know someone else asked you to do it this way, and I apologize that you have to revert your code now again, but this is the right way)
Also, please add a ; to the throw and at the end.
apiManager.ts
Outdated
| return fetch(mainUrl) | ||
| .then(res => res.text()) | ||
| .then(data => JSON.parse(data)) | ||
| .catch((err) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either remove the () around err or specify a type
style.css
Outdated
| text-overflow: ellipsis; | ||
| white-space: nowrap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
style.css
Outdated
| padding-left: 10px; | ||
| } | ||
|
|
||
| input:focus{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a space before the {
style.css
Outdated
| margin: 3px; | ||
| background-color: #ffffff36; | ||
| box-shadow: inset 0px 0px 20px -10px rgba(255, 255, 255, 0.438); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this one empty line.
| .header { | ||
| height: 5vh; | ||
| } | ||
| .heading { | ||
| height: 5vh; | ||
| } | ||
| .table-container { | ||
| height: 80vh; | ||
| } | ||
| .wrapper { | ||
| height: 10vh; | ||
| display: flex; | ||
| align-items: center; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave an empty line between classes.
style.css
Outdated
| @keyframes rot { | ||
| 100% { | ||
| transform: rotate(360deg); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this one empty line.
Deleted the js files
…s. Fixed bugs that poped up after changing starting id.
anzelIMQS
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave a very partial review. Will get back to you if necessary.
app.ts
Outdated
| } | ||
| }) | ||
| .catch(error => { | ||
| throw new Error(`Failed to retrieve columns: ${error}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| throw new Error(`Failed to retrieve columns: ${error}`) | |
| throw new Error(`Failed to retrieve columns: ${error}`); |
Missing semi-colon
app.ts
Outdated
| } | ||
| else if (this.currentPage === 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | |
| else if (this.currentPage === 1) { | |
| } else if (this.currentPage === 1) { |
On the same line please
app.ts
Outdated
| this.paginationEnd = pageEnd; | ||
| } | ||
| } else { | ||
| throw new Error("Please provide a valid integer.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| throw new Error("Please provide a valid integer.") | |
| throw new Error("Please provide a valid integer."); |
app.ts
Outdated
| return this.apiManager.getRecordCount() | ||
| .then(count => { | ||
| let inputNumber = this.input(); | ||
| let inputNumberInt: any = parseInt(inputNumber); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it always a number being returned?
apiManager.ts
Outdated
|
|
||
| /** Retrieves the number of records there are */ | ||
| getRecordCount(): Promise<number> { | ||
| let test = `${this.mainUrl}recordCount` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove stray
apiManager.ts
Outdated
| private fetchJson(mainUrl: string): Promise<any> { | ||
| return fetch(mainUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private fetchJson(mainUrl: string): Promise<any> { | |
| return fetch(mainUrl) | |
| private fetchJson(url: string): Promise<any> { | |
| return fetch(url) |
Feels incorrect calling it the main one since in this scope it is only one and can be anything. Main or not.
| class ApiManager { | ||
| private mainUrl: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space inbetween.
| } | ||
| $("#records-table-body").append(`</tr>`); | ||
| } | ||
| this.isFunctionRunning = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know that there is a chance that your request doesn't get this far since it broke somewhere above. That would mean your isFunctionRunning will forever be true and causing no new requests to come in for showRecords.
Ideally, make use of the finally-block instead. It will always run irrespective of the request failing.
app.ts
Outdated
| let screenHeight = <number>($(window).height()); | ||
| if (screenHeight < 68) { | ||
| screenHeight = 68; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eish, then why not have a min-height prop on your window?
anzelIMQS
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to see how you can make use of more shared code. I still see some repetitiveness. Try to reduce it by seeing a pattern in your code.
app.ts
Outdated
| } | ||
|
|
||
| /** Fetching the records and rendering it on the DOM in the table*/ | ||
| showRecords(fromID: number, toID: number): Promise<any> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| showRecords(fromID: number, toID: number): Promise<any> { | |
| showRecords(fromID: number, toID: number): Promise<void> { |
Change back to void
app.ts
Outdated
|
|
||
| constructor() { | ||
| this.isFunctionRunning = false; | ||
| this.apiManager = new ApiManager("http://localhost:2050/"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| this.apiManager = new ApiManager("http://localhost:2050/"); | |
| this.apiManager = new ApiManager("http://localhost:2050"); |
apiManager.ts
Outdated
|
|
||
| /** Retrieves records from the api */ | ||
| getRecords(fromID: number, toID: number): Promise<string[][]> { | ||
| return this.fetchJson(`${this.mainUrl}records?from=${fromID}&to=${toID}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return this.fetchJson(`${this.mainUrl}records?from=${fromID}&to=${toID}`); | |
| return this.fetchJson(`${this.mainUrl}/records?from=${fromID}&to=${toID}`); |
apiManager.ts
Outdated
|
|
||
| /** Retrieves columns from the api */ | ||
| getColumns(): Promise<string[]> { | ||
| return this.fetchJson(`${this.mainUrl}columns`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return this.fetchJson(`${this.mainUrl}columns`); | |
| return this.fetchJson(`${this.mainUrl}/columns`); |
apiManager.ts
Outdated
|
|
||
| /** Retrieves the number of records there are */ | ||
| getRecordCount(): Promise<number> { | ||
| return this.fetchJson(`${this.mainUrl}recordCount`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return this.fetchJson(`${this.mainUrl}recordCount`); | |
| return this.fetchJson(`${this.mainUrl}/recordCount`); |
app.ts
Outdated
| $(".prev").on("click", () => { | ||
| this.paginationEnd = this.paginationStart - 1; | ||
| this.paginationStart = this.paginationEnd - 9; | ||
| $(".pagination").empty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are already emptying in pageNumbers.
Please remove.
app.ts
Outdated
| start = end - maxRecords; | ||
| } | ||
| this.currentPage = Math.floor(end / maxRecords); | ||
| if (inputNumberInt < 1000000 && inputNumberInt > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (inputNumberInt < 1000000 && inputNumberInt > 0) { | |
| if (inputNumberInt < 1000000 && inputNumberInt > 0) { |
You have your count. You went all the way to fetch it, use it and not 1000000.
app.ts
Outdated
| /** Fetching the records and rendering it on the DOM in the table*/ | ||
| showRecords(fromID: number, toID: number): Promise<any> { | ||
| if (this.isFunctionRunning) { | ||
| return Promise.resolve(undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return Promise.resolve(undefined); | |
| return new Promise<void>(() => { }); |
app.ts
Outdated
| // element's attribute value. | ||
| $(".pagination").on("click", ".pagination-item", (event) => { | ||
| $('.pagination-item').prop('disabled', true); | ||
| return this.apiManager.getRecordCount() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to return here. Just run it.
| return this.apiManager.getRecordCount() | |
| this.apiManager.getRecordCount() |
app.ts
Outdated
| $(".pagination-item").removeClass("active"); | ||
| $(event.target).addClass("active"); | ||
| const self = this; | ||
| $(".pagination-item").each(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this can't be an arrow function?
app.ts
Outdated
| @@ -0,0 +1,408 @@ | |||
| class DataHandler { | |||
| /** It tracks if the showRecords function is running and would the value would be false if it's not. */ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /** It tracks if the showRecords function is running and would the value would be false if it's not. */ | |
| /** It tracks if the showRecords function is running. Is false if it's not. */ |
apiManager.ts
Outdated
| return fetch(url) | ||
| .then(res => { | ||
| if (res.ok) { | ||
| return res.json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing ;
apiManager.ts
Outdated
| if (res.ok) { | ||
| return res.json() | ||
| } else { | ||
| throw new Error(`HTTP error! Status: ${res.status}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing ;
| getRecordCount(): Promise<number> { | ||
| return this.fetchJson(`${this.mainUrl}/recordCount`); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So /recordCount returns a number as text... not a json... this feels misleading. You should probably do a different fetch to handle this case.
app.ts
Outdated
| class DataHandler { | ||
| /** It tracks if the showRecords function is running and would the value would be false if it's not. */ | ||
| private isFunctionRunning: boolean; | ||
| /** This is an instance of the ApiManager class and passing a string when being used. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably mean that you provide the url to the server during initialization. The way you have it written here it sounds like every function on this class takes a string as a parameter.
app.ts
Outdated
| } | ||
| this.currentToID = this.currentFromID + maxRecords; | ||
| this.currentPage = newCurrentPage; | ||
| let originalID = ((this.currentPage * maxRecords) + (this.currentPage - 1)) - maxRecords; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please just change this to be
(this.currentPage - 1) * (maxRecords + 1)It just makes it a bit clearer that you are calculating the fromID of the previous page.
app.ts
Outdated
| this.currentFromID = (this.currentPage - 1) * maxRecords + 1; | ||
| } | ||
| if (this.currentFromID === 0) { | ||
| let divisor = screenHeight < 136 ? maxRecords : maxRecords - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this hard coded value... 136. You definitely should not need it. Something must be wrong with the way you calculate maxRecords if this is necessary. Please remove it.
app.ts
Outdated
| clearTimeout(this.resizeTimer); | ||
| } | ||
| this.resizeTimer = setTimeout(() => { | ||
| return this.adjustDisplayedRecords() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning here does not make a lot of sens. setTimeout can't do anything with your promise.
FritzOnFire
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please only handle errors as late as possible
apiManager.ts
Outdated
| .then(res => { | ||
| if(res.ok) { | ||
| return res.text(); | ||
| } else { | ||
| throw new Error(`HTTP error? Status: ${res.status}`); | ||
| } | ||
| }) | ||
| .then (recordCount => { | ||
| return parseInt(recordCount); | ||
| }) | ||
| .catch(error => { | ||
| throw error; | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing some indentation.
apiManager.ts
Outdated
| getRecordCount(): Promise<number> { | ||
| return fetch(`${this.mainUrl}/recordCount`) | ||
| .then(res => { | ||
| if(res.ok) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if(res.ok) { | |
| if (res.ok) { |
apiManager.ts
Outdated
| throw new Error(`HTTP error? Status: ${res.status}`); | ||
| } | ||
| }) | ||
| .then (recordCount => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| .then (recordCount => { | |
| .then(recordCount => { |
apiManager.ts
Outdated
| } | ||
| }) | ||
| .then (recordCount => { | ||
| return parseInt(recordCount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would prefer it you checked for NaN here... but for this project it is probably fine.
app.ts
Outdated
| alert("An error occurred while trying to load the page. Please try again."); | ||
| throw error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
Why are you handling the error and then throwing the error anyway?
In this scenario there is no one to catch that error, which is bad, you should remove the throw.
app.ts
Outdated
| // on to the DOM. | ||
| $(".search-input").on("input", (e: any) => { | ||
| e.preventDefault(); | ||
| return this.getRecordCount() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure the handler function jquery is looking for does not return anything. Please remove the return.
app.ts
Outdated
| alert("An error occurred while trying to search. Please try again."); | ||
| throw error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment about handling the error and then throwing it anyway.
app.ts
Outdated
| alert("An error occurred while trying to search. Please try again."); | ||
| console.error("Failed when clicking on the results: ", error); | ||
| throw error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment about handling the error and then throwing it anyway.
app.ts
Outdated
| let endID: number; | ||
| let pageEnd: number; | ||
| let pageStart: number; | ||
| return this.getRecordCount() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure the handler function jquery is looking for does not return anything. Please remove the return.
app.ts
Outdated
| alert("An error occurred while trying to adjust the records. Please try again."); | ||
| throw error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
So you handle the error... and then you throw it anyway meaning that you have to handle it again later?
Please do not handle the error here, as who ever is calling adjustDisplayedRecords needs to know that we failed to adjustDisplayedRecords and they need to react accordingly.
app.ts
Outdated
| alert("An error occurred while trying to resize the window. Please try again."); | ||
| throw error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't throw here, there is no one left to catch it.
app.ts
Outdated
| }) | ||
| .catch(error => { | ||
| alert("An error occurred while trying to load your page. Please try again."); | ||
| throw new Error(`An error occurred when loading your page: ${error}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't throw here, there is no one left to catch it.
No description provided.