mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2026-01-11 07:33:02 +00:00
↩️ return type annotations
This commit is contained in:
parent
804ad3f92f
commit
4bab74b852
15 changed files with 48 additions and 48 deletions
|
|
@ -23,7 +23,7 @@ const modal_visible = ref(false);
|
||||||
const is_busy = ref(false);
|
const is_busy = ref(false);
|
||||||
const store = advent22Store();
|
const store = advent22Store();
|
||||||
|
|
||||||
function on_click() {
|
function on_click(): void {
|
||||||
if (store.is_admin) {
|
if (store.is_admin) {
|
||||||
store.logout();
|
store.logout();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -33,7 +33,7 @@ function on_click() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_submit(creds: Credentials) {
|
async function on_submit(creds: Credentials): Promise<void> {
|
||||||
modal_visible.value = false;
|
modal_visible.value = false;
|
||||||
|
|
||||||
store
|
store
|
||||||
|
|
@ -42,7 +42,7 @@ function on_submit(creds: Credentials) {
|
||||||
.finally(() => (is_busy.value = false));
|
.finally(() => (is_busy.value = false));
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_cancel() {
|
function on_cancel(): void {
|
||||||
modal_visible.value = false;
|
modal_visible.value = false;
|
||||||
is_busy.value = false;
|
is_busy.value = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,11 +71,11 @@ let modal: HMultiModal | undefined;
|
||||||
let toast: HBulmaToast | undefined;
|
let toast: HBulmaToast | undefined;
|
||||||
let toast_timeout: number | undefined;
|
let toast_timeout: number | undefined;
|
||||||
|
|
||||||
function on_modal_handle(handle: HMultiModal) {
|
function on_modal_handle(handle: HMultiModal): void {
|
||||||
modal = handle;
|
modal = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_toast_handle(handle: HBulmaToast) {
|
function on_toast_handle(handle: HBulmaToast): void {
|
||||||
toast = handle;
|
toast = handle;
|
||||||
|
|
||||||
if (store.is_touch_device) return;
|
if (store.is_touch_device) return;
|
||||||
|
|
@ -90,7 +90,7 @@ function on_toast_handle(handle: HBulmaToast) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function door_click(day: number) {
|
async function door_click(day: number): Promise<void> {
|
||||||
window.clearTimeout(toast_timeout);
|
window.clearTimeout(toast_timeout);
|
||||||
toast?.hide();
|
toast?.hide();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,11 +46,11 @@ const emit = defineEmits<{
|
||||||
(event: "handle", handle: HMultiModal): void;
|
(event: "handle", handle: HMultiModal): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
function hide() {
|
function hide(): void {
|
||||||
state.value = { show: "none" };
|
state.value = { show: "none" };
|
||||||
}
|
}
|
||||||
|
|
||||||
function dismiss() {
|
function dismiss(): void {
|
||||||
if (state.value.show !== "loading") {
|
if (state.value.show !== "loading") {
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
@ -58,10 +58,10 @@ function dismiss() {
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
emit("handle", {
|
emit("handle", {
|
||||||
show_image(src: string, caption: string = "") {
|
show_image(src: string, caption: string = ""): void {
|
||||||
state.value = { show: "image", src: src, caption: caption };
|
state.value = { show: "image", src: src, caption: caption };
|
||||||
},
|
},
|
||||||
show_loading() {
|
show_loading(): void {
|
||||||
state.value = { show: "loading" };
|
state.value = { show: "loading" };
|
||||||
},
|
},
|
||||||
hide,
|
hide,
|
||||||
|
|
|
||||||
|
|
@ -59,11 +59,11 @@ const day_data = ref<Record<number, { part: string; image_name: string }>>({});
|
||||||
|
|
||||||
let modal: HMultiModal | undefined;
|
let modal: HMultiModal | undefined;
|
||||||
|
|
||||||
function on_modal_handle(handle: HMultiModal) {
|
function on_modal_handle(handle: HMultiModal): void {
|
||||||
modal = handle;
|
modal = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function on_open() {
|
async function on_open(): Promise<void> {
|
||||||
const [day_parts, day_image_names] = await Promise.all([
|
const [day_parts, day_image_names] = await Promise.all([
|
||||||
API.request<NumStrDict>("admin/day_parts"),
|
API.request<NumStrDict>("admin/day_parts"),
|
||||||
API.request<NumStrDict>("admin/day_image_names"),
|
API.request<NumStrDict>("admin/day_image_names"),
|
||||||
|
|
@ -86,7 +86,7 @@ async function on_open() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function door_click(day: number) {
|
async function door_click(day: number): Promise<void> {
|
||||||
if (modal === undefined) return;
|
if (modal === undefined) return;
|
||||||
modal.show_loading();
|
modal.show_loading();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ function fmt_puzzle_date(name: keyof AdminConfigModel["puzzle"]): string {
|
||||||
return DateTime.fromISO(iso_date).toLocaleString(DateTime.DATE_SHORT);
|
return DateTime.fromISO(iso_date).toLocaleString(DateTime.DATE_SHORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function on_open() {
|
async function on_open(): Promise<void> {
|
||||||
const [store_update, new_admin_config_model, new_doors] = await Promise.all([
|
const [store_update, new_admin_config_model, new_doors] = await Promise.all([
|
||||||
store.update(),
|
store.update(),
|
||||||
API.request<AdminConfigModel>("admin/config_model"),
|
API.request<AdminConfigModel>("admin/config_model"),
|
||||||
|
|
@ -259,7 +259,7 @@ async function on_open() {
|
||||||
doors.value = new_doors;
|
doors.value = new_doors;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function load_dav_credentials() {
|
async function load_dav_credentials(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
dav_credentials.value = await API.request<Credentials>(
|
dav_credentials.value = await API.request<Credentials>(
|
||||||
"admin/dav_credentials",
|
"admin/dav_credentials",
|
||||||
|
|
@ -267,7 +267,7 @@ async function load_dav_credentials() {
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function load_ui_credentials() {
|
async function load_ui_credentials(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
ui_credentials.value = await API.request<Credentials>(
|
ui_credentials.value = await API.request<Credentials>(
|
||||||
"admin/ui_credentials",
|
"admin/ui_credentials",
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
:disabled="current_step === 0"
|
:disabled="current_step === 0"
|
||||||
class="level-item is-link"
|
class="level-item is-link"
|
||||||
@click="current_step--"
|
@click="current_step--"
|
||||||
:icon="['fas', 'fa-backward']"
|
:icon="['fas', 'fa-backward']"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<BulmaBreadcrumbs
|
<BulmaBreadcrumbs
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
:disabled="current_step === 2"
|
:disabled="current_step === 2"
|
||||||
class="level-item is-link"
|
class="level-item is-link"
|
||||||
@click="current_step++"
|
@click="current_step++"
|
||||||
:icon="['fas', 'fa-forward']"
|
:icon="['fas', 'fa-forward']"
|
||||||
/>
|
/>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|
@ -47,20 +47,20 @@
|
||||||
<BulmaButton
|
<BulmaButton
|
||||||
class="card-footer-item is-danger"
|
class="card-footer-item is-danger"
|
||||||
@click="on_download"
|
@click="on_download"
|
||||||
:icon="['fas', 'fa-cloud-arrow-down']"
|
:icon="['fas', 'fa-cloud-arrow-down']"
|
||||||
:busy="loading_doors"
|
:busy="loading_doors"
|
||||||
text="Laden"
|
text="Laden"
|
||||||
/>
|
/>
|
||||||
<BulmaButton
|
<BulmaButton
|
||||||
class="card-footer-item is-warning"
|
class="card-footer-item is-warning"
|
||||||
@click="on_discard"
|
@click="on_discard"
|
||||||
:icon="['fas', 'fa-trash']"
|
:icon="['fas', 'fa-trash']"
|
||||||
text="Löschen"
|
text="Löschen"
|
||||||
/>
|
/>
|
||||||
<BulmaButton
|
<BulmaButton
|
||||||
class="card-footer-item is-success"
|
class="card-footer-item is-success"
|
||||||
@click="on_upload"
|
@click="on_upload"
|
||||||
:icon="['fas', 'fa-cloud-arrow-up']"
|
:icon="['fas', 'fa-cloud-arrow-up']"
|
||||||
:busy="saving_doors"
|
:busy="saving_doors"
|
||||||
text="Speichern"
|
text="Speichern"
|
||||||
/>
|
/>
|
||||||
|
|
@ -95,7 +95,7 @@ const current_step = ref(0);
|
||||||
const loading_doors = ref(false);
|
const loading_doors = ref(false);
|
||||||
const saving_doors = ref(false);
|
const saving_doors = ref(false);
|
||||||
|
|
||||||
async function load_doors() {
|
async function load_doors(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const data = await API.request<DoorSaved[]>("admin/doors");
|
const data = await API.request<DoorSaved[]>("admin/doors");
|
||||||
|
|
||||||
|
|
@ -109,7 +109,7 @@ async function load_doors() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function save_doors() {
|
async function save_doors(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const data: DoorSaved[] = [];
|
const data: DoorSaved[] = [];
|
||||||
|
|
||||||
|
|
@ -128,7 +128,7 @@ async function save_doors() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function on_download() {
|
async function on_download(): Promise<void> {
|
||||||
if (confirm("Aktuelle Änderungen verwerfen und Status vom Server laden?")) {
|
if (confirm("Aktuelle Änderungen verwerfen und Status vom Server laden?")) {
|
||||||
loading_doors.value = true;
|
loading_doors.value = true;
|
||||||
|
|
||||||
|
|
@ -146,14 +146,14 @@ async function on_download() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_discard() {
|
function on_discard(): void {
|
||||||
if (confirm("Alle Türchen löschen? (nur lokal)")) {
|
if (confirm("Alle Türchen löschen? (nur lokal)")) {
|
||||||
// empty `doors` array
|
// empty `doors` array
|
||||||
doors.value.length = 0;
|
doors.value.length = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function on_upload() {
|
async function on_upload(): Promise<void> {
|
||||||
if (confirm("Aktuelle Änderungen an den Server schicken?")) {
|
if (confirm("Aktuelle Änderungen an den Server schicken?")) {
|
||||||
saving_doors.value = true;
|
saving_doors.value = true;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ const props = withDefaults(
|
||||||
const state = ref<"closed" | "loading" | "ok" | "err">("closed");
|
const state = ref<"closed" | "loading" | "ok" | "err">("closed");
|
||||||
const is_open = computed(() => state.value !== "closed");
|
const is_open = computed(() => state.value !== "closed");
|
||||||
|
|
||||||
async function toggle() {
|
async function toggle(): Promise<void> {
|
||||||
if (is_open.value) {
|
if (is_open.value) {
|
||||||
state.value = "closed";
|
state.value = "closed";
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -64,7 +64,7 @@ async function toggle() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function load() {
|
async function load(): Promise<void> {
|
||||||
state.value = "loading";
|
state.value = "loading";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ const message = useTemplateRef("message");
|
||||||
|
|
||||||
onMounted(() =>
|
onMounted(() =>
|
||||||
emit("handle", {
|
emit("handle", {
|
||||||
show(options: ToastOptions = {}) {
|
show(options: ToastOptions = {}): void {
|
||||||
if (message.value === null) return;
|
if (message.value === null) return;
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
|
|
@ -33,7 +33,7 @@ onMounted(() =>
|
||||||
message: message.value,
|
message: message.value,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
hide() {
|
hide(): void {
|
||||||
if (message.value === null) return;
|
if (message.value === null) return;
|
||||||
|
|
||||||
const toast_div = message.value.parentElement;
|
const toast_div = message.value.parentElement;
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ const emit = defineEmits<{
|
||||||
(event: TCEventType, e: MouseEvent, point: Vector2D): void;
|
(event: TCEventType, e: MouseEvent, point: Vector2D): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
function transform_mouse_event(event: MouseEvent) {
|
function transform_mouse_event(event: MouseEvent): void {
|
||||||
if (!is_tceventtype(event.type)) return;
|
if (!is_tceventtype(event.type)) return;
|
||||||
|
|
||||||
emit(event.type, event, get_event_thous(event));
|
emit(event.type, event, get_event_thous(event));
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ function pop_door(point: Vector2D): VueLike<Door> | undefined {
|
||||||
return model.value.splice(idx, 1)[0];
|
return model.value.splice(idx, 1)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw_start(event: MouseEvent, point: Vector2D) {
|
function draw_start(event: MouseEvent, point: Vector2D): void {
|
||||||
if (preview_visible.value) {
|
if (preview_visible.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -66,7 +66,7 @@ function draw_start(event: MouseEvent, point: Vector2D) {
|
||||||
state.value = { kind: "drawing" };
|
state.value = { kind: "drawing" };
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw_finish() {
|
function draw_finish(): void {
|
||||||
if (state.value.kind !== "drawing") {
|
if (state.value.kind !== "drawing") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -78,7 +78,7 @@ function draw_finish() {
|
||||||
state.value = { kind: "idle" };
|
state.value = { kind: "idle" };
|
||||||
}
|
}
|
||||||
|
|
||||||
function drag_start(event: MouseEvent, point: Vector2D) {
|
function drag_start(event: MouseEvent, point: Vector2D): void {
|
||||||
if (preview_visible.value) {
|
if (preview_visible.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +94,7 @@ function drag_start(event: MouseEvent, point: Vector2D) {
|
||||||
state.value = { kind: "dragging", door: drag_door, origin: point };
|
state.value = { kind: "dragging", door: drag_door, origin: point };
|
||||||
}
|
}
|
||||||
|
|
||||||
function drag_finish() {
|
function drag_finish(): void {
|
||||||
if (state.value.kind !== "dragging") {
|
if (state.value.kind !== "dragging") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +104,7 @@ function drag_finish() {
|
||||||
state.value = { kind: "idle" };
|
state.value = { kind: "idle" };
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_mousemove(event: MouseEvent, point: Vector2D) {
|
function on_mousemove(event: MouseEvent, point: Vector2D): void {
|
||||||
if (state.value.kind === "drawing") {
|
if (state.value.kind === "drawing") {
|
||||||
preview.value = preview.value.update(undefined, point);
|
preview.value = preview.value.update(undefined, point);
|
||||||
} else if (state.value.kind === "dragging") {
|
} else if (state.value.kind === "dragging") {
|
||||||
|
|
@ -113,7 +113,7 @@ function on_mousemove(event: MouseEvent, point: Vector2D) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_rect(event: MouseEvent, point: Vector2D) {
|
function remove_rect(event: MouseEvent, point: Vector2D): void {
|
||||||
if (preview_visible.value) {
|
if (preview_visible.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,12 @@ const day_input = useTemplateRef("day_input");
|
||||||
const day_str = ref("");
|
const day_str = ref("");
|
||||||
const editing = ref(false);
|
const editing = ref(false);
|
||||||
|
|
||||||
function toggle_editing() {
|
function toggle_editing(): void {
|
||||||
day_str.value = String(model.value.day);
|
day_str.value = String(model.value.day);
|
||||||
editing.value = !editing.value;
|
editing.value = !editing.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_click(event: MouseEvent) {
|
function on_click(event: MouseEvent): void {
|
||||||
if (!(event.target instanceof HTMLDivElement)) {
|
if (!(event.target instanceof HTMLDivElement)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -57,7 +57,7 @@ function on_click(event: MouseEvent) {
|
||||||
toggle_editing();
|
toggle_editing();
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_keydown(event: KeyboardEvent) {
|
function on_keydown(event: KeyboardEvent): void {
|
||||||
if (!editing.value) {
|
if (!editing.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,14 +62,14 @@ export class APIError extends Error {
|
||||||
return result();
|
return result();
|
||||||
}
|
}
|
||||||
|
|
||||||
public alert() {
|
public alert(): void {
|
||||||
toast({
|
toast({
|
||||||
message: this.format(),
|
message: this.format(),
|
||||||
type: "is-danger",
|
type: "is-danger",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static alert(error: unknown) {
|
public static alert(error: unknown): void {
|
||||||
new APIError(error, "").alert();
|
new APIError(error, "").alert();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export function unwrap_loading<T>(o: Loading<T>): T {
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function wait_for(condition: () => boolean, action: () => void) {
|
export function wait_for(condition: () => boolean, action: () => void): void {
|
||||||
const enqueue_action = () => {
|
const enqueue_action = () => {
|
||||||
if (!condition()) {
|
if (!condition()) {
|
||||||
nextTick(enqueue_action);
|
nextTick(enqueue_action);
|
||||||
|
|
@ -38,7 +38,7 @@ export function wait_for(condition: () => boolean, action: () => void) {
|
||||||
enqueue_action();
|
enqueue_action();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handle_error(error: unknown) {
|
export function handle_error(error: unknown): void {
|
||||||
if (error instanceof APIError) {
|
if (error instanceof APIError) {
|
||||||
error.alert();
|
error.alert();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -110,12 +110,12 @@ export const advent22Store = defineStore({
|
||||||
return this.is_admin;
|
return this.is_admin;
|
||||||
},
|
},
|
||||||
|
|
||||||
login(creds: Credentials): Promise<boolean> {
|
async login(creds: Credentials): Promise<boolean> {
|
||||||
API.creds = { username: creds[0], password: creds[1] };
|
API.creds = { username: creds[0], password: creds[1] };
|
||||||
return this.update_is_admin();
|
return await this.update_is_admin();
|
||||||
},
|
},
|
||||||
|
|
||||||
logout(): Promise<boolean> {
|
logout() {
|
||||||
return this.login(["", ""]);
|
return this.login(["", ""]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ describe("Rectangle Tests", () => {
|
||||||
top: number,
|
top: number,
|
||||||
width: number,
|
width: number,
|
||||||
height: number,
|
height: number,
|
||||||
) {
|
): void {
|
||||||
expect(r.left).to.equal(left);
|
expect(r.left).to.equal(left);
|
||||||
expect(r.top).to.equal(top);
|
expect(r.top).to.equal(top);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue