|
30 | 30 | extractPollIdFromSearch, |
31 | 31 | filterRowsForVisibleDaysAndMinYesVotes, |
32 | 32 | filterWeekRowsByMinYesVotes, |
| 33 | + filterTimezoneSuggestionOptions, |
33 | 34 | isVoteStatusValue, |
34 | 35 | loadCalendarTimezonePreferenceValue, |
35 | 36 | matchesYesVoteFilter, |
|
48 | 49 | || typeof extractPollIdFromSearch !== "function" |
49 | 50 | || typeof filterRowsForVisibleDaysAndMinYesVotes !== "function" |
50 | 51 | || typeof filterWeekRowsByMinYesVotes !== "function" |
| 52 | + || typeof filterTimezoneSuggestionOptions !== "function" |
51 | 53 | || typeof isVoteStatusValue !== "function" |
52 | 54 | || typeof loadCalendarTimezonePreferenceValue !== "function" |
53 | 55 | || typeof matchesYesVoteFilter !== "function" |
@@ -1512,78 +1514,22 @@ const translations = { |
1512 | 1514 | ]; |
1513 | 1515 | }, |
1514 | 1516 | filteredTimezoneOptions() { |
1515 | | - const options = this.timezoneOptions.map((tz) => { |
1516 | | - const meta = this.timezoneMeta(tz); |
1517 | | - const label = meta ? `${tz} ${meta}` : tz; |
1518 | | - return { id: tz, meta, label }; |
1519 | | - }); |
1520 | | - const rawQuery = (this.createForm.timezone || "").trim().toLowerCase(); |
1521 | | - if (!rawQuery) { |
1522 | | - return options.slice(0, 200); |
1523 | | - } |
1524 | | - return options |
1525 | | - .filter((item) => item.label.toLowerCase().includes(rawQuery)) |
1526 | | - .slice(0, 200); |
| 1517 | + return this.buildFilteredTimezoneOptions(this.timezoneInputValue("create")); |
1527 | 1518 | }, |
1528 | 1519 | filteredEditTimezoneOptions() { |
1529 | | - const options = this.timezoneOptions.map((tz) => { |
1530 | | - const meta = this.timezoneMeta(tz); |
1531 | | - const label = meta ? `${tz} ${meta}` : tz; |
1532 | | - return { id: tz, meta, label }; |
1533 | | - }); |
1534 | | - const rawQuery = this.editForm && typeof this.editForm.timezone === "string" |
1535 | | - ? this.editForm.timezone.trim().toLowerCase() |
1536 | | - : ""; |
1537 | | - if (!rawQuery) { |
1538 | | - return options.slice(0, 200); |
1539 | | - } |
1540 | | - return options |
1541 | | - .filter((item) => item.label.toLowerCase().includes(rawQuery)) |
1542 | | - .slice(0, 200); |
| 1520 | + return this.buildFilteredTimezoneOptions(this.timezoneInputValue("edit")); |
1543 | 1521 | }, |
1544 | 1522 | filteredCalendarTimezoneOptions() { |
1545 | | - const options = this.timezoneOptions.map((tz) => { |
1546 | | - const meta = this.timezoneMeta(tz); |
1547 | | - const label = meta ? `${tz} ${meta}` : tz; |
1548 | | - return { id: tz, meta, label }; |
1549 | | - }); |
1550 | | - const rawQuery = (this.calendarCustomTimezone || "").trim().toLowerCase(); |
1551 | | - if (!rawQuery) { |
1552 | | - return options.slice(0, 200); |
1553 | | - } |
1554 | | - return options |
1555 | | - .filter((item) => item.label.toLowerCase().includes(rawQuery)) |
1556 | | - .slice(0, 200); |
| 1523 | + return this.buildFilteredTimezoneOptions(this.timezoneInputValue("calendar")); |
1557 | 1524 | }, |
1558 | 1525 | activeCreateTimezoneSuggestionId() { |
1559 | | - if ( |
1560 | | - !this.showTimezoneSuggestions |
1561 | | - || this.activeTimezoneSuggestionIndex < 0 |
1562 | | - || this.activeTimezoneSuggestionIndex >= this.filteredTimezoneOptions.length |
1563 | | - ) { |
1564 | | - return ""; |
1565 | | - } |
1566 | | - return this.timezoneSuggestionOptionId("create", this.activeTimezoneSuggestionIndex); |
| 1526 | + return this.activeTimezoneSuggestionIdForScope("create"); |
1567 | 1527 | }, |
1568 | 1528 | activeEditTimezoneSuggestionId() { |
1569 | | - if ( |
1570 | | - !this.showEditTimezoneSuggestions |
1571 | | - || this.activeEditTimezoneSuggestionIndex < 0 |
1572 | | - || this.activeEditTimezoneSuggestionIndex >= this.filteredEditTimezoneOptions.length |
1573 | | - ) { |
1574 | | - return ""; |
1575 | | - } |
1576 | | - return this.timezoneSuggestionOptionId("edit", this.activeEditTimezoneSuggestionIndex); |
| 1529 | + return this.activeTimezoneSuggestionIdForScope("edit"); |
1577 | 1530 | }, |
1578 | 1531 | activeCalendarTimezoneSuggestionId() { |
1579 | | - if ( |
1580 | | - !this.showCalendarTimezoneSuggestions |
1581 | | - || this.activeCalendarTimezoneSuggestionIndex < 0 |
1582 | | - || this.activeCalendarTimezoneSuggestionIndex >= this.filteredCalendarTimezoneOptions.length |
1583 | | - ) { |
1584 | | - return ""; |
1585 | | - } |
1586 | | - return this.timezoneSuggestionOptionId("calendar", this.activeCalendarTimezoneSuggestionIndex); |
| 1532 | + return this.activeTimezoneSuggestionIdForScope("calendar"); |
1587 | 1533 | }, |
1588 | 1534 | selectedTimezoneDisplay() { |
1589 | 1535 | return this.timezoneDisplay(this.createForm.timezone); |
@@ -2598,6 +2544,45 @@ const translations = { |
2598 | 2544 | } |
2599 | 2545 | return this.filteredTimezoneOptions; |
2600 | 2546 | }, |
| 2547 | + timezoneInputValue(scope = "create") { |
| 2548 | + if (scope === "calendar") { |
| 2549 | + return this.calendarCustomTimezone; |
| 2550 | + } |
| 2551 | + if (scope === "edit") { |
| 2552 | + return this.editForm && typeof this.editForm.timezone === "string" |
| 2553 | + ? this.editForm.timezone |
| 2554 | + : ""; |
| 2555 | + } |
| 2556 | + return this.createForm.timezone; |
| 2557 | + }, |
| 2558 | + timezoneSuggestionsOpen(scope = "create") { |
| 2559 | + if (scope === "calendar") { |
| 2560 | + return this.showCalendarTimezoneSuggestions; |
| 2561 | + } |
| 2562 | + if (scope === "edit") { |
| 2563 | + return this.showEditTimezoneSuggestions; |
| 2564 | + } |
| 2565 | + return this.showTimezoneSuggestions; |
| 2566 | + }, |
| 2567 | + buildFilteredTimezoneOptions(query = "") { |
| 2568 | + return filterTimezoneSuggestionOptions( |
| 2569 | + this.timezoneOptions, |
| 2570 | + query, |
| 2571 | + (timeZone) => this.timezoneMeta(timeZone) |
| 2572 | + ); |
| 2573 | + }, |
| 2574 | + activeTimezoneSuggestionIdForScope(scope = "create") { |
| 2575 | + const options = this.timezoneSuggestionOptions(scope); |
| 2576 | + const activeIndex = this.timezoneSuggestionIndex(scope); |
| 2577 | + if ( |
| 2578 | + !this.timezoneSuggestionsOpen(scope) |
| 2579 | + || activeIndex < 0 |
| 2580 | + || activeIndex >= options.length |
| 2581 | + ) { |
| 2582 | + return ""; |
| 2583 | + } |
| 2584 | + return this.timezoneSuggestionOptionId(scope, activeIndex); |
| 2585 | + }, |
2601 | 2586 | timezoneSuggestionIndex(scope = "create") { |
2602 | 2587 | if (scope === "calendar") { |
2603 | 2588 | return this.activeCalendarTimezoneSuggestionIndex; |
@@ -2634,12 +2619,7 @@ const translations = { |
2634 | 2619 | this.setTimezoneSuggestionIndex(scope, -1); |
2635 | 2620 | return; |
2636 | 2621 | } |
2637 | | - const rawValue = scope === "calendar" |
2638 | | - ? this.calendarCustomTimezone |
2639 | | - : scope === "edit" |
2640 | | - ? (this.editForm ? this.editForm.timezone : "") |
2641 | | - : this.createForm.timezone; |
2642 | | - const normalizedValue = String(rawValue || "").trim().toLowerCase(); |
| 2622 | + const normalizedValue = String(this.timezoneInputValue(scope) || "").trim().toLowerCase(); |
2643 | 2623 | const matchedIndex = options.findIndex((item) => item.id.toLowerCase() === normalizedValue); |
2644 | 2624 | this.setTimezoneSuggestionIndex(scope, matchedIndex >= 0 ? matchedIndex : 0); |
2645 | 2625 | }, |
|
0 commit comments