mirror of
				https://github.com/hydralauncher/hydra.git
				synced 2025-03-09 15:40:26 +00:00 
			
		
		
		
	feat: list blocked users
This commit is contained in:
		
							parent
							
								
									7e6b9ca825
								
							
						
					
					
						commit
						fbe3c1973a
					
				
					 7 changed files with 119 additions and 3 deletions
				
			
		| 
						 | 
					@ -43,6 +43,7 @@ import "./auth/sign-out";
 | 
				
			||||||
import "./auth/open-auth-window";
 | 
					import "./auth/open-auth-window";
 | 
				
			||||||
import "./auth/get-session-hash";
 | 
					import "./auth/get-session-hash";
 | 
				
			||||||
import "./user/get-user";
 | 
					import "./user/get-user";
 | 
				
			||||||
 | 
					import "./user/get-user-blocks";
 | 
				
			||||||
import "./user/block-user";
 | 
					import "./user/block-user";
 | 
				
			||||||
import "./user/unblock-user";
 | 
					import "./user/unblock-user";
 | 
				
			||||||
import "./user/get-user-friends";
 | 
					import "./user/get-user-friends";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								src/main/events/user/get-user-blocks.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/main/events/user/get-user-blocks.ts
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,13 @@
 | 
				
			||||||
 | 
					import { registerEvent } from "../register-event";
 | 
				
			||||||
 | 
					import { HydraApi } from "@main/services";
 | 
				
			||||||
 | 
					import { UserBlocks } from "@types";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const getUserBlocks = async (
 | 
				
			||||||
 | 
					  _event: Electron.IpcMainInvokeEvent,
 | 
				
			||||||
 | 
					  take: number,
 | 
				
			||||||
 | 
					  skip: number
 | 
				
			||||||
 | 
					): Promise<UserBlocks> => {
 | 
				
			||||||
 | 
					  return HydraApi.get(`/profile/blocks`, { take, skip });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					registerEvent("getUserBlocks", getUserBlocks);
 | 
				
			||||||
| 
						 | 
					@ -152,6 +152,8 @@ contextBridge.exposeInMainWorld("electron", {
 | 
				
			||||||
  unblockUser: (userId: string) => ipcRenderer.invoke("unblockUser", userId),
 | 
					  unblockUser: (userId: string) => ipcRenderer.invoke("unblockUser", userId),
 | 
				
			||||||
  getUserFriends: (userId: string, take: number, skip: number) =>
 | 
					  getUserFriends: (userId: string, take: number, skip: number) =>
 | 
				
			||||||
    ipcRenderer.invoke("getUserFriends", userId, take, skip),
 | 
					    ipcRenderer.invoke("getUserFriends", userId, take, skip),
 | 
				
			||||||
 | 
					  getUserBlocks: (take: number, skip: number) =>
 | 
				
			||||||
 | 
					    ipcRenderer.invoke("getUserBlocks", take, skip),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Auth */
 | 
					  /* Auth */
 | 
				
			||||||
  signOut: () => ipcRenderer.invoke("signOut"),
 | 
					  signOut: () => ipcRenderer.invoke("signOut"),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								src/renderer/src/declaration.d.ts
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								src/renderer/src/declaration.d.ts
									
										
									
									
										vendored
									
									
								
							| 
						 | 
					@ -17,6 +17,7 @@ import type {
 | 
				
			||||||
  FriendRequest,
 | 
					  FriendRequest,
 | 
				
			||||||
  FriendRequestAction,
 | 
					  FriendRequestAction,
 | 
				
			||||||
  UserFriends,
 | 
					  UserFriends,
 | 
				
			||||||
 | 
					  UserBlocks,
 | 
				
			||||||
} from "@types";
 | 
					} from "@types";
 | 
				
			||||||
import type { DiskSpace } from "check-disk-space";
 | 
					import type { DiskSpace } from "check-disk-space";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -135,6 +136,7 @@ declare global {
 | 
				
			||||||
      take: number,
 | 
					      take: number,
 | 
				
			||||||
      skip: number
 | 
					      skip: number
 | 
				
			||||||
    ) => Promise<UserFriends>;
 | 
					    ) => Promise<UserFriends>;
 | 
				
			||||||
 | 
					    getUserBlocks: (take: number, skip: number) => Promise<UserBlocks>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Profile */
 | 
					    /* Profile */
 | 
				
			||||||
    getMe: () => Promise<UserProfile | null>;
 | 
					    getMe: () => Promise<UserProfile | null>;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,92 @@
 | 
				
			||||||
 | 
					import { SPACING_UNIT } from "@renderer/theme.css";
 | 
				
			||||||
 | 
					import { UserFriend } from "@types";
 | 
				
			||||||
 | 
					import { useEffect, useState } from "react";
 | 
				
			||||||
 | 
					import { useNavigate } from "react-router-dom";
 | 
				
			||||||
 | 
					import { useToast, useUserDetails } from "@renderer/hooks";
 | 
				
			||||||
 | 
					import { useTranslation } from "react-i18next";
 | 
				
			||||||
 | 
					import { UserFriendItem } from "@renderer/pages/shared-modals/user-friend-modal/user-friend-item";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface UserEditProfileBlockListProps {
 | 
				
			||||||
 | 
					  closeModal: () => void;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const pageSize = 12;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const UserEditProfileBlockList = ({
 | 
				
			||||||
 | 
					  closeModal,
 | 
				
			||||||
 | 
					}: UserEditProfileBlockListProps) => {
 | 
				
			||||||
 | 
					  const { t } = useTranslation("user_profile");
 | 
				
			||||||
 | 
					  const { showErrorToast } = useToast();
 | 
				
			||||||
 | 
					  const navigate = useNavigate();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const [page, setPage] = useState(0);
 | 
				
			||||||
 | 
					  const [maxPage, setMaxPage] = useState(0);
 | 
				
			||||||
 | 
					  const [blocks, setBlocks] = useState<UserFriend[]>([]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const { unblockUser } = useUserDetails();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const loadNextPage = () => {
 | 
				
			||||||
 | 
					    if (page > maxPage) return;
 | 
				
			||||||
 | 
					    window.electron
 | 
				
			||||||
 | 
					      .getUserBlocks(pageSize, page * pageSize)
 | 
				
			||||||
 | 
					      .then((newPage) => {
 | 
				
			||||||
 | 
					        if (page === 0) {
 | 
				
			||||||
 | 
					          setMaxPage(newPage.totalBlocks / pageSize);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        setBlocks([...blocks, ...newPage.blocks]);
 | 
				
			||||||
 | 
					        setPage(page + 1);
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					      .catch(() => {});
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const reloadList = () => {
 | 
				
			||||||
 | 
					    setPage(0);
 | 
				
			||||||
 | 
					    setMaxPage(0);
 | 
				
			||||||
 | 
					    setBlocks([]);
 | 
				
			||||||
 | 
					    loadNextPage();
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  useEffect(() => {
 | 
				
			||||||
 | 
					    reloadList();
 | 
				
			||||||
 | 
					  }, []);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const handleClickBlocked = (userId: string) => {
 | 
				
			||||||
 | 
					    closeModal();
 | 
				
			||||||
 | 
					    navigate(`/user/${userId}`);
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const handleUnblock = (userId: string) => {
 | 
				
			||||||
 | 
					    unblockUser(userId)
 | 
				
			||||||
 | 
					      .then(() => {
 | 
				
			||||||
 | 
					        reloadList();
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					      .catch(() => {
 | 
				
			||||||
 | 
					        showErrorToast(t("try_again"));
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return (
 | 
				
			||||||
 | 
					    <div
 | 
				
			||||||
 | 
					      style={{
 | 
				
			||||||
 | 
					        display: "flex",
 | 
				
			||||||
 | 
					        flexDirection: "column",
 | 
				
			||||||
 | 
					        gap: `${SPACING_UNIT * 2}px`,
 | 
				
			||||||
 | 
					      }}
 | 
				
			||||||
 | 
					    >
 | 
				
			||||||
 | 
					      {blocks.map((friend) => {
 | 
				
			||||||
 | 
					        return (
 | 
				
			||||||
 | 
					          <UserFriendItem
 | 
				
			||||||
 | 
					            userId={friend.id}
 | 
				
			||||||
 | 
					            displayName={friend.displayName}
 | 
				
			||||||
 | 
					            profileImageUrl={friend.profileImageUrl}
 | 
				
			||||||
 | 
					            onClickItem={handleClickBlocked}
 | 
				
			||||||
 | 
					            onClickUndoFriendship={handleUnblock}
 | 
				
			||||||
 | 
					            type={"ACCEPTED"}
 | 
				
			||||||
 | 
					            key={friend.id}
 | 
				
			||||||
 | 
					          />
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					      })}
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -4,8 +4,9 @@ import { SPACING_UNIT } from "@renderer/theme.css";
 | 
				
			||||||
import { useState } from "react";
 | 
					import { useState } from "react";
 | 
				
			||||||
import { useTranslation } from "react-i18next";
 | 
					import { useTranslation } from "react-i18next";
 | 
				
			||||||
import { UserEditProfile } from "./user-edit-profile";
 | 
					import { UserEditProfile } from "./user-edit-profile";
 | 
				
			||||||
 | 
					import { UserEditProfileBlockList } from "./user-block-list";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface UserEditProfileModalProps {
 | 
					export interface UserProfileSettingsModalProps {
 | 
				
			||||||
  userProfile: UserProfile;
 | 
					  userProfile: UserProfile;
 | 
				
			||||||
  visible: boolean;
 | 
					  visible: boolean;
 | 
				
			||||||
  onClose: () => void;
 | 
					  onClose: () => void;
 | 
				
			||||||
| 
						 | 
					@ -17,7 +18,7 @@ export const UserProfileSettingsModal = ({
 | 
				
			||||||
  visible,
 | 
					  visible,
 | 
				
			||||||
  onClose,
 | 
					  onClose,
 | 
				
			||||||
  updateUserProfile,
 | 
					  updateUserProfile,
 | 
				
			||||||
}: UserEditProfileModalProps) => {
 | 
					}: UserProfileSettingsModalProps) => {
 | 
				
			||||||
  const { t } = useTranslation("user_profile");
 | 
					  const { t } = useTranslation("user_profile");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const tabs = [t("edit_profile"), t("blocked_users")];
 | 
					  const tabs = [t("edit_profile"), t("blocked_users")];
 | 
				
			||||||
| 
						 | 
					@ -35,7 +36,7 @@ export const UserProfileSettingsModal = ({
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (currentTabIndex == 1) {
 | 
					    if (currentTabIndex == 1) {
 | 
				
			||||||
      return <></>;
 | 
					      return <UserEditProfileBlockList closeModal={onClose} />;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return <></>;
 | 
					    return <></>;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -282,6 +282,11 @@ export interface UserFriends {
 | 
				
			||||||
  friends: UserFriend[];
 | 
					  friends: UserFriend[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface UserBlocks {
 | 
				
			||||||
 | 
					  totalBlocks: number;
 | 
				
			||||||
 | 
					  blocks: UserFriend[];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface FriendRequest {
 | 
					export interface FriendRequest {
 | 
				
			||||||
  id: string;
 | 
					  id: string;
 | 
				
			||||||
  displayName: string;
 | 
					  displayName: string;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue