fix: 🐛 Make usernames case-insensitive when searching and viewing profiles

This commit is contained in:
Jesse Wierzbinski 2024-07-17 01:34:21 +02:00
parent 2a4deacff4
commit e89f56a97e
No known key found for this signature in database

View file

@ -22,12 +22,19 @@ definePageMeta({
const route = useRoute();
const client = useClient();
const username = (route.params.username as string).replace("@", "");
const username = (route.params.username as string).startsWith("@")
? (route.params.username as string).substring(1)
: (route.params.username as string);
const accounts = useAccountSearch(client, username);
watch(accounts, (newValue) => {
if (Array.isArray(newValue)) {
if (!newValue.find((account) => account.acct === username)) {
if (
!newValue.find(
(account) =>
account.acct.toLowerCase() === username.toLowerCase(),
)
) {
useEvent("error", {
title: "Account not found",
message: `The account <code>@${username}</code> does not exist.`,
@ -37,7 +44,10 @@ watch(accounts, (newValue) => {
}
});
const account = computed<Account | null>(
() => accounts.value?.find((account) => account.acct === username) ?? null,
() =>
accounts.value?.find(
(account) => account.acct.toLowerCase() === username.toLowerCase(),
) ?? null,
);
const accountId = computed(() => account.value?.id ?? undefined);