Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/v3' into release/v3.11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ChayanitBm committed Nov 21, 2024
2 parents 096f0fc + 258afeb commit e6bff96
Show file tree
Hide file tree
Showing 24 changed files with 114 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"react-hook-form": "^7.49.2",
"react-infinite-scroll-component": "^6.1.0",
"react-insta-stories": "^2.6.2",
"react-intl": "^6.5.5",
"react-intl": "^6.8.7",
"react-loading-skeleton": "^3.3.1",
"react-mentions": "^4.4.10",
"react-modal-sheet": "^2.2.0",
Expand Down
12 changes: 9 additions & 3 deletions src/core/components/Button/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const commonButtonStyles = ({ theme }: { theme: DefaultTheme }) => css<{ fullWid
}
`;

export const DefaultButton = styled.button<{ fullWidth?: boolean }>`
export const DefaultButton = styled.button.withConfig({
shouldForwardProp: (prop) => prop !== 'fullWidth',
})<{ fullWidth?: boolean }>`
${commonButtonStyles};
background-color: #fff;
border: 1px solid #e3e4e8;
Expand All @@ -32,7 +34,9 @@ export const DefaultButton = styled.button<{ fullWidth?: boolean }>`
}
`;

export const PrimaryButton = styled.button<{ fullWidth?: boolean }>`
export const PrimaryButton = styled.button.withConfig({
shouldForwardProp: (prop) => prop !== 'fullWidth',
})<{ fullWidth?: boolean }>`
${commonButtonStyles};
border: none;
background-color: ${({ theme }) => theme.palette.primary.main};
Expand All @@ -45,7 +49,9 @@ export const PrimaryButton = styled.button<{ fullWidth?: boolean }>`
}
`;

export const SecondaryButton = styled.button<{ active?: boolean; fullWidth?: boolean }>`
export const SecondaryButton = styled.button.withConfig({
shouldForwardProp: (prop) => prop !== 'active' && prop !== 'fullWidth',
})<{ active?: boolean; fullWidth?: boolean }>`
${commonButtonStyles};
color: ${({ theme }) => theme.palette.neutral.shade1};
background-color: transparent;
Expand Down
4 changes: 3 additions & 1 deletion src/core/components/HorizontalList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ function findColumnByWidth(width: number, columns: { [width: number]: number })
return founded[1];
}

const StretchedList = styled.div<{ currentWidth: number; columns: { [width: number]: number } }>`
const StretchedList = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'currentWidth' && prop !== 'columns',
})<{ currentWidth: number; columns: { [width: number]: number } }>`
margin-bottom: 0.188rem; // give the shadow a little space
display: grid;
grid-auto-flow: column;
Expand Down
4 changes: 3 additions & 1 deletion src/core/components/OptionMenu/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const Option = styled.div<{ active?: boolean }>`
}
`;

export const Container = styled.div<{ pullRight?: boolean }>`
export const Container = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'pullRight',
})<{ pullRight?: boolean }>`
${({ pullRight }) => pullRight && `margin-left: auto;`}
`;
4 changes: 3 additions & 1 deletion src/core/components/SideBar/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export const MenuName = styled.div`
white-space: normal;
`;

export const MenuTabContainer = styled.div<{ active?: boolean }>`
export const MenuTabContainer = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'active',
})<{ active?: boolean }>`
flex-direction: column;
display: flex;
align-items: center;
Expand Down
4 changes: 3 additions & 1 deletion src/core/components/SideMenuActionItem/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export const AnchorActionItem = styled.a<{ active?: boolean }>`
`};
`;

export const IconWrapper = styled.div<{ active?: boolean }>`
export const IconWrapper = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'active',
})<{ active?: boolean }>`
width: 40px;
height: 40px;
border-radius: 4px;
Expand Down
5 changes: 4 additions & 1 deletion src/core/components/SideMenuItem/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ export const SideMenuItemContainer = styled(SecondaryButton)`
`}
`;

export const IconWrapper = styled.div<{ active?: boolean }>`
export const IconWrapper = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'active',
})<{ active?: boolean }>`
width: 40px;
height: 40px;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
margin-right: 8px;
${({ active, theme }) =>
active
? css`
Expand Down
8 changes: 7 additions & 1 deletion src/core/components/Time/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ export interface TimeProps {
}

const Time = ({ className, date = Date.now() }: TimeProps) => {
const isValidDate = !isNaN(date) && new Date(date).getTime() > 0;
const delta = Date.now() - date;

return (
<DateContainer className={className}>
{delta < DAY ? <TimeAgo date={date} /> : <FormattedDate value={date} />}
{isValidDate &&
(delta < DAY ? (
<TimeAgo date={new Date(date)} />
) : (
<FormattedDate value={new Date(date)} />
))}
</DateContainer>
);
};
Expand Down
14 changes: 10 additions & 4 deletions src/core/components/Uploaders/Image/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import Skeleton from '~/core/components/Skeleton';
import RemoveIcon from '~/icons/Remove';
import ExclamationCircle from '~/icons/ExclamationCircle';

export const ImageContainer = styled.div<{ border?: boolean }>`
export const ImageContainer = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'border',
})<{ border?: boolean }>`
position: relative;
display: inline-block;
min-width: 2em;
Expand Down Expand Up @@ -38,9 +40,13 @@ const ImgPreviewContainerStyles = css<{ mediaFit?: string; loading?: string }>`
object-position: center;
`;

export const ImgPreview = styled.img.attrs<{ mediaFit?: string; loading?: string }>({
loading: 'lazy',
})`
export const ImgPreview = styled.img
.withConfig({
shouldForwardProp: (prop) => prop !== 'mediaFit',
})
.attrs<{ mediaFit?: string; loading?: string }>({
loading: 'lazy',
})`
${ImgPreviewContainerStyles}
`;

Expand Down
4 changes: 3 additions & 1 deletion src/core/components/Uploaders/Video/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import LiveBadge from '~/social/components/LiveBadge';

import { ExclamationCircle, Play, Remove } from '~/icons';

export const VideoContainer = styled.div<{ border?: boolean }>`
export const VideoContainer = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'border',
})<{ border?: boolean }>`
position: relative;
display: inline-block;
min-width: 2em;
Expand Down
4 changes: 3 additions & 1 deletion src/social/components/CommunityInfo/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export const Container = styled.div`
margin-bottom: 12px;
`;

export const Cover = styled.div<{ backgroundImage?: string }>`
export const Cover = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'backgroundImage',
})<{ backgroundImage?: string }>`
padding-top: 56.25%;
position: relative;
Expand Down
4 changes: 3 additions & 1 deletion src/social/components/SocialSearch/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const SearchIcon = styled(Search).attrs({ width: 16, height: 16 })`
fill: ${({ theme }) => theme.palette.base.shade2};
`;

export const SocialSearchContainer = styled.div<{ sticky?: boolean }>`
export const SocialSearchContainer = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'sticky',
})<{ sticky?: boolean }>`
position: relative;
${({ sticky }) =>
Expand Down
4 changes: 3 additions & 1 deletion src/social/components/community/Card/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const Container = styled.div`
overflow: hidden;
`;

export const Cover = styled.div<{ backgroundImage?: string }>`
export const Cover = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'backgroundImage',
})<{ backgroundImage?: string }>`
padding-top: 74.46%;
position: relative;
Expand Down
4 changes: 3 additions & 1 deletion src/social/components/community/CategoryCard/styles.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import styled from 'styled-components';

export const Container = styled.div<{ backgroundImage?: string }>`
export const Container = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'backgroundImage',
})<{ backgroundImage?: string }>`
min-width: 160px;
min-height: 150px;
cursor: pointer;
Expand Down
6 changes: 3 additions & 3 deletions src/social/components/community/Header/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ interface CommunityHeaderContainerProps {
isActive?: boolean;
}

export const CommunityHeaderContainer = styled.a.attrs(
(props) => props,
)<CommunityHeaderContainerProps>`
export const CommunityHeaderContainer = styled.a.withConfig({
shouldForwardProp: (prop) => !['loading', 'isActive'].includes(prop),
})<CommunityHeaderContainerProps>`
display: grid;
grid-template-areas: 'avatar title' 'avatar children';
grid-template-columns: min-content auto;
Expand Down
4 changes: 3 additions & 1 deletion src/social/components/community/Name/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export const Name = styled.div`
padding-right: 1ch;
`;

export const NameContainer = styled.div<{
export const NameContainer = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'isActive' && prop !== 'isTitle',
})<{
isActive?: boolean;
isTitle?: boolean;
}>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const ItemContainer = styled.div`
overflow: hidden;
`;

const Cover = styled.div<{ backgroundImage?: string }>`
const Cover = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'backgroundImage',
})<{ backgroundImage?: string }>`
padding-left: 100%;
${({ backgroundImage, theme }) => `
Expand Down
2 changes: 1 addition & 1 deletion src/social/components/post/ChildrenContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ChildrenContent = ({ contents }: { contents: Amity.Post[] }) => {
return (
<>
{items.map((poll) => (
<PollContent key={dataType} pollId={poll.data.pollId} />
<PollContent key={poll.data.pollId} pollId={poll.data.pollId} />
))}
</>
);
Expand Down
1 change: 1 addition & 0 deletions src/social/components/post/GalleryContent/ImageItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface ThumbnailProps {
export const Thumbnail = ({ item }: ThumbnailProps) => {
return (
<Image
key={item?.data.fileId}
fileId={item?.data.fileId}
data-qa-anchor="post-gallery-content-image-thumbnail-item"
mediaFit="cover"
Expand Down
1 change: 1 addition & 0 deletions src/social/components/post/GalleryContent/StreamItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const Thumbnail = ({

return (
<LivestreamThumbnail
key={stream.streamId}
duration={mp4Recording?.duration}
fileId={file?.fileId}
overlayElements={
Expand Down
1 change: 1 addition & 0 deletions src/social/components/post/GalleryContent/VideoItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface ThumbnailProps {
export const Thumbnail = ({ item, showPlayIcon, showVideoDuration }: ThumbnailProps) => {
return (
<VideoThumbnail
key={item?.data.thumbnailFileId}
fileId={item?.data.thumbnailFileId}
showPlayIcon={showPlayIcon}
videoFileId={showVideoDuration && item?.data.videoFileId.original}
Expand Down
4 changes: 3 additions & 1 deletion src/social/components/post/Header/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export const MessageContainer = styled.div`
}
`;

export const AdditionalInfo = styled.div<{ showTime?: boolean }>`
export const AdditionalInfo = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'showTime',
})<{ showTime?: boolean }>`
display: flex;
align-items: center;
Expand Down
8 changes: 6 additions & 2 deletions src/social/pages/NewsFeed/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export const MobileContainer = styled.div`
}
`;

export const CommunitySideMenuOverlay = styled.div<{ isOpen: boolean }>`
export const CommunitySideMenuOverlay = styled.div.withConfig({
shouldForwardProp: (prop) => prop !== 'isOpen',
})<{ isOpen?: boolean }>`
position: fixed;
top: 0;
left: 0;
Expand All @@ -48,7 +50,9 @@ export const CommunitySideMenuOverlay = styled.div<{ isOpen: boolean }>`
cursor: pointer;
`;

export const StyledCommunitySideMenu = styled(CommunitySideMenu)<{ isOpen: boolean }>`
export const StyledCommunitySideMenu = styled(CommunitySideMenu).withConfig({
shouldForwardProp: (prop) => prop !== 'isOpen',
})<{ isOpen?: boolean }>`
position: fixed;
top: 0;
left: 0;
Expand Down
34 changes: 34 additions & 0 deletions src/v4/social/hooks/useVisibilitySensor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { RefObject, useEffect, useState } from 'react';

interface UseVisibilitySensorProps {
threshold: number;
elementRef: RefObject<HTMLDivElement>;
}

export const useVisibilitySensor = ({ threshold, elementRef }: UseVisibilitySensorProps) => {
const [isVisible, setIsVisible] = useState(false);

useEffect(() => {
if (!elementRef.current) return;

const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
const isIntersecting = entry.isIntersecting;
setIsVisible(isIntersecting);
});
},
{
threshold: threshold,
},
);

observer.observe(elementRef.current);

return () => {
observer.disconnect();
};
}, [threshold, elementRef]);

return { isVisible };
};

0 comments on commit e6bff96

Please sign in to comment.