This commit is contained in:
YasinOnm08 2024-10-07 11:16:51 +02:00
parent 2e67f911c1
commit 0f610d3c18
11 changed files with 408 additions and 288 deletions

View file

@ -20,23 +20,25 @@ const InputOutputBackend: React.FC = () => {
const [timeZone, setTimeZone] = useState<string>("GMT");
const [dateFormat, setDateFormat] = useState<string>("DD-MM-YYYY");
const [messages, setMessages] = useState<Message[]>([]);
const [myBoolean, setMyBoolean] = useState<boolean>(() => localStorage.getItem('myBoolean') === 'true') || false;
const [myBoolean, setMyBoolean] = useState<boolean>(false);
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_create")
apiURL.hostname = window.location.hostname;
// Fetch local storage values and update state on component mount
useEffect(() => {
setPreferredCurrency(localStorage.getItem("preferredCurrency") || "USD");
setPreferredLanguage(localStorage.getItem("preferredLanguage") || "english");
setTimeFormat(localStorage.getItem("timeFormat") || "24-hour");
setPreferredMeasurement(localStorage.getItem("preferredMeasurement") || "metric");
setTimeZone(localStorage.getItem("timeZone") || "GMT");
setDateFormat(localStorage.getItem("dateFormat") || "DD-MM-YYYY");
setMyBoolean(localStorage.getItem('myBoolean') === 'true');
}, []);
if (typeof window !== 'undefined') {
apiURL.hostname = window.location.hostname;
} else {
apiURL.hostname = "localhost"
}
// Update messages when any of the settings change
useEffect(() => {
if (typeof localStorage !== 'undefined') {
setPreferredCurrency(localStorage.getItem("preferredCurrency") || "USD");
setPreferredLanguage(localStorage.getItem("preferredLanguage") || "english");
setTimeFormat(localStorage.getItem("timeFormat") || "24-hour");
setPreferredMeasurement(localStorage.getItem("preferredMeasurement") || "metric");
setTimeZone(localStorage.getItem("timeZone") || "GMT");
setDateFormat(localStorage.getItem("dateFormat") || "DD-MM-YYYY");
setMyBoolean(localStorage.getItem('myBoolean') === 'true');
}
const measurementString = (preferredMeasurement == "Metric")
? "All measurements follow the metric system. Refuse to use any other measurement system."
: "All measurements follow the imperial system. Refuse to use any other measurement system.";
@ -113,7 +115,12 @@ const InputOutputBackend: React.FC = () => {
if (!getWorkerRef.current) {
getWorkerRef.current = new Worker(new URL("./threads/GetWorker.ts", import.meta.url))
const windowname = window.location.hostname
let windowname = "localhost"
if (typeof window !== 'undefined') {
windowname = window.location.hostname
} else {
windowname = "localhost"
}
getWorkerRef.current.postMessage({ action: "start", access_token: accessToken, windowname })
@ -169,12 +176,15 @@ const InputOutputBackend: React.FC = () => {
setInputDisabled(true)
if (postWorkerRef.current) {
addMessage("user", inputValue)
const type = localStorage.getItem('type')
let type:string = "local"
let api_key: string = ""
if (type != null && type != 'local') {
const try_key = localStorage.getItem(type)
if (try_key) {
api_key = try_key
if (typeof localStorage !== 'undefined') {
type = localStorage.getItem('type') || "local"
if (type != null && type != 'local') {
const try_key = localStorage.getItem(type)
if (try_key) {
api_key = try_key
}
}
}
setInputMessage("")