@ansiversa/components 0.0.140 → 0.0.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -118,22 +118,26 @@ const initialAudience = defaultAudience === "admin" ? "admin" : "user";
|
|
|
118
118
|
<tr>
|
|
119
119
|
<td>
|
|
120
120
|
<div class="av-faq-manager__order-cell">
|
|
121
|
-
<
|
|
122
|
-
class="av-input av-faq-manager__order-input"
|
|
123
|
-
type="number"
|
|
124
|
-
min="1"
|
|
125
|
-
x-model.number="faq.sort_order"
|
|
126
|
-
:disabled="loading || saving"
|
|
127
|
-
aria-label="Sort order"
|
|
128
|
-
/>
|
|
121
|
+
<span class="av-faq-manager__order-pill" x-text="faq.sort_order"></span>
|
|
129
122
|
<AvButton
|
|
130
123
|
size="sm"
|
|
131
124
|
variant="ghost"
|
|
132
125
|
type="button"
|
|
133
|
-
@click.prevent="
|
|
134
|
-
:disabled="loading || saving || !faq.id"
|
|
126
|
+
@click.prevent="moveFaq(index, -1)"
|
|
127
|
+
:disabled="loading || saving || index === 0 || !faq.id || !faqs[index - 1]?.id"
|
|
128
|
+
aria-label="Move up"
|
|
135
129
|
>
|
|
136
|
-
|
|
130
|
+
↑
|
|
131
|
+
</AvButton>
|
|
132
|
+
<AvButton
|
|
133
|
+
size="sm"
|
|
134
|
+
variant="ghost"
|
|
135
|
+
type="button"
|
|
136
|
+
@click.prevent="moveFaq(index, 1)"
|
|
137
|
+
:disabled="loading || saving || index === faqs.length - 1 || !faq.id || !faqs[index + 1]?.id"
|
|
138
|
+
aria-label="Move down"
|
|
139
|
+
>
|
|
140
|
+
↓
|
|
137
141
|
</AvButton>
|
|
138
142
|
</div>
|
|
139
143
|
</td>
|
|
@@ -658,41 +662,70 @@ const initialAudience = defaultAudience === "admin" ? "admin" : "user";
|
|
|
658
662
|
}
|
|
659
663
|
},
|
|
660
664
|
|
|
661
|
-
|
|
662
|
-
|
|
665
|
+
normalizeSortOrder(value, fallbackOrder) {
|
|
666
|
+
const parsed = Number.parseInt(String(value ?? ""), 10);
|
|
667
|
+
if (Number.isInteger(parsed) && parsed >= 1) return parsed;
|
|
668
|
+
return Math.max(1, Number.parseInt(String(fallbackOrder ?? 1), 10) || 1);
|
|
669
|
+
},
|
|
670
|
+
|
|
671
|
+
async patchSortOrder(id, sortOrder) {
|
|
672
|
+
const response = await fetch(
|
|
673
|
+
this.endpoint(`/api/admin/faqs/${encodeURIComponent(String(id))}.json`),
|
|
674
|
+
{
|
|
675
|
+
method: "PATCH",
|
|
676
|
+
credentials: "include",
|
|
677
|
+
headers: {
|
|
678
|
+
"Content-Type": "application/json",
|
|
679
|
+
},
|
|
680
|
+
body: JSON.stringify({ sort_order: sortOrder }),
|
|
681
|
+
},
|
|
682
|
+
);
|
|
683
|
+
|
|
684
|
+
const responsePayload = await this.parseJson(response);
|
|
685
|
+
|
|
686
|
+
if (!response.ok) {
|
|
687
|
+
throw new Error(this.mapError(response.status, responsePayload, "Failed to update sort order."));
|
|
688
|
+
}
|
|
689
|
+
},
|
|
690
|
+
|
|
691
|
+
async moveFaq(index, direction) {
|
|
692
|
+
const currentIndex = Number(index);
|
|
693
|
+
const nextIndex = currentIndex + Number(direction);
|
|
694
|
+
if (!Number.isInteger(currentIndex) || !Number.isInteger(nextIndex)) return;
|
|
695
|
+
if (nextIndex < 0 || nextIndex >= this.faqs.length) return;
|
|
696
|
+
|
|
697
|
+
const currentFaq = this.faqs[currentIndex];
|
|
698
|
+
const nextFaq = this.faqs[nextIndex];
|
|
699
|
+
if (!currentFaq?.id || !nextFaq?.id) return;
|
|
663
700
|
|
|
664
|
-
const
|
|
665
|
-
|
|
701
|
+
const currentOrder = this.normalizeSortOrder(currentFaq.sort_order, currentIndex + 1);
|
|
702
|
+
const nextOrder = this.normalizeSortOrder(nextFaq.sort_order, nextIndex + 1);
|
|
703
|
+
if (currentOrder < 1 || nextOrder < 1) {
|
|
666
704
|
this.error = "Sort order must be 1 or greater.";
|
|
667
705
|
return;
|
|
668
706
|
}
|
|
669
707
|
|
|
708
|
+
const snapshot = this.faqs.map((item) => ({ ...item }));
|
|
709
|
+
const reordered = this.faqs.map((item) => ({ ...item }));
|
|
710
|
+
[reordered[currentIndex], reordered[nextIndex]] = [reordered[nextIndex], reordered[currentIndex]];
|
|
711
|
+
reordered[nextIndex].sort_order = currentOrder;
|
|
712
|
+
reordered[currentIndex].sort_order = nextOrder;
|
|
713
|
+
|
|
714
|
+
this.faqs = reordered;
|
|
715
|
+
|
|
670
716
|
this.saving = true;
|
|
671
717
|
this.error = "";
|
|
672
718
|
this.notice = "";
|
|
673
719
|
|
|
674
720
|
try {
|
|
675
|
-
|
|
676
|
-
this.
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
credentials: "include",
|
|
680
|
-
headers: {
|
|
681
|
-
"Content-Type": "application/json",
|
|
682
|
-
},
|
|
683
|
-
body: JSON.stringify({ sort_order: nextSortOrder }),
|
|
684
|
-
},
|
|
685
|
-
);
|
|
686
|
-
|
|
687
|
-
const responsePayload = await this.parseJson(response);
|
|
688
|
-
|
|
689
|
-
if (!response.ok) {
|
|
690
|
-
throw new Error(this.mapError(response.status, responsePayload, "Failed to update sort order."));
|
|
691
|
-
}
|
|
721
|
+
await Promise.all([
|
|
722
|
+
this.patchSortOrder(reordered[currentIndex].id, reordered[currentIndex].sort_order),
|
|
723
|
+
this.patchSortOrder(reordered[nextIndex].id, reordered[nextIndex].sort_order),
|
|
724
|
+
]);
|
|
692
725
|
|
|
693
|
-
this.notice = "
|
|
694
|
-
await this.fetchFaqs();
|
|
726
|
+
this.notice = "Order updated.";
|
|
695
727
|
} catch (sortError) {
|
|
728
|
+
this.faqs = snapshot;
|
|
696
729
|
this.error = sortError?.message || "Failed to update sort order.";
|
|
697
730
|
} finally {
|
|
698
731
|
this.saving = false;
|
|
@@ -709,9 +742,18 @@ const initialAudience = defaultAudience === "admin" ? "admin" : "user";
|
|
|
709
742
|
align-items: center;
|
|
710
743
|
}
|
|
711
744
|
|
|
712
|
-
.av-faq-manager__order-
|
|
713
|
-
width:
|
|
714
|
-
|
|
745
|
+
.av-faq-manager__order-pill {
|
|
746
|
+
min-width: 2rem;
|
|
747
|
+
height: 2rem;
|
|
748
|
+
display: inline-flex;
|
|
749
|
+
align-items: center;
|
|
750
|
+
justify-content: center;
|
|
751
|
+
border-radius: 9999px;
|
|
752
|
+
border: 1px solid rgba(148, 163, 184, 0.35);
|
|
753
|
+
color: rgba(226, 232, 240, 0.95);
|
|
754
|
+
font-size: 0.78rem;
|
|
755
|
+
line-height: 1;
|
|
756
|
+
padding: 0 0.5rem;
|
|
715
757
|
}
|
|
716
758
|
|
|
717
759
|
.av-faq-manager__publish-toggle {
|