Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,14 @@
"xchat/cryptography-primer",
"xchat/getting-started",
"xchat/xchat-xdk",
"xchat/migrate-from-legacy-dms"
{
"group": "Migrate from Legacy DMs",
"root": "xchat/migrate-from-legacy-dms",
"expanded": true,
"pages": [
"xchat/migrate-from-legacy-dms/faq"
]
}
]
},
{
Expand Down
303 changes: 303 additions & 0 deletions snippets/faq-search.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
{/* Live search + topic filter chips for FAQ pages (XDS filled input,
pill chips). Questions stay in the server-rendered page: on mount
this reads every .x-faq-topic section (data-topic, data-label) and
its .x-faq-item entries, then only toggles their [hidden] state and
paints match highlights, so answers remain indexable, linkable, and
readable without JavaScript. Matching folds typographic quotes 1:1
so highlight offsets still line up with the original text nodes.
On mount each .x-faq-q becomes a toggle and its answer collapses;
searching opens the matching rows, clearing the search closes them
again, and hash links open their row. Keep JS comments out
of the component body: Mintlify's snippet parser rejects them. */}
export const FaqSearch = () => {
const [query, setQuery] = useState("");
const [topic, setTopic] = useState("");
const [topics, setTopics] = useState([]);
const [counts, setCounts] = useState({ shown: 0, total: 0, byTopic: {} });
const [fade, setFade] = useState(undefined);
const inputRef = useRef(null);
const chipsRef = useRef(null);
const pendingTarget = useRef(null);
const wasSearching = useRef(false);

const normalize = (value) =>
value.toLowerCase().replace(/[\u2018\u2019]/g, "'").replace(/[\u201C\u201D]/g, '"');

const isWordChar = (ch) => /[a-z0-9]/.test(ch);

const findAll = (text, term) => {
const hits = [];
let index = text.indexOf(term);
while (index !== -1) {
if (index === 0 || !isWordChar(term[0]) || !isWordChar(text[index - 1])) hits.push(index);
index = text.indexOf(term, index + 1);
}
return hits;
};

const decode = (value) => {
try {
return decodeURIComponent(value);
} catch (error) {
return value;
}
};

const findTarget = (hash) => {
const raw = (hash || "").replace(/^#/, "");
if (!raw) return null;
return document.getElementById(raw) || document.getElementById(decode(raw));
};

const setOpen = (item, open) => {
item.dataset.state = open ? "open" : "closed";
const question = item.querySelector(".x-faq-q");
if (question) question.setAttribute("aria-expanded", open ? "true" : "false");
};

const openItem = (target) => {
const item = target.closest(".x-faq-item");
if (item) setOpen(item, true);
};

const toggle = (question) => {
const item = question.closest(".x-faq-item");
if (item) setOpen(item, item.dataset.state !== "open");
};

const collectRanges = (root, terms, ranges) => {
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
let node = walker.nextNode();
while (node) {
const text = normalize(node.data);
terms.forEach((term) => {
findAll(text, term).forEach((index) => {
const range = document.createRange();
range.setStart(node, index);
range.setEnd(node, index + term.length);
ranges.push(range);
});
});
node = walker.nextNode();
}
};

useEffect(() => {
const sections = Array.from(document.querySelectorAll(".x-faq-topic"));
setTopics(sections.map((section) => ({ id: section.dataset.topic, label: section.dataset.label })));

const items = Array.from(document.querySelectorAll(".x-faq-item"));
items.forEach((item) => {
const question = item.querySelector(".x-faq-q");
if (!question) return;
question.setAttribute("role", "button");
question.tabIndex = 0;
setOpen(item, false);
});

const onKeyDown = (event) => {
const question = event.target.closest && event.target.closest(".x-faq-q");
if (question && (event.key === "Enter" || event.key === " ")) {
event.preventDefault();
toggle(question);
return;
}
if (event.key !== "/" || event.metaKey || event.ctrlKey || event.altKey) return;
const active = document.activeElement;
if (active && (active.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(active.tagName))) return;
event.preventDefault();
if (inputRef.current) inputRef.current.focus();
};
const reveal = (hash, scroll) => {
const target = findTarget(hash);
if (!target) return;
openItem(target);
if (target.closest(".x-faq-topic[hidden], .x-faq-item[hidden]")) {
pendingTarget.current = target;
setQuery("");
setTopic("");
} else if (scroll) {
target.scrollIntoView();
}
};
const onHashChange = () => reveal(window.location.hash);
const onClick = (event) => {
const question = event.target.closest && event.target.closest(".x-faq-q");
if (question && !event.target.closest("a")) toggle(question);
const link = event.target.closest && event.target.closest("a[href*='#']");
if (link && link.pathname === window.location.pathname) reveal(link.hash);
};

document.addEventListener("keydown", onKeyDown);
document.addEventListener("click", onClick);
window.addEventListener("hashchange", onHashChange);
const frame = window.requestAnimationFrame(() => reveal(window.location.hash, true));
return () => {
window.cancelAnimationFrame(frame);
document.removeEventListener("keydown", onKeyDown);
document.removeEventListener("click", onClick);
window.removeEventListener("hashchange", onHashChange);
document.querySelectorAll(".x-faq-topic, .x-faq-item").forEach((el) => {
el.hidden = false;
});
items.forEach((item) => {
delete item.dataset.state;
const question = item.querySelector(".x-faq-q");
if (!question) return;
question.removeAttribute("role");
question.removeAttribute("tabindex");
question.removeAttribute("aria-expanded");
});
if (typeof CSS !== "undefined" && CSS.highlights) CSS.highlights.delete("x-faq-match");
};
}, []);

useEffect(() => {
const terms = normalize(query).split(/\s+/).filter(Boolean);
const byTopic = {};
const ranges = [];
let shown = 0;
let total = 0;

document.querySelectorAll(".x-faq-topic").forEach((section) => {
const id = section.dataset.topic;
const inTopic = topic === "" || topic === id;
let matches = 0;
let visible = 0;
section.querySelectorAll(".x-faq-item").forEach((item) => {
const text = normalize(item.textContent);
const match = terms.every((term) => findAll(text, term).length > 0);
const show = match && inTopic;
item.hidden = !show;
if (terms.length > 0) setOpen(item, show);
else if (wasSearching.current) setOpen(item, false);
total += 1;
if (match) matches += 1;
if (show) {
visible += 1;
if (terms.length > 0) collectRanges(item, terms, ranges);
}
});
byTopic[id] = matches;
section.hidden = visible === 0;
shown += visible;
});

wasSearching.current = terms.length > 0;
setCounts({ shown, total, byTopic });
if (typeof CSS !== "undefined" && CSS.highlights && typeof Highlight === "function") {
CSS.highlights.set("x-faq-match", new Highlight(...ranges));
}
if (pendingTarget.current) {
openItem(pendingTarget.current);
pendingTarget.current.scrollIntoView();
pendingTarget.current = null;
}
}, [query, topic, topics]);

useEffect(() => {
const row = chipsRef.current;
if (!row) return undefined;
const update = () => {
const start = row.scrollLeft > 1;
const end = row.scrollLeft < row.scrollWidth - row.clientWidth - 1;
setFade(start && end ? "both" : start ? "start" : end ? "end" : undefined);
};
update();
row.addEventListener("scroll", update, { passive: true });
const observer = typeof ResizeObserver === "function" ? new ResizeObserver(update) : null;
if (observer) observer.observe(row);
return () => {
row.removeEventListener("scroll", update);
if (observer) observer.disconnect();
};
}, [topics, counts]);

const filtered = query.trim() !== "" || topic !== "";
const noun = (n) => (n === 1 ? "question" : "questions");
const placeholder = counts.total > 0 ? `Search ${counts.total} questions` : "Search questions";
const clearAll = () => {
setQuery("");
setTopic("");
if (inputRef.current) inputRef.current.focus();
};

return (
<div className="x-faq-search not-prose" role="search">
<div className="x-faq-search-field">
<svg className="x-faq-search-icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<path d="M10.75 1.75a9 9 0 0 1 7.03 14.62l4.43 4.42-1.42 1.42-4.42-4.43a9 9 0 1 1-5.62-16.03m0 2a7 7 0 1 0 0 14 7 7 0 0 0 0-14" />
</svg>
<input
ref={inputRef}
type="search"
value={query}
placeholder={placeholder}
aria-label={placeholder}
autoComplete="off"
spellCheck={false}
onChange={(event) => setQuery(event.target.value)}
onKeyDown={(event) => {
if (event.key === "Escape") setQuery("");
}}
/>
{query ? (
<button
type="button"
className="x-faq-search-clear"
aria-label="Clear search"
onClick={() => {
setQuery("");
if (inputRef.current) inputRef.current.focus();
}}
>
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<path d="M17.7 7.7 13.42 12l4.3 4.3-1.42 1.4-4.3-4.28-4.3 4.3-1.4-1.42 4.28-4.3-4.3-4.3L7.7 6.3l4.3 4.28 4.3-4.3z" />
</svg>
</button>
) : (
<kbd className="x-faq-search-kbd" aria-hidden="true">/</kbd>
)}
</div>

<div ref={chipsRef} className="x-faq-chips" role="group" aria-label="Filter by topic" data-fade={fade}>
<button type="button" className="x-faq-chip" aria-pressed={topic === ""} onClick={() => setTopic("")}>
All
</button>
{topics.map((item) => (
<button
key={item.id}
type="button"
className="x-faq-chip"
aria-pressed={topic === item.id}
data-empty={counts.byTopic[item.id] === 0 ? "" : undefined}
onClick={() => setTopic(topic === item.id ? "" : item.id)}
>
{item.label} <span className="x-faq-chip-count">{counts.byTopic[item.id] || 0}</span>
</button>
))}
</div>

<p className="x-faq-status" aria-live="polite">
{filtered && counts.shown > 0 ? `Showing ${counts.shown} of ${counts.total} ${noun(counts.total)}` : ""}
{filtered && counts.shown > 0 ? (
<button type="button" onClick={clearAll}>
Clear filters
</button>
) : null}
</p>

{filtered && counts.shown === 0 && counts.total > 0 ? (
<div className="x-faq-empty x-empty-state">
<div className="x-empty-state-title">No matching questions</div>
<p className="x-empty-state-description">
Try fewer or different words, or pick another topic.
</p>
<button type="button" className="x-btn-outline" onClick={clearAll}>
Clear filters
</button>
</div>
) : null}
</div>
);
};
53 changes: 53 additions & 0 deletions snippets/legacy-dm-faq-redirect.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{/* The Partner FAQ used to sit on xchat/migrate-from-legacy-dms as
accordions. Deep links to those questions are forwarded to the
standalone FAQ page, where each question keeps its old slug as id. The
list is frozen: questions added after the move never had anchors on
the guide, and unknown hashes must stay put (some guide links use
stale section anchors). */}
export const LegacyDmFaqRedirect = () => {
useEffect(() => {
const slugs = [
"what-is-changing",
"when-does-this-happen",
"what-stops-working-after-december-9-2026",
"do-we-need-to-move-or-archive-our-existing-dm-history",
"will-my-customers-notice",
"where-is-the-up-to-date-documentation",
"do-i-have-to-switch-to-oauth-2-0-to-use-x-chat",
"what-app-permission-or-scopes-do-i-need",
"if-i-change-my-apps-permission-do-my-customers-have-to-reconnect",
"chat-xdk-examples-use-oauth-2-0-with-pkce-does-chat-xdk-require-that",
"does-sign-in-with-x-change",
"what-are-keys-and-what-is-the-pin",
"my-customers-staff-use-our-web-app-but-only-an-admin-knows-the-pin-does-that-work",
"what-if-the-account-has-never-set-a-pin-or-the-admin-doesnt-know-it",
"how-do-i-check-whether-an-account-already-has-keys-or-can-receive-encrypted-chats",
"is-there-a-limit-on-wrong-pin-guesses",
"do-i-need-xs-approval-to-store-keys-on-my-servers",
"if-a-customer-revokes-my-apps-access-are-the-keys-revoked-too",
"if-we-pause-our-dm-integration-for-a-while-can-we-read-those-messages-later",
"can-we-export-keys-in-the-browser-can-the-pin-stay-off-our-servers",
"can-we-capture-messages-now-and-decrypt-them-after-the-customer-gives-us-keys",
"which-events-replace-the-old-dm-events",
"can-i-create-webhook-subscriptions-with-oauth-1-0a",
"the-chat-events-dont-include-the-senders-name-or-profile-how-do-i-get-them",
"our-bot-only-replies-to-messages-do-we-need-to-do-anything-to-start-conversations",
"is-there-a-full-map-from-the-old-dm-endpoints-to-the-new-ones",
"is-there-a-replacement-for-custom-profiles-listing-all-dm-events-at-once-or-looking-up-one-event-by-id",
"what-about-attachments-welcome-messages-and-surveys",
"what-are-the-x-chat-rate-limits",
"which-languages-does-chat-xdk-support",
"can-i-send-plain-text-through-the-x-chat-api",
"what-do-xchat-setup-required-and-recipient-xchat-setup-required-mean",
"why-does-key-setup-post-2-chat-conversations-id-keys-return-403",
"what-do-message-request-not-supported-and-recipient-not-messageable-mean",
"we-have-several-services-sending-from-the-same-brand-account-can-we-move-them-one-at-a-time",
"some-dms-no-longer-show-up-in-the-legacy-endpoints-why",
"what-other-errors-might-i-see",
];
const hash = window.location.hash.slice(1);
if (slugs.includes(hash)) window.location.replace("/xchat/migrate-from-legacy-dms/faq#" + hash);
}, []);

return null;
};
Loading
Loading