Skip to content

Commit

Permalink
Merge pull request #154 from us3r-network/F-channelTagFilter-ttang
Browse files Browse the repository at this point in the history
feat: channel tag filter
  • Loading branch information
Tonyce authored Oct 12, 2023
2 parents 1bd004a + a5b6765 commit 9a7cf87
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 36 deletions.
26 changes: 15 additions & 11 deletions apps/u3/src/components/social/AddPostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import useLogin from '../../hooks/useLogin';
import getAvatar from '../../utils/lens/getAvatar';
import { Channel } from '../../services/types/farcaster';
import ChannelSelect from './ChannelSelect';
import { getChannelFromName } from '../../utils/social/getChannel';

export default function AddPostForm({
onSuccess,
Expand Down Expand Up @@ -141,6 +142,11 @@ export default function AddPostForm({
const handleSubmitToFarcaster = useCallback(async () => {
if (!text || !encryptedSigner) return;
const currFid = getCurrFid();
let parentUrl;
if (channelValue !== 'Home') {
const ch = getChannelFromName(channelValue);
parentUrl = ch?.parent_url;
}
try {
const uploadedLinks = await uploadSelectedImages();
// eslint-disable-next-line no-underscore-dangle
Expand All @@ -152,8 +158,7 @@ export default function AddPostForm({
embedsDeprecated: [],
mentions: [],
mentionsPositions: [],
parentUrl:
channelValue === 'Home' ? undefined : channel?.parent_url,
parentUrl,
},
{ fid: currFid, network: FARCASTER_NETWORK },
encryptedSigner
Expand Down Expand Up @@ -330,15 +335,14 @@ export default function AddPostForm({
<SendEmojiBtn disabled>
<EmojiIcon />
</SendEmojiBtn>
{channel && (
<ChannelSelect
channel={channel}
selectChannelName={channelValue}
setSelectChannelName={(v) => {
setChannelValue(v);
}}
/>
)}

<ChannelSelect
channel={channel}
selectChannelName={channelValue}
setSelectChannelName={(v) => {
setChannelValue(v);
}}
/>
<Description
hidden={
!(
Expand Down
66 changes: 44 additions & 22 deletions apps/u3/src/components/social/ChannelSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
SelectValue,
} from 'react-aria-components';
import ArrowDown from '../icons/ArrowDown';
import ChannelHome from '../icons/ChannelHome';
import { getChannel } from '../../utils/social/getChannel';

export default function ChannelSelect({
channel,
Expand All @@ -21,24 +21,28 @@ export default function ChannelSelect({
selectChannelName: string;
setSelectChannelName: (name: string) => void;
}) {
// const [value, setValue] = useState('Home');
const [value, setValue] = useState('');
const options = useMemo(() => {
return [
{
name: 'Home',
image: '',
image: '/social/imgs/channel-home.png',
},
{
name: channel.name || channel.channel_description,
image: channel.image,
},
];
}, [channel]);
...getChannel().map((c) => ({
name: c.name || c.channel_description,
image: c.image,
})),
].filter((c) => {
return c.name.toLowerCase().includes(value.toLowerCase());
});
}, [channel, value]);

return (
<SelectStyled
selectedKey={selectChannelName}
onSelectionChange={(k) => {
setSelectChannelName(k as string);
setValue('');
}}
aria-label="Select a channel"
>
Expand All @@ -47,19 +51,22 @@ export default function ChannelSelect({
<ArrowDown />
</ButtonStyled>
<PopoverStyled>
<input
type="text"
placeholder="search for trends"
value={value}
onChange={(e) => {
setValue(e.target.value);
}}
/>
<ListBox items={options}>
{(item) => (
<ItemStyled id={item.name} textValue={item.name}>
<div className="item">
{(item.image && (
<span>
<img src={item.image} alt={item.name} />
</span>
)) || (
<span>
<ChannelHome />
</span>
)}
<span>#</span>
<span>
<img src={item.image} alt={item.name} />
</span>
<span>{item.name}</span>
</div>
</ItemStyled>
Expand All @@ -78,7 +85,7 @@ const SelectStyled = styled(Select)`
font-size: 16px;
line-height: 24px;
position: relative;
width: 100px;
width: 130px;
> span {
font-weight: 500;
font-size: 16px;
Expand All @@ -92,7 +99,7 @@ const ButtonStyled = styled(Button)`
cursor: pointer;
border: none;
padding: 5px;
width: 100px;
width: 130px;
border-radius: 4px;
height: 20px;
display: inline-flex;
Expand Down Expand Up @@ -125,6 +132,7 @@ const ButtonStyled = styled(Button)`
> img {
width: 12px;
height: 12px;
border-radius: 2px;
}
}
}
Expand All @@ -133,9 +141,10 @@ const ButtonStyled = styled(Button)`
const PopoverStyled = styled(Popover)`
background: #1b1e23;
border: none;
width: 100px;
width: 130px;
border-radius: 10px;
overflow: scroll;
margin-top: 3px;
&[data-placement='top'] {
--origin: translateY(4px);
}
Expand Down Expand Up @@ -163,6 +172,18 @@ const PopoverStyled = styled(Popover)`
opacity: 1;
}
}
input {
background-color: inherit;
border: none;
outline: none;
font-size: 13px;
padding: 5px;
width: 100%;
box-sizing: border-box;
caret-color: #fff;
color: #fff;
}
`;

const ItemStyled = styled(Item)`
Expand Down Expand Up @@ -216,6 +237,7 @@ const ItemStyled = styled(Item)`
width: 10px;
height: 10px;
margin: 1px;
border-radius: 2px;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/u3/src/components/social/SocialPageNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components';
import { useNavigate } from 'react-router-dom';
import MobilePageHeader from '../common/mobile/MobilePageHeader';
import { ArrowLeft } from '../icons/ArrowLeft';
import { getChannelFormName } from '../../utils/social/getChannel';
import { getChannelFromName } from '../../utils/social/getChannel';

export enum FeedsType {
FOLLOWING = 'following',
Expand Down Expand Up @@ -54,7 +54,7 @@ export function SocialBackNav({
isChannel?: boolean;
}) {
const navigate = useNavigate();
const channel = isChannel ? getChannelFormName(title) : null;
const channel = isChannel ? getChannelFromName(title) : null;
return (
<SocialNavWrapper>
{!isMobile && (
Expand Down
2 changes: 1 addition & 1 deletion apps/u3/src/utils/social/getChannel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import FarcasterChannelData from '../../constants/warpcast.json';

export function getChannelFormName(name: string) {
export function getChannelFromName(name: string) {
const channel = FarcasterChannelData.find(
(c) => c.name === name || c.channel_description === name
);
Expand Down

0 comments on commit 9a7cf87

Please sign in to comment.