-
Notifications
You must be signed in to change notification settings - Fork 32
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
Implemented Notification from the mantine functionality for Config.tsx and Urloader.tsx #121
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -4,6 +4,8 @@ import './UrlLoader.css'; | |||
import { useEffect, useState } from 'react'; | |||
import { apiCall } from '../../../utils/api'; | |||
import { useForm } from '@mantine/form'; | |||
import { Notifications } from '@mantine/notifications'; | |||
import { check } from 'prettier'; |
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 seems not to be 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.
lgtm awesome work.
Can you also refresh the Uploaded.tsx
component, if someone indexed a Website? Basically like you did with the callback function for the Dropzone component.
In the App.tsx
there's also some logic which either shows the Config page or the Welcome to AIxplora.
This is currently not working I believe it has to do something with state change, please doublecheck here.
Again: Thanks a lot for working on this!
I reviewed again, looks good to me but something with the localstorage doesn't work properly. If I refresh my config is gone again. Testing it via home <-> config page |
Do you want the App to keep the same configuration after reloading it? |
Hi, yes, once a user has set a configuration it should always fallback on it. In the backend it's implemented like this, so it references the last row of the table..
Otherwise a user had to set a new config on every start-up. |
apiCall('/files/website', 'POST', payload) | ||
.then((response) => { | ||
console.log(response.data); | ||
window.location.reload(); | ||
|
||
Notifications.show({ | ||
title: 'URL Upload Successful', | ||
message: 'The URL was successfully uploaded.', | ||
color: 'green' | ||
}); | ||
|
||
// passing the website to the Upload.tsx component | ||
onFilesUploaded([payload.website]); | ||
}) |
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 add a check here, if the status code f.e. is 500 it still will "upload successful".
@@ -37,10 +38,9 @@ function saveConfig(OPENAI_API_KEY: string, model: string, embeddingsmodel: stri | |||
// console.log('Error fetching config:', error); | |||
// return false; | |||
// }); | |||
// } | |||
// }console.log("saveconfig"); | |||
return apiCall('/config', 'POST', payload).then((response) => { |
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 you say we should extend the apiCall
function with a boolean to deactivate the Notification? As of now a user gets the Endpoint error + the configerror.
useEffect(() => { | ||
// Attempt to retrieve the configuration data from localStorage | ||
const savedConfig = JSON.parse(localStorage.getItem('config') || '{}'); | ||
|
||
if (Object.keys(savedConfig).length > 0) { | ||
// Configuration data exists in localStorage, set it as valid | ||
setConfigValid(true); | ||
} else { | ||
// Configuration data does not exist in localStorage, set it as invalid | ||
setConfigValid(false); | ||
} | ||
}, []); | ||
|
||
if (isConfigValid === undefined) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
|
||
return isConfigValid ? <Start /> : <Config setConfigValid={setConfigValid} />; | ||
} |
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.
Hi there, it works like expected. Very good job!
I would like to have another oppinion on the behavior. So for now, if I delete the database, the API key is still stored.
I mentioned that in this case an API call would make sense every time the Home page is opened initally.
Would you be open to discussing whether to adapt this approach? Should we implement it additionally or go with that approach? So we have 1 single souce of truth basically -> which is the db.
Same for the Config page btw :)
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.
Great work, I left some comments with questions :)
Hi, that makes sense. I'll start working on it :) |
frontend/src/renderer/utils/api.tsx
Outdated
@@ -14,7 +14,7 @@ const selectBaseUrl = () => { | |||
} | |||
}; | |||
|
|||
export const apiCall = async (endpoint, method, data) => { | |||
export const apiCall = async (endpoint, method, data, disableNotification = 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.
the default parameter should either be true
or it should be if(disabledNotification)
, otherwise we won't have any Notifcation.
// Make an API call to fetch the configuration data only on the first load | ||
if (!dataLoaded) { | ||
apiCall('/config', 'GET', null, true) | ||
.then((response) => { | ||
const fetchedConfig = response.data; | ||
// Set the form values based on the retrieved data | ||
form.setValues({ | ||
OPENAI_API_KEY: fetchedConfig.openai_api_key || '', | ||
model: fetchedConfig.model || '', | ||
embeddingsmodel: fetchedConfig.embeddings_model || '', | ||
}); | ||
// Save to localStorage for future loads | ||
localStorage.setItem('config', JSON.stringify(fetchedConfig)); | ||
// Set the dataLoaded flag to true to prevent future API calls | ||
setDataLoaded(true); | ||
}) | ||
.catch((error) => { | ||
console.log('Error fetching config:', error); | ||
// Handle the error as needed, maybe show a notification or take other actions | ||
}); | ||
} | ||
|
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 would make the first load
everytime one goes back to Config component - is the if dataLoaded
then even needed? as the state will be gone if we change the component.
frontend/src/renderer/App.tsx
Outdated
@@ -41,12 +93,11 @@ export default function Hello() { | |||
<Router> | |||
<HeaderResponsive links={randomLinks}/> | |||
<Routes> | |||
<Route path="/" element={<Home />}/> | |||
<Route path="/" element={isConfigValid ? <GettingStarted/> : <Config/>}/> |
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 am not sure if this will work, if the API returns JSON
instead of the true
and false which is wanted in the JSX condition.
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 think I found some little mistakes, other than that nice work. I like the additional status code implementation you did even without questioning. Really awesome :)
hi @auksesir please ping me if you checked my review and changed if possible so I'll have another look. thx |
Hi @grumpyp, I've changed it. Let me know if it's working correctly. |
Hi, I am sorry but it's not working like expected: So if there's no Config in the DB, it should render the |
Hi @grumpyp. It should work as expected now. I tried testing it one last time but I started getting this error: Access to XMLHttpRequest at 'http://localhost:8000/config/' (redirected from 'http://localhost:8000/config') from origin 'http://localhost:1212' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. It started occurring even though I had not changed anything. Do you have any idea what could it be? I was trying to figure it out but nothing worked. |
Hi, sorry, but it doesn't work. Please make also sure to merge the current |
I made the code to empty the text input box and uncheck the checkbox after submitting the URL. I also made selected values stay as placeholders in Config.tsx.