Skip to content

Commit

Permalink
work on error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
targoninc-alex committed Jun 1, 2024
1 parent c9d4155 commit 3eeb372
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 32 deletions.
8 changes: 4 additions & 4 deletions ui/actions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const testImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIA
export function toggleAllowlist(instances, instance) {
Api.toggleAllowlist(instance.id).then(res => {
if (res.status === 200) {
toast("Allowlist toggled", "positive");
toast("Allowlist toggled", "success");
instances.value = instances.value.map(i => {
if (i.id === instance.id) {
return {
Expand All @@ -90,15 +90,15 @@ export function toggleAllowlist(instances, instance) {
return i;
});
} else {
toast("Failed to toggle allowlist", "negative");
toast("Failed to toggle allowlist: " + res.data.error, "error");
}
});
}

export function toggleInstanceEnabled(instances, instance) {
Api.toggleEnabled(instance.id).then(res => {
if (res.status === 200) {
toast("Instance enabled toggled", "positive");
toast("Instance enabled toggled", "success");
instances.value = instances.value.map(i => {
if (i.id === instance.id) {
return {
Expand All @@ -109,7 +109,7 @@ export function toggleInstanceEnabled(instances, instance) {
return i;
});
} else {
toast("Failed to toggle instance enabled", "negative");
toast("Failed to toggle instance enabled: " + res.data.error, "error");
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions ui/api/Hooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Hooks {
Hooks.runActiveChannel(channel.id);
}
} else {
toast("Failed to fetch channels", "negative");
toast("Failed to fetch channels: " + res.data.error, "negative");
store().setSignalValue('channels', []);
}
});
Expand All @@ -40,7 +40,7 @@ export class Hooks {
if (res.status === 200) {
setMessages(channel, res.data);
} else {
toast("Failed to fetch messages", "negative");
toast("Failed to fetch messages: " + res.data.error, "negative");
}
});
}
Expand Down
28 changes: 22 additions & 6 deletions ui/api/Popups.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class Popups {

Api.search(query).then((res) => {
if (res.status !== 200) {
toast("Failed to search for users", "error");
toast("Failed to search for users: " + res.data.error, "error");
return;
}
userSearchResults.value = res.data.filter(user => {
Expand All @@ -39,7 +39,7 @@ export class Popups {
return CommonTemplates.chatWithButton(result.username, () => {
Api.createDirect(result.id).then((res) => {
if (res.status !== 200) {
toast("Failed to create DM", "error");
toast("Failed to create DM: " + res.data.error, "error");
removePopups();
return;
}
Expand Down Expand Up @@ -69,7 +69,7 @@ export class Popups {

Api.search(query).then((res) => {
if (res.status !== 200) {
toast("Failed to search for users", "error");
toast("Failed to search for users: " + res.data.error, "error");
return;
}
userSearchResults.value = res.data.filter(user => {
Expand All @@ -80,7 +80,7 @@ export class Popups {
return CommonTemplates.addUserButton(result.username, () => {
Api.addBridgedUser(result.id, instance.id).then((res) => {
if (res.status !== 200) {
toast("Failed to add user", "error");
toast("Failed to add user: " + res.data.error, "error");
removePopups();
return;
}
Expand All @@ -96,7 +96,7 @@ export class Popups {
popup(PopupComponents.confirmPopup("Are you sure you want to delete this user?", () => {
Api.deleteUser(user.id).then((res) => {
if (res.status !== 200) {
toast("Failed to delete user", "error");
toast("Failed to delete user: " + res.data.error, "error");
removePopups();
return;
}
Expand All @@ -123,12 +123,28 @@ export class Popups {
Api.changePassword(oldPassword, newPassword).then((res) => {
if (res.status !== 200) {
errorState.value = res.data.error;
toast("Failed to update password", "error");
toast("Failed to update password: " + res.data.error, "error");
return;
}
toast("Password updated", "success");
removePopups();
});
}));
}

static deleteAccount(user) {
popup(PopupComponents.confirmPopup("Are you sure you want to delete your account?", () => {
Api.deleteUser(user.value.id).then((res) => {
if (res.status !== 200) {
toast("Failed to delete user: " + res.data.error, "error");
removePopups();
return;
}
toast("User deleted", "success");
window.router.navigate("/logout");
});
}, () => {
removePopups();
}, "Delete account", "Yes", "No", "delete", "close"));
}
}
5 changes: 5 additions & 0 deletions ui/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ button.positive, input.positive, textarea.positive, select.positive {
color: var(--green);
}

button.negative, input.negative, textarea.negative, select.negative {
border: var(--input-border-width) solid var(--red);
color: var(--red);
}

button.double, input.double, textarea.double, select.double {
padding: var(--input-padding-v) calc(var(--input-padding-h) * 2);
}
Expand Down
4 changes: 2 additions & 2 deletions ui/components/pages/login.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ export class LoginComponent {
loading.value = false;
if (res.status !== 200) {
actionError.value = res.data.error;
toast("Login failed", "negative");
toast("Login failed: " + res.data.error, "error");
} else {
actionError.value = null;
toast("Login successful", "positive");
toast("Login successful", "success");
window.router.navigate("chat");
}
});
Expand Down
2 changes: 1 addition & 1 deletion ui/components/pages/logout.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class LogoutComponent {
if (res.status === 200) {
window.router.navigate('login');
} else {
toast("Failed to log out", "negative");
toast("Failed to log out: " + res.data.error, "error");
}
});

Expand Down
9 changes: 6 additions & 3 deletions ui/components/pages/profile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ export class ProfileComponent {
const updateUser = () => {
Api.updateUser(username.value, displayname.value, description.value).then((res) => {
if (res.status !== 200) {
toast("Failed to update user info", "error");
toast("Failed to update user info: " + res.data.error, "error");
return;
}
toast("User info updated", "success");
Api.getUser().then((res) => {
if (res.status !== 200) {
toast("Failed to get user info", "error");
toast("Failed to get user info: " + res.data.error, "error");
return;
}
store().setSignalValue('user', res.data.user);
Expand Down Expand Up @@ -134,7 +134,10 @@ export class ProfileComponent {
.children(
CommonTemplates.buttonWithIcon("password", "Change password", () => {
Popups.updatePassword(user);
})
}),
CommonTemplates.buttonWithIcon("delete", "Delete account", () => {
Popups.deleteAccount(user);
}, ["negative"])
).build();
}
}
4 changes: 2 additions & 2 deletions ui/components/pages/register.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ export class RegisterComponent {
Api.register(username.value, password.value).then((res) => {
loading.value = false;
if (res.status === 200) {
toast("Registration successful", "positive");
toast("Registration successful", "success");
window.router.navigate("chat");
} else {
toast("Registration failed: " + res.data.error, "negative");
toast("Registration failed: " + res.data.error, "error");
}
}).catch(() => {
loading.value = false;
Expand Down
16 changes: 8 additions & 8 deletions ui/components/pages/settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class SettingsComponent {
if (res.status === 200) {
bridgedInstances.value = res.data;
} else {
toast("Failed to fetch bridged instances", "negative");
toast("Failed to fetch bridged instances: " + res.data.error, "error");
}
});
}
Expand Down Expand Up @@ -203,17 +203,17 @@ export class SettingsComponent {
CommonTemplates.buttonWithIcon("close", "Cancel" , onclose),
CommonTemplates.buttonWithIcon("add_link", "Add", () => {
if (!url.value) {
toast("URL is required", "negative");
toast("URL is required", "error");
return;
}

Api.addInstance(url.value, useAllowlist.value, enabled.value).then(res => {
if (res.status === 200) {
toast("Bridged instance added", "positive");
toast("Bridged instance added", "success");
bridgedInstances.value = [...bridgedInstances.value, res.data];
onclose();
} else {
toast("Failed to add bridged instance", "negative");
toast("Failed to add bridged instance: " + res.data.error, "error");
}
});
}),
Expand Down Expand Up @@ -244,10 +244,10 @@ export class SettingsComponent {
ifjs(hasRemovePermission, CommonTemplates.buttonWithIcon("delete", "Remove", () => {
Api.removeInstance(instance.id).then(res => {
if (res.status === 200) {
toast("Bridged instance removed", "positive");
toast("Bridged instance removed", "success");
instances.value = instances.value.filter(i => i.id !== instance.id);
} else {
toast("Failed to remove bridged instance", "negative");
toast("Failed to remove bridged instance: " + res.data.error, "error");
}
});
})),
Expand All @@ -267,7 +267,7 @@ export class SettingsComponent {
if (res.status === 200) {
users.value = res.data.users;
} else {
toast("Failed to fetch users", "negative");
toast("Failed to fetch users: " + res.data.error, "error");
}
});
}
Expand Down Expand Up @@ -370,7 +370,7 @@ export class SettingsComponent {
allowList.value = allowList.value.filter(u => u.id !== user.id);
toast("User removed", "success");
} else {
toast("Failed to remove user", "error");
toast("Failed to remove user: " + res.data.error, "error");
}
});
});
Expand Down
7 changes: 3 additions & 4 deletions ui/live/LiveInstance.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ export class LiveInstance {
let connectSid = await this.getConnectSid();
if (!connectSid) {
console.error("No connect.sid cookie found");
toast("Could not connect to live server. You have to refresh the page to get any updates.");
return;
}
const res = await Api.url();
if (res.status !== 200) {
console.error("Failed to get live server URL");
toast("Could not connect to live server. You have to refresh the page to get any updates.");
toast("Could not get live server URL: " + res.data.error, "error");
return;
}
this.server = new WebSocket(encodeURI(`${res.data}?cid=${connectSid}`));
Expand All @@ -42,7 +40,8 @@ export class LiveInstance {
this.server.onclose = () => {
this.onStop();
setTimeout(() => {
console.log("Reconnecting to live server...");
console.log("Lost connection to live server, reconnecting...");
toast("Lost connection to live server, reconnecting...", "info");
this.start();
}, 1000);
};
Expand Down

0 comments on commit 3eeb372

Please sign in to comment.