replace redux with zustand

This commit is contained in:
2025-07-25 01:03:11 +02:00
parent 5448285211
commit 3bcd2e16a2
30 changed files with 510 additions and 534 deletions

View File

@@ -1,55 +1,55 @@
class Flatastic {
private apikey: string;
private apikey: string;
constructor(apikey: string) {
this.apikey = apikey;
}
constructor(apikey: string) {
this.apikey = apikey;
}
async request(url: string, option: any, cb: (info: any) => void) {
const headers = {
"accept": "application/json, text/plain, */*",
"accept-language": "de-CH,de;q=0.9,en-US;q=0.8,en-CH;q=0.7,en;q=0.6,ar-JO;q=0.5,ar;q=0.4,de-DE;q=0.3",
// "cache-control": "no-cache",
// "pragma": "no-cache",
// "sec-fetch-dest": "empty",
// "sec-fetch-mode": "cors",
// "sec-fetch-site": "same-site",
"x-api-key": this.apikey,
"x-api-version": "2.0.0",
"x-client-version": "2.3.20"
};
try {
const response = await fetch(url, {
method: 'GET',
headers: headers
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const info = await response.json();
cb(info);
} catch (error) {
let message = 'Unknown error';
if (error instanceof Error) {
message = error.message;
}
cb({ error: message });
}
}
async request(url: string, option: any) {
const headers = {
accept: "application/json, text/plain, */*",
"accept-language":
"de-CH,de;q=0.9,en-US;q=0.8,en-CH;q=0.7,en;q=0.6,ar-JO;q=0.5,ar;q=0.4,de-DE;q=0.3",
// "cache-control": "no-cache",
// "pragma": "no-cache",
// "sec-fetch-dest": "empty",
// "sec-fetch-mode": "cors",
// "sec-fetch-site": "same-site",
"x-api-key": this.apikey,
"x-api-version": "2.0.0",
"x-client-version": "2.3.20",
};
const response = await fetch(url, {
...option,
headers: {
...headers,
...option.headers,
},
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
}
getShoppingList(callback: (info: any) => void) {
this.request('https://api.flatastic-app.com/index.php/api/shoppinglist', {}, callback);
}
getShoppingList() {
return this.request(
"https://api.flatastic-app.com/index.php/api/shoppinglist",
{},
);
}
getTaskList(callback: (info: any) => void) {
this.request('https://api.flatastic-app.com/index.php/api/chores', {}, callback);
}
getTaskList() {
return this.request(
"https://api.flatastic-app.com/index.php/api/chores",
{},
);
}
getInformation(callback: (info: any) => void) {
this.request('https://api.flatastic-app.com/index.php/api/wg', {}, callback);
}
getInformation() {
this.request("https://api.flatastic-app.com/index.php/api/wg", {});
}
}
export { Flatastic };
export default Flatastic;
export default Flatastic;