From b8264a33459272ad7aa5504b4d1f302879491eac Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 19 Sep 2024 18:01:17 +0200 Subject: [PATCH] UX: improvements to opening hours picker, fix some residual errors after refactoring --- .../Helpers/OpeningHours/OHCell.svelte | 10 ++- .../Helpers/OpeningHours/OHTable.svelte | 86 +++++++++++++++---- .../Helpers/OpeningHoursInput.svelte | 8 +- src/UI/OpeningHours/OpeningHours.ts | 21 +++++ 4 files changed, 102 insertions(+), 23 deletions(-) diff --git a/src/UI/InputElement/Helpers/OpeningHours/OHCell.svelte b/src/UI/InputElement/Helpers/OpeningHours/OHCell.svelte index 85aa89990..10719c44d 100644 --- a/src/UI/InputElement/Helpers/OpeningHours/OHCell.svelte +++ b/src/UI/InputElement/Helpers/OpeningHours/OHCell.svelte @@ -25,7 +25,7 @@ continue } const el = document.elementFromPoint(touch.clientX, touch.clientY) - if (!el) { + if (!el || !el.classList.contains("oh-timecell")) { continue } lastElement = el @@ -46,12 +46,18 @@ if (el?.onmouseup) { el?.onmouseup(ev) }else{ + // We dragged outside of the table dispatch("clear") } }) element.addEventListener("touchmove", ev => { - elementUnderTouch(ev)?.onmouseenter(ev) + const underTouch = elementUnderTouch(ev) + if(typeof underTouch?.onmouseenter !== "function"){ + return + } + + underTouch.onmouseenter(ev) }) diff --git a/src/UI/InputElement/Helpers/OpeningHours/OHTable.svelte b/src/UI/InputElement/Helpers/OpeningHours/OHTable.svelte index 9d845dafe..56e273933 100644 --- a/src/UI/InputElement/Helpers/OpeningHours/OHTable.svelte +++ b/src/UI/InputElement/Helpers/OpeningHours/OHTable.svelte @@ -24,6 +24,8 @@ wd.sunday, ] + let element: HTMLTableElement + function range(n: number) { return Utils.TimesT(n, n => n) } @@ -114,11 +116,29 @@ clearSelection() } + + let lasttouched: [number, number] = undefined + function moved(weekday: number, hour: number) { + lasttouched = [weekday, hour] if (selectionStart) { clearSelection() setSelection(selectionStart[0], weekday, selectionStart[1], hour + 0.5) } + const allRows = Array.from(element.getElementsByTagName("tr")) + for (const r of allRows) { + r.classList.remove("hover") + r.classList.remove("hovernext") + + } + const selectedRow = allRows[hour * 2 + 2] + selectedRow?.classList?.add("hover") + const selectedNextRow = allRows[hour * 2 + 3] + selectedNextRow?.classList?.add("hovernext") + } + + function mouseLeft() { + endSelection(...lasttouched) } let totalHeight = 0 @@ -146,14 +166,20 @@ - +
- + {#each days as wd} - + - {#each range(7) as wd} @@ -215,12 +243,13 @@ {/each} - - {#if h === 23} - + {#if h === 0} + @@ -235,4 +264,25 @@ position: sticky; z-index: 10; } + + + .hasselection tr:hover .hour-header, .hasselection tr.hover .hour-header { + border-bottom: 2px solid black; + } + + + .hasselection tr:hover + tr { + font-weight: bold; + } + + .hasselection tr.hovernext { + font-weight: bold; + } + + .hasnoselection tr:hover, .hasnoselection tr.hover { + font-weight: bold; + } + + + diff --git a/src/UI/InputElement/Helpers/OpeningHoursInput.svelte b/src/UI/InputElement/Helpers/OpeningHoursInput.svelte index 068a7503c..2b82a9cad 100644 --- a/src/UI/InputElement/Helpers/OpeningHoursInput.svelte +++ b/src/UI/InputElement/Helpers/OpeningHoursInput.svelte @@ -9,6 +9,8 @@ import OHTable from "./OpeningHours/OHTable.svelte" import OpeningHoursState from "../../OpeningHours/OpeningHoursState" import Popup from "../../Base/Popup.svelte" + import CheckCircle from "@babeard/svelte-heroicons/mini/CheckCircle" + import Check from "@babeard/svelte-heroicons/mini/Check" export let value: UIEventSource export let args: string @@ -34,9 +36,9 @@ -
- -
+
diff --git a/src/UI/OpeningHours/OpeningHours.ts b/src/UI/OpeningHours/OpeningHours.ts index d664a86fd..7f775ebd1 100644 --- a/src/UI/OpeningHours/OpeningHours.ts +++ b/src/UI/OpeningHours/OpeningHours.ts @@ -916,6 +916,27 @@ This list will be sorted } return ohs } + + /** + * Small utility function for the OH-table. if endHour is '0', rewrite this as '24' + * + * const oh = { + * weekday: 0, + * endMinutes: 0, + * endHour: 0, + * startHour: 10, + * startMinutes: 0 + * } + * OH.rangeAs24Hr(oh).endHour // => 24 + */ + static rangeAs24Hr(oh: OpeningHour) { + if(oh.endHour === 0){ + return { + ...oh, endHour : 24 + } + } + return oh + } } export class ToTextualDescription {
- + + + @@ -162,14 +188,14 @@ {/each}
- {#if h < 23} - {h + 1}:00 + 0 ? 2: 1 } + class="relative text-sm sm:text-base oh-left-col oh-timecell-full border-box interactive " + style={ h > 0 ? "top: -0.75rem" : "height:0; top: -0.75rem"}> + {#if h > 0} + + {h}:00 + {/if}
- {/if} +
+ {/if} {#each range(7) as wd} - startSelection(wd, h + 0.5)} on:end={() => endSelection(wd, h + 0.5)} + startSelection(wd, h + 0.5)} + on:end={() => endSelection(wd, h + 0.5)} on:move={() => moved(wd, h + 0.5)} on:clear={() => clearSelection()} /> {/each}