Skip to content

Commit

Permalink
✨ (block): view block list + add/remove users from block list (#44)
Browse files Browse the repository at this point in the history
* ✨ (privacy-settings): View block list finished

* ✨ (block): add/remove user from block list

* 💄 (block):  adding scrollbar styling

* 🔀 Merging dev

* 🐛 fixing merging bugs
  • Loading branch information
AbdelruhmanSamy authored Nov 8, 2024
1 parent 53adca8 commit 19c9739
Show file tree
Hide file tree
Showing 31 changed files with 512 additions and 46 deletions.
3 changes: 2 additions & 1 deletion app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import Signup from "./pages/Signup";
import ResetPasswordModal from "@features/authentication/reset-password/ResetPasswordModal";
import ProtectedRoute from "@components/protected-route/ProtectedRoute";
import AppLayout from "@components/AppLayout";
import ChatBox from "@features/Chats/ChatBox";
import ChatBox from "@features/chats/ChatBox";

const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 0,
retry: 3,
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/side-bar/ContactsSideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function ContactsSideBar({ children }: ContactsSideBarProps) {
<ContactsSidebarHeader />
{children}
<CircleIcon
$icon="AddContacts"
$icon="Add"
$right={1}
$bottom={1}
$size={3.3}
Expand Down
8 changes: 7 additions & 1 deletion app/src/components/side-bar/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { RadioInputProps } from "@components/inputs/radio-input/RadioInput";
import { SideBarRowProps } from "./settings/side-bar-row/SideBarRow";
import ProfileSettings from "@features/profile-settings/ProfileSettings";
import ProfileInfo from "@features/profile-info/ProfileInfo";
import ChatList from "@features/Chats/ChatsList";
import ChatList from "@features/chats/ChatsList";

import { useAppSelector } from "@hooks/useGlobalState";
import BlockList from "@features/privacy-settings/BlockList";

interface SideBarProps {
rows?: SideBarRowProps[];
Expand Down Expand Up @@ -81,6 +82,11 @@ const sideBarMap: { [key: string]: (props: SideBarProps) => React.ReactNode } =
</SettingsSideBar>
),
ProfileUpdate: () => <ProfileSettings />,
blockList: () => (
<SettingsSideBar rows={[]}>
<BlockList />
</SettingsSideBar>
),
};

function Sidebar() {
Expand Down
13 changes: 1 addition & 12 deletions app/src/components/side-bar/settings/side-bar-row/SideBarRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,16 @@ interface SideBarRowProps {
title: string;
type?: StatusType;
status?: activitySettingsID | privacySettingsID | permissionSettingsID;
count?: number;
redirect?: number;
id: number;
}

function SideBarRow({
redirect,
icon,
title,
status,
count,
type,
}: SideBarRowProps) {
function SideBarRow({ redirect, icon, title, status, type }: SideBarRowProps) {
const userData = useAppSelector((state) => state.user);
const dispatch = useAppDispatch();
const renderedIcon = getIcon(icon);


const [currStatus, setCurrStatus] = useState<string | undefined>(undefined);

let key:
| {
id: keyof privacySettingsInterface;
Expand Down Expand Up @@ -145,7 +135,6 @@ function SideBarRow({
<Heading as="h5">{title}</Heading>
)}
</RowInfo>
{count && <StyledP>{count}</StyledP>}
</StyledSideBarRow>
);
}
Expand Down
13 changes: 11 additions & 2 deletions app/src/data/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import AddIcon from "@mui/icons-material/Add";
import CloseOutlinedIcon from "@mui/icons-material/CloseOutlined";
import VisibilityIcon from "@mui/icons-material/Visibility";
import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";
import NoEncryptionOutlinedIcon from "@mui/icons-material/NoEncryptionOutlined";
import KeyboardVoiceIcon from "@mui/icons-material/KeyboardVoice";
import AttachFileIcon from "@mui/icons-material/AttachFile";
import SentimentSatisfiedAltIcon from "@mui/icons-material/SentimentSatisfiedAlt";
Expand All @@ -36,7 +37,7 @@ enum icons {
Contacts,
Settings,
NightMode,
AddContacts,
Add,
Edit,
AddStory,
Logout,
Expand All @@ -47,6 +48,7 @@ enum icons {
Close,
Show,
Hide,
Unlock,
Record,
Attatch,
Emojie,
Expand Down Expand Up @@ -101,7 +103,7 @@ const iconMap: { [K in iconStrings]: React.ReactNode } = {
}}
/>
),
AddContacts: (
Add: (
<AddIcon fontSize="large" sx={{ color: `var(--color-search-border)` }} />
),
Edit: (
Expand Down Expand Up @@ -161,6 +163,13 @@ const iconMap: { [K in iconStrings]: React.ReactNode } = {
sx={{ color: `var(--color-icon-secondary)` }}
/>
),
Unlock: (
<NoEncryptionOutlinedIcon
sx={{
color: `var(--color-icon-secondary)`,
}}
/>
),

Record: <KeyboardVoiceIcon sx={{ fontSize: "1rem" }} />,

Expand Down
15 changes: 14 additions & 1 deletion app/src/data/sideBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const pagesMap: { [K in pagesStrings]: string } = {
PRIVACY_SETTINGS: "Privacy",
SETTINGS_UPDATE: "SettingsUpdate",
PROFILE_UPDATE: "ProfileUpdate",
BLOCKED_USERS: "blockList",
};

const settingsRows = [
Expand All @@ -101,7 +102,7 @@ const privacySettingsRows = [
{
icon: "BlockIcon",
title: "Blocked Users",
count: 2,
redirect: sideBarPages.BLOCKED_USERS,
},
{
title: "Who can see my stories?",
Expand Down Expand Up @@ -173,6 +174,17 @@ const profileUpdate: SideBarView = {
backView: sideBarPages.SETTINGS,
page: "PROFILE_UPDATE",
};

const blockList: SideBarView = {
title: "Blocked Users",
backView: sideBarPages.PRIVACY_SETTINGS,
page: "BLOCKED_USERS",
props: {
subtitle:
"Blocked users can't send you messages or add you to groups. They will not see your profile photos, stories, online and last seen status.",
},
};

export {
chats,
contacts,
Expand All @@ -188,4 +200,5 @@ export {
settingsUpdate,
profileUpdate,
pagesMap,
blockList,
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ChatInput from "@features/Chats/ChatInput";
import Topbar from "@features/Chats/Topbar";
import ChatInput from "@features/chats/ChatInput";
import Topbar from "@features/chats/Topbar";

import { useCloseChat } from "@hooks/useCloseChat";

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import styled from "styled-components";

import { getIcon } from "@data/icons";

import Avatar from "@features/Chats/Avatar";
import Avatar from "@features/chats/Avatar";
import Icon from "@components/Icon";

import { useChat } from "@features/Chats/hooks/useChat";
import { useChat } from "@features/chats/hooks/useChat";

const Container = styled.div`
position: absolute;
Expand Down
File renamed without changes.
File renamed without changes.
96 changes: 96 additions & 0 deletions app/src/features/privacy-settings/AddToBlockMenuList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import styled from "styled-components";
import BlockItem, { BlockedUserProps } from "./BlockItem";
import { useBlock } from "./hooks/useBlock";
import { ScrollContainer } from "styles/GlobalStyles";
import { useChats } from "@features/chats/hooks/useChats";
import { Chat } from "@mocks/data/chats";

const StyledList = styled.ul<StyledListProps>`
position: absolute;
width: ${(props) => props.$size}%;
right: ${(props) => (props.$right ?? 3) + 2}rem;
bottom: ${(props) => (props.$bottom ?? 3) + 3}rem;
height: ${(props) => (props.$height ?? 3) + 3}rem;
z-index: 1;
overflow: auto;
display: flex;
flex-direction: column;
gap: 1rem;
justify-content: center;
align-items: start;
list-style: none;
padding: 0.2rem 0.2rem;
background-color: var(--color-background);
box-shadow: var(--box-shadow);
box-shadow: var(--box-shadow);
border-radius: var(--border-radius-default);
`;


interface StyledListProps {
$bottom?: number;
$right?: number;
$size?: number;
$height?: number;
}

const menuStyles: StyledListProps = {
$bottom: 5,
$right: 4,
$size: 70,
$height: 30,
};

const StylingWrapper = styled.div`
width: 100%;
`;

function filterChats(blockList: BlockedUserProps[], chats: Chat[]) {
const blockIds = blockList
? new Set(blockList.map((val) => val.id))
: new Set();
const filteredChats = chats?.filter((item) => !blockIds.has(item.id));

return filteredChats;
}

function AddToBlockMenuList({ setIsMenuOpened }: any) {
const { addToBlockList } = useBlock();

const { blockList } = useBlock();
const { chats } = useChats();

const filteredChats = filterChats(
blockList as BlockedUserProps[],
chats as Chat[]
);

function handleClick(item: Chat) {
setIsMenuOpened(false);
addToBlockList({ id: item.id.toString() });
}

return (
<StyledList {...menuStyles}>
<ScrollContainer>
{filteredChats?.map((item) => {
const data: BlockedUserProps = {
name: item.name,
id: item.id,
username: item.name.toLowerCase() + 123,
};
return (
<StylingWrapper onClick={() => handleClick(item)} key={data.id}>
<BlockItem {...data} />
</StylingWrapper>
);
})}
</ScrollContainer>
</StyledList>
);
}

export default AddToBlockMenuList;
export { StyledList };
export type { StyledListProps };
Loading

0 comments on commit 19c9739

Please sign in to comment.