fix: validation messages stay in the composer, toast only for send/hc errors
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
2dbb3fe23e
commit
dfe5101451
1 file changed
+29
-26
+29
-26
@@ -439,7 +439,7 @@ export default class Composer extends View {
|
||||
savedAt: Date.now(),
|
||||
});
|
||||
} catch (err) {
|
||||
this.notice(`Nie udało się zapisać szkicu: ${errorText(err)}`, "error");
|
||||
this.notice(`Nie udało się zapisać szkicu: ${errorText(err)}`, "problem");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -638,7 +638,7 @@ export default class Composer extends View {
|
||||
/** The panel opens over the composer; the caret of the field is remembered. */
|
||||
openPanel(tab = "history") {
|
||||
if (!this.target()) {
|
||||
this.notice("Wybierz agenta, aby otworzyć historię.", "error");
|
||||
this.notice("Wybierz agenta, aby otworzyć historię.", "problem");
|
||||
return;
|
||||
}
|
||||
this.closeMenu();
|
||||
@@ -710,7 +710,7 @@ export default class Composer extends View {
|
||||
try {
|
||||
run("layout.resize", { id: "composer", px });
|
||||
} catch (err) {
|
||||
this.notice(`Nie udało się zmienić wysokości composera: ${errorText(err)}`, "error");
|
||||
this.notice(`Nie udało się zmienić wysokości composera: ${errorText(err)}`, "problem");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -863,7 +863,7 @@ export default class Composer extends View {
|
||||
/** The star next to the field: the text of the field is a favourite, or no longer. */
|
||||
toggleCurrentFavorite(cx) {
|
||||
if (this.value.trim() === "") {
|
||||
this.notice("Wpisz tekst, aby dodać go do ulubionych.", "error", cx);
|
||||
this.notice("Wpisz tekst, aby dodać go do ulubionych.", "problem", cx);
|
||||
return;
|
||||
}
|
||||
this.toggleFavoriteText(this.value, cx);
|
||||
@@ -874,7 +874,7 @@ export default class Composer extends View {
|
||||
try {
|
||||
storage.saveFavorites(this.store, this.favorites);
|
||||
} catch (err) {
|
||||
this.notice(`Nie udało się zapisać ulubionych: ${errorText(err)}`, "error");
|
||||
this.notice(`Nie udało się zapisać ulubionych: ${errorText(err)}`, "problem");
|
||||
}
|
||||
if (this.panel) this.panel.index = Math.min(this.panel.index, Math.max(0, this.panelView().state.hits.length - 1));
|
||||
cx.notify();
|
||||
@@ -989,12 +989,12 @@ export default class Composer extends View {
|
||||
/** The message goes out, or it waits in the queue. */
|
||||
submit(text, cx, mode = "auto", force = false) {
|
||||
if (!this.syncOk(cx)) {
|
||||
this.notice("Agent się zmienił — wiadomość nie została wysłana. Zostaje w szkicu poprzedniego agenta.", "error", cx);
|
||||
this.notice("Agent się zmienił — wiadomość nie została wysłana. Zostaje w szkicu poprzedniego agenta.", "problem", cx);
|
||||
return;
|
||||
}
|
||||
const agent = this.target();
|
||||
if (!agent) {
|
||||
this.notice("Composer nie ma do kogo pisać — brak agenta.", "error", cx);
|
||||
this.notice("Composer nie ma do kogo pisać — brak agenta.", "problem", cx);
|
||||
return;
|
||||
}
|
||||
const body = text.trim();
|
||||
@@ -1002,7 +1002,7 @@ export default class Composer extends View {
|
||||
|
||||
const over = overLimit(text);
|
||||
if (over > 0) {
|
||||
this.notice(`Limit ${LIMITS.messageChars} znaków · ${over} za dużo`, "error", cx);
|
||||
this.notice(`Limit ${LIMITS.messageChars} znaków · ${over} za dużo`, "problem", cx);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1012,11 +1012,11 @@ export default class Composer extends View {
|
||||
if (broken) {
|
||||
// A file that did not make it to the agent is still in the way - the
|
||||
// person removes it or fixes it first.
|
||||
this.notice(`Plik ${broken.name} nie dotarł do agenta — kliknij „Ponów” albo usuń go.`, "error", cx);
|
||||
this.notice(`Plik ${broken.name} nie dotarł do agenta — kliknij „Ponów” albo usuń go.`, "problem", cx);
|
||||
return;
|
||||
}
|
||||
if (attached.some((file) => file.state === "adding")) {
|
||||
this.notice("Pliki są jeszcze dodawane do agenta — poczekaj chwilę.", "error", cx);
|
||||
this.notice("Pliki są jeszcze dodawane do agenta — poczekaj chwilę.", "problem", cx);
|
||||
return;
|
||||
}
|
||||
const files = attached.filter((file) => file.state === "ready");
|
||||
@@ -1114,7 +1114,7 @@ export default class Composer extends View {
|
||||
async sendNow(agent, message, cx, options = {}) {
|
||||
const key = agentKey(agent);
|
||||
if (this.draining.has(key)) {
|
||||
this.notice("Ta wiadomość jest już w locie.", "error", cx);
|
||||
this.notice("Ta wiadomość jest już w locie.", "problem", cx);
|
||||
return;
|
||||
}
|
||||
this.draining.add(key);
|
||||
@@ -1371,7 +1371,7 @@ export default class Composer extends View {
|
||||
async sendQueued(agent, id, cx) {
|
||||
const key = agentKey(agent);
|
||||
if (this.draining.has(key)) {
|
||||
this.notice("Ta wiadomość jest już w locie.", "error", cx);
|
||||
this.notice("Ta wiadomość jest już w locie.", "problem", cx);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1744,11 +1744,11 @@ export default class Composer extends View {
|
||||
this.addFiles(paths.map((path) => ({ path, bytes: null })), "drop", cx);
|
||||
return;
|
||||
}
|
||||
if (measured.dirs.length) this.notice(DIR_NOTICE, "error");
|
||||
if (measured.dirs.length) this.notice(DIR_NOTICE, "problem");
|
||||
this.addFiles(measured.files, "drop", cx);
|
||||
// A path that is not there any more is said, not skipped in silence.
|
||||
if (measured.missing.length) {
|
||||
this.notice(`Nie znaleziono pliku: ${measured.missing.map(nameOf).join(", ")}`, "error", cx);
|
||||
this.notice(`Nie znaleziono pliku: ${measured.missing.map(nameOf).join(", ")}`, "problem", cx);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1778,7 +1778,7 @@ export default class Composer extends View {
|
||||
if (!this.syncOk(cx)) return;
|
||||
const agent = this.target();
|
||||
if (!agent) {
|
||||
this.notice("Wybierz agenta — nie ma do kogo dodać pliku.", "error", cx);
|
||||
this.notice("Wybierz agenta — nie ma do kogo dodać pliku.", "problem", cx);
|
||||
return;
|
||||
}
|
||||
const key = agentKey(agent);
|
||||
@@ -1793,7 +1793,7 @@ export default class Composer extends View {
|
||||
fresh.push(entry);
|
||||
}
|
||||
if (!fresh.length) {
|
||||
if ((entries ?? []).length) this.notice("Ten plik jest już dodany.", "error", cx);
|
||||
if ((entries ?? []).length) this.notice("Ten plik jest już dodany.", "problem", cx);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1811,7 +1811,7 @@ export default class Composer extends View {
|
||||
// The whole batch may be 100 files at most; every file is judged on its
|
||||
// own - a file that is too big does not take the good ones with it.
|
||||
if ((this.state.attachments[key] ?? []).length + files.length > LIMITS.filesPerAction) {
|
||||
this.notice(`Za dużo plików (limit ${LIMITS.filesPerAction})`, "error", cx);
|
||||
this.notice(`Za dużo plików (limit ${LIMITS.filesPerAction})`, "problem", cx);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1833,7 +1833,7 @@ export default class Composer extends View {
|
||||
file: error ? { ...file, state: "error", error } : { ...file, state: "adding" },
|
||||
});
|
||||
}
|
||||
if (problem) this.notice(problem, "error");
|
||||
if (problem) this.notice(problem, "problem");
|
||||
this.scheduleDraftSave(cx);
|
||||
cx.notify();
|
||||
|
||||
@@ -1860,13 +1860,13 @@ export default class Composer extends View {
|
||||
}
|
||||
|
||||
if (result.kind === "none") {
|
||||
this.notice("Schowek nie zawiera tekstu ani obrazu, który można wkleić.", "error");
|
||||
this.notice("Schowek nie zawiera tekstu ani obrazu, który można wkleić.", "problem");
|
||||
} else if (result.kind === "error") {
|
||||
this.notice(`Nie udało się odczytać schowka: ${result.message}`, "error");
|
||||
this.notice(`Nie udało się odczytać schowka: ${result.message}`, "problem");
|
||||
} else if (result.kind === "dirs") {
|
||||
this.notice(DIR_NOTICE, "error");
|
||||
this.notice(DIR_NOTICE, "problem");
|
||||
} else {
|
||||
if (result.dirs.length) this.notice(DIR_NOTICE, "error");
|
||||
if (result.dirs.length) this.notice(DIR_NOTICE, "problem");
|
||||
this.addFiles(result.files, "paste", cx);
|
||||
}
|
||||
cx.notify();
|
||||
@@ -1886,7 +1886,7 @@ export default class Composer extends View {
|
||||
const picked = parsePickerResult(res);
|
||||
if (picked.length) this.addFiles(picked, "picker", cx);
|
||||
} catch (err) {
|
||||
this.notice(`Nie udało się otworzyć okna wyboru plików: ${errorText(err)}`, "error");
|
||||
this.notice(`Nie udało się otworzyć okna wyboru plików: ${errorText(err)}`, "problem");
|
||||
} finally {
|
||||
this.picking = false;
|
||||
cx.notify();
|
||||
@@ -1973,7 +1973,7 @@ export default class Composer extends View {
|
||||
};
|
||||
storage.saveHistory(this.store, record(storage.loadHistory(this.store), entry));
|
||||
} catch (err) {
|
||||
this.notice(`Nie udało się zapisać historii: ${errorText(err)}`, "error");
|
||||
this.notice(`Nie udało się zapisać historii: ${errorText(err)}`, "problem");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1982,7 +1982,7 @@ export default class Composer extends View {
|
||||
try {
|
||||
storage.saveQueue(this.store, key, this.state.queue[key] ?? []);
|
||||
} catch (err) {
|
||||
this.notice(`Nie udało się zapisać kolejki: ${errorText(err)}`, "error");
|
||||
this.notice(`Nie udało się zapisać kolejki: ${errorText(err)}`, "problem");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1993,6 +1993,9 @@ export default class Composer extends View {
|
||||
* to show up - the caller says when that happens.
|
||||
*/
|
||||
notice(text, level = "info", cx = null) {
|
||||
// Levels: "info"; "problem" - red in the composer, no toast (what the
|
||||
// person did: an empty text, a duplicate file); "error" - red and a toast
|
||||
// (a send or an `hc` call that failed).
|
||||
this.state = reduce(this.state, { type: "notice", notice: { text, level } });
|
||||
if (level === "error") {
|
||||
notify({ title: "Composer", body: text, level: "error" });
|
||||
@@ -2291,7 +2294,7 @@ export default class Composer extends View {
|
||||
renderNotice(t) {
|
||||
const notice = this.state.notice;
|
||||
if (!notice) return null;
|
||||
const error = notice.level === "error";
|
||||
const error = notice.level === "error" || notice.level === "problem";
|
||||
|
||||
return div()
|
||||
.id("composer-notice")
|
||||
|
||||
Reference in new issue
Block a user