From 72e7a8fd6eed9d7f09fdca888b44c40021af207d Mon Sep 17 00:00:00 2001
From: Atridad Lahiji
Date: Mon, 27 Jan 2025 00:05:19 -0600
Subject: [PATCH] Added handle editing with warning.
---
src/components/features/users/UserList.tsx | 137 ++++++++++++++++++++-
src/types/index.ts | 0
2 files changed, 134 insertions(+), 3 deletions(-)
delete mode 100644 src/types/index.ts
diff --git a/src/components/features/users/UserList.tsx b/src/components/features/users/UserList.tsx
index 1e1ff0c..921b77e 100644
--- a/src/components/features/users/UserList.tsx
+++ b/src/components/features/users/UserList.tsx
@@ -4,6 +4,7 @@ import { useRefresh } from "../../../lib/RefreshContext";
interface User {
did: string;
+ handle?: string;
displayName?: string;
description?: string;
avatar?: {
@@ -14,6 +15,7 @@ interface User {
createdAt: string;
}
+
interface RepoResponse {
cursor: string;
repos: {
@@ -79,6 +81,16 @@ export default function UserList() {
show: false,
user: null,
});
+ const [editModal, setEditModal] = useState<{
+ show: boolean;
+ user: User | null;
+ newHandle: string;
+ }>({
+ show: false,
+ user: null,
+ newHandle: "",
+ });
+
const resetState = () => {
setUsers([]);
@@ -108,6 +120,7 @@ export default function UserList() {
const data = await response.json();
return {
did,
+ handle: data.value.handle,
displayName: data.value.displayName,
description: data.value.description,
avatar: data.value.avatar,
@@ -210,6 +223,48 @@ export default function UserList() {
}
};
+ const updateUserHandle = async (did: string, newHandle: string) => {
+ try {
+ setLoading(true);
+ setError(null);
+
+ const baseUrl = await Settings.getServiceUrl();
+ if (!baseUrl) throw new Error("Service URL not configured");
+
+ const headers = {
+ Authorization: await getAuthHeader(),
+ "Content-Type": "application/json",
+ };
+
+ const response = await fetch(
+ `${baseUrl}/xrpc/com.atproto.admin.updateAccountHandle`,
+ {
+ method: "POST",
+ headers,
+ body: JSON.stringify({
+ did,
+ handle: newHandle,
+ }),
+ }
+ );
+
+ if (!response.ok) {
+ const errorText = await response.text();
+ console.error("Error response:", errorText);
+ throw new Error(
+ `Failed to update handle: ${response.status} ${response.statusText}`
+ );
+ }
+
+ await fetchUsers(); // Refresh the user list after successful update
+ } catch (err) {
+ console.error("Update handle error:", err);
+ setError(err instanceof Error ? err.message : "Failed to update handle");
+ } finally {
+ setLoading(false);
+ }
+ };
+
useEffect(() => {
async function checkSettings() {
try {
@@ -304,6 +359,69 @@ export default function UserList() {
+ {/* Edit Handle Modal */}
+ {editModal.show && editModal.user && (
+
+ )}
+
{/* Confirmation Modal */}
{deleteConfirmation.show && deleteConfirmation.user && (
)}
+
+