From aebf65405b19a972b187fc56f3ff2f48877c8260 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?No=C3=A9=20Viricel?=
Date: Tue, 22 Oct 2024 19:41:24 +0200
Subject: [PATCH] refactor: apply script setup style to openg hour #353
---
components/Fields/Field.vue | 3 +-
components/Fields/OpeningHours.vue | 318 +++++++++++++----------------
composables/useOpeningHours.ts | 21 ++
3 files changed, 160 insertions(+), 182 deletions(-)
create mode 100644 composables/useOpeningHours.ts
diff --git a/components/Fields/Field.vue b/components/Fields/Field.vue
index 7eee6309..807af690 100644
--- a/components/Fields/Field.vue
+++ b/components/Fields/Field.vue
@@ -10,7 +10,8 @@ import DateRange, { isDateRangeEmpty } from '~/components/Fields/DateRange.vue'
import Facebook from '~/components/Fields/Facebook.vue'
import LinkedIn from '~/components/Fields/LinkedIn.vue'
import Instagram from '~/components/Fields/Instagram.vue'
-import OpeningHours, { isOpeningHoursSupportedOsmTags } from '~/components/Fields/OpeningHours.vue'
+import OpeningHours from '~/components/Fields/OpeningHours.vue'
+import { isOpeningHoursSupportedOsmTags } from '~/composables/useOpeningHours'
import Phone from '~/components/Fields/Phone.vue'
import RoutesField from '~/components/Fields/RoutesField.vue'
import Stars from '~/components/Fields/Stars.vue'
diff --git a/components/Fields/OpeningHours.vue b/components/Fields/OpeningHours.vue
index 7909a4fe..b178d148 100644
--- a/components/Fields/OpeningHours.vue
+++ b/components/Fields/OpeningHours.vue
@@ -1,193 +1,149 @@
-
@@ -195,7 +151,7 @@ export default defineNuxtComponent({
{{ openingHours }}
- {{ $t('openingHours.next') }}
+ {{ t('openingHours.next') }}
@@ -204,10 +160,10 @@ export default defineNuxtComponent({
id="opened"
class="tw-text-emerald-500"
>
- {{ $t('openingHours.opened') }}
+ {{ t('openingHours.opened') }}
-
- {{ $t('openingHours.closeAt') }}
+ {{ t('openingHours.closeAt') }}
@@ -216,10 +172,10 @@ export default defineNuxtComponent({
id="openAt"
class="tw-text-red-500"
>
- {{ $t('openingHours.closed') }}
+ {{ t('openingHours.closed') }}
-
- {{ $t('openingHours.openAt') }}
+ {{ t('openingHours.openAt') }}
@@ -246,7 +202,7 @@ export default defineNuxtComponent({
- {{ $t('openingHours.variableWeek') }}
+ {{ t('openingHours.variableWeek') }}
diff --git a/composables/useOpeningHours.ts b/composables/useOpeningHours.ts
new file mode 100644
index 00000000..8948a78b
--- /dev/null
+++ b/composables/useOpeningHours.ts
@@ -0,0 +1,21 @@
+export const PointTime = [/^collection_times$/, /^service_times$/]
+
+// List of tag keys regex copied from opening_hours.js
+const SupportedOsmKeys = [
+ ...PointTime,
+ /^opening_hours$/,
+ /^opening_hours:.+/,
+ /.+:opening_hours$/,
+ /.+:opening_hours:.+/,
+ /^smoking_hours$/,
+ /^happy_hours$/,
+ /^lit$/,
+]
+
+export function isSupportedOsmTags(keys: RegExp[], key: string): boolean {
+ return keys.some(regexKey => regexKey.test(key))
+}
+
+export function isOpeningHoursSupportedOsmTags(key: string): boolean {
+ return isSupportedOsmTags(SupportedOsmKeys, key)
+}