Skip to content

Commit

Permalink
fix: anonymous (#1800)
Browse files Browse the repository at this point in the history
* fix: handle anonymous home

* feat: redirect timeline on search to home
  • Loading branch information
nekaartajaya authored Apr 12, 2023
1 parent 59807dd commit 0d953a9
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 44 deletions.
3 changes: 1 addition & 2 deletions src/components/ExpericenceRightBar/Experience.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export const Experience: React.FC<ExperienceProps> = props => {
const isOwnExperience = userExperience.experience.user.id === user?.id;
const experienceId = userExperience.experience.id;
const userExperienceId = userExperience.id;
const link =
publicRuntimeConfig.appAuthURL + `?type=experience&id=${experienceId}`;
const link = publicRuntimeConfig.appAuthURL + `?type=all&id=${experienceId}`;
const { userExperiencesMeta } = useExperienceHook();
const totalOwnedExperience =
userExperiencesMeta.additionalData?.totalOwnedExperience ?? 0;
Expand Down
4 changes: 2 additions & 2 deletions src/components/ExperienceList/ExperienceList.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export const ExperienceListContainer: React.FC<ExperienceListContainerProps> =
) => {
router.push(
userExperience
? `/?type=experience&id=${userExperience.experience.id}`
: `/?type=experience`,
? `/?type=all&id=${userExperience.experience.id}`
: `/?type=all`,
undefined,
{
shallow: true,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ExperienceList/ExperienceListDiscover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const ExperienceListDiscover: React.FC<ExperienceListDiscoverProps> =

const handleSelectExperience =
(userExperience: WrappedExperience) => () => {
router.push(`/experience/${userExperience.experience.id}`);
router.push(`/?type=all&id=${userExperience.experience.id}`);
};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/ExperienceList/ExperienceListRightBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const ExperienceListRightBar: React.FC<ExperienceListProps> = props => {
const [selectedExperienceId, setSelectedExperienceId] = useState<string>();

useEffect(() => {
const experienceId = getIdByType('experience');
const experienceId = getIdByType('all');
const exists = experiences.find(
item => item.experience.id === experienceId,
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ExperiencePreview/ExperiencePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const ExperiencePreview: React.FC<Props> = props => {

const getSelectedIds = async (selected: SelectedUserIds[]) => {
setIsLoadingSelectedUser(true);
const userIds = selected.map(e => e.userId);
const userIds = selected?.map(e => e.userId);
const response = await UserAPI.getUserByIds(userIds, pageUserIds);
setSelectedUserIds([
...selectedUserIds,
Expand Down
31 changes: 17 additions & 14 deletions src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const Menu: React.FC<MenuProps> = props => {
const { query, replace } = useQueryParams();

const menu = useMenuList(
query.type && query.type === 'all' ? 'all' : 'timeline',
anonymous ? 'all' : query.type && query.type === 'all' ? 'all' : 'timeline',
);

const gotoHome = () => {
Expand Down Expand Up @@ -219,19 +219,22 @@ export const Menu: React.FC<MenuProps> = props => {

{menu
.filter(ar => ar.isDesktop === true)
.map(item => (
<ListItemComponent
data-testid={`list-item-${item.id}`}
id={item.id}
key={item.id}
title={item.title}
icon={item.icon}
active={router.pathname === '/' ? item.active : false}
onClick={async () => openMenu(item)}
url={item.url}
isAnimated={item.isAnimated}
/>
))}
.map(item => {
if (anonymous && !item.allowAnonymous) return;
return (
<ListItemComponent
data-testid={`list-item-${item.id}`}
id={item.id}
key={item.id}
title={item.title}
icon={item.icon}
active={router.pathname === '/' ? item.active : false}
onClick={async () => openMenu(item)}
url={item.url}
isAnimated={item.isAnimated}
/>
);
})}

<div style={{ padding: '0 30px', marginTop: '20px' }}>
<Button
Expand Down
3 changes: 3 additions & 0 deletions src/components/Menu/use-menu-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export type MenuDetail = {
url: string;
isDesktop: boolean;
isAnimated: boolean;
allowAnonymous: boolean;
};

export const useMenuList = (selected: MenuId): MenuDetail[] => {
Expand All @@ -154,6 +155,7 @@ export const useMenuList = (selected: MenuId): MenuDetail[] => {
url: '/',
isDesktop: true,
isAnimated: false,
allowAnonymous: false,
},
{
id: 'all',
Expand All @@ -163,6 +165,7 @@ export const useMenuList = (selected: MenuId): MenuDetail[] => {
url: '/all',
isDesktop: true,
isAnimated: false,
allowAnonymous: true,
},
],
[selected],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ export const ExperienceInfo: React.FC<ExperienceInfo> = props => {
&nbsp;• {i18n.t('Post_Detail.Experience.Added')}&nbsp;
{!!experiences && !!experiences.length && (
<>
<Link
href={`/?type=experience&id=${experiences[0].id}`}
shallow
passHref>
<Link href={`/?type=all&id=${experiences[0].id}`} shallow passHref>
<span className={style.link}>{experiences[0].name}</span>
</Link>
<ShowIf condition={totalExperience > 1}>
Expand Down
4 changes: 3 additions & 1 deletion src/components/PostList/PostList.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const PostsListContainer: React.FC<PostsListContainerProps> = props => {

useEffect(() => {
clear();
if (!user) filterTimeline({ ...query, timelineType: TimelineType.ALL });
filterTimeline(query);

loadAllBlockedUser();
Expand All @@ -81,7 +82,8 @@ export const PostsListContainer: React.FC<PostsListContainerProps> = props => {
return (
<EmptyResult
emptyContent={
query.type && query.type === TimelineType.EXPERIENCE
(query.type && query.type === TimelineType.EXPERIENCE) ||
(!query.type && user)
? EmptyContentEnum.DISCOVER
: EmptyContentEnum.POST
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/PostList/hooks/use-timeline-filter.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const useTimelineFilter = (filters?: TimelineFilterFields) => {

const filterTimeline = useCallback(
async (query?: ParsedUrlQuery) => {
let timelineType = TimelineType.EXPERIENCE;
let timelineType = query.timelineType ?? TimelineType.EXPERIENCE;
let timelineOrder = TimelineOrderType.LATEST;
let tags: string[] = [];
let search: string;
Expand Down Expand Up @@ -111,7 +111,7 @@ export const useTimelineFilter = (filters?: TimelineFilterFields) => {
// TODO: anonymous user should only see trending posts
}

if (query?.type === TimelineType.EXPERIENCE && query?.id) {
if (query?.type === TimelineType.ALL && query?.id) {
const expFilterFields: TimelineFilterFields = {
...filterFields,
experienceId: query.id as string,
Expand All @@ -125,7 +125,7 @@ export const useTimelineFilter = (filters?: TimelineFilterFields) => {
order: timelineOrder,
query: search,
},
timelineType,
TimelineType.EXPERIENCE,
),
);
} else {
Expand Down
19 changes: 15 additions & 4 deletions src/components/RightMenuBar/RightMenuBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ const CustomFolderIcon = () => (
</svg>
);

export const RightMenuBar: React.FC = () => {
interface RightMenuBarProps {
anonymous?: boolean;
}

export const RightMenuBar: React.FC<RightMenuBarProps> = props => {
const { t } = useTranslation();
const { anonymous } = props;
const classes = useStyles();

const [activeTab, setActiveTab] = useState('experienceTabMenu');
const [activeTab, setActiveTab] = useState(
anonymous ? 'trendingExperienceTabPanel' : 'experienceTabMenu',
);

const handleChangeTab = (tab: string) => {
setActiveTab(tab);
Expand All @@ -76,6 +83,7 @@ export const RightMenuBar: React.FC = () => {
</div>
),
component: <ExperienceTab />,
allowAnonymous: false,
},
{
id: 'trendingExperienceTabPanel',
Expand All @@ -90,19 +98,22 @@ export const RightMenuBar: React.FC = () => {
</div>
),
component: <TrendingExperienceTab />,
allowAnonymous: true,
},
];

return (
<div className={classes.root}>
<TabsComponent
selected={activeTab}
tabs={iconTabs}
tabs={
anonymous ? iconTabs.filter(item => item.allowAnonymous) : iconTabs
}
position="space-between"
mark="cover"
size="medium"
onChangeTab={handleChangeTab}
width={'48%'}
width={anonymous ? '100%' : '48%'}
/>
</div>
);
Expand Down
3 changes: 1 addition & 2 deletions src/components/Timeline/Render/ExperienceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ export const ExperienceCard: React.FC<ExperienceCardProps> = props => {
useState<null | HTMLElement>(null);
const { userExperiencesMeta, removeExperience, loadExperience } =
useExperienceHook();
const link =
publicRuntimeConfig.appAuthURL + `?type=experience&id=${experience.id}`;
const link = publicRuntimeConfig.appAuthURL + `?type=all&id=${experience.id}`;
const isOwnExperience = experience?.createdBy === user?.id;
const isHidden = () => {
if (experience.private && !experience.friend) return true;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Timeline/Timeline.layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const Timeline: React.FC<TimelineContainerProps> = props => {
}, []);

useEffect(() => {
if (query.type === 'experience') {
if (query.type === 'all') {
query.id && getExperienceDetail(query.id);
}
}, [query.id]);
Expand All @@ -52,7 +52,7 @@ export const Timeline: React.FC<TimelineContainerProps> = props => {
</Grid>

<TimelineAutoReloader />
{query.type === 'experience' && query.id && experience && (
{query.type === 'all' && query.id && experience && (
<ExperienceCard
experience={experience}
userExperiences={userExperiences}
Expand Down
7 changes: 5 additions & 2 deletions src/components/TimelineFilter/TimelineFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type TimelineFilterProps = {

export const TimelineFilter: React.FC<TimelineFilterProps> = props => {
const {
user,
order,
originType,
filterType,
Expand All @@ -58,13 +59,15 @@ export const TimelineFilter: React.FC<TimelineFilterProps> = props => {
<div className={styles.itemContainer}>
<div>
<SvgIcon
component={query.type === 'all' ? GlobeAltIcon : CustomFolderIcon}
component={
query.type === 'all' || !user ? GlobeAltIcon : CustomFolderIcon
}
/>
<div className={styles.border}></div>
</div>

<Typography className={styles.text}>
{query.type === 'all'
{query.type === 'all' || !user
? i18n.t('Experience.New.AllOfMyriad')
: i18n.t('Experience.New.TimelineIFollow')}
</Typography>
Expand Down
17 changes: 16 additions & 1 deletion src/components/WalletBalance/WalletBalanceContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Typography } from '@material-ui/core';
import { WalletBalances as WalletBalancesComponent } from '.';
import { BoxComponent } from '../atoms/Box';

import { InfoIconYellow } from 'src/images/Icons';
import i18n from 'src/locale';
import { RootState } from 'src/reducers';
import { BalanceState } from 'src/reducers/balance/reducer';
Expand All @@ -22,7 +23,21 @@ export const WalletBalancesContainer: React.FC = () => {
if (anonymous)
return (
<BoxComponent title={i18n.t('Wallet.Header')}>
<Typography>{i18n.t('Wallet.Anonymous')}</Typography>
<div
style={{
backgroundColor: '#ffc85726',
padding: 10,
borderRadius: 8,
fontSize: 14,
display: 'flex',
alignItems: 'start',
marginBottom: 16,
}}>
<div style={{ marginRight: 8, marginTop: 4 }}>
<InfoIconYellow />
</div>
<Typography>{i18n.t('Wallet.Anonymous')}</Typography>
</div>
</BoxComponent>
);

Expand Down
3 changes: 3 additions & 0 deletions src/components/atoms/Tabs/Tabs.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const useStyles = makeStyles<Theme, StylesProps>(theme =>
justifyContent: props => props.position ?? null,
gap: props => (props.position === 'left' ? 20 : null),
},
'& .MuiTab-root': {
maxWidth: '100%',
},
},
}),
);
2 changes: 1 addition & 1 deletion src/components/template/Default/DefaultLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const Default: React.FC<DefaultLayoutProps> = props => {
/>
</div>
<div>
<RightMenuBar />
<RightMenuBar anonymous={anonymous} />
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@
"Wallet": {
"Title": "{{appname}} - Wallet",
"Header": "Wallet",
"Anonymous": "Please Log-in to access this feature",
"Anonymous": "You are signed-out. Sign-in with crypto wallet to access this feature.",
"Tab": {
"Balance": "Balance",
"History": "History",
Expand Down
2 changes: 1 addition & 1 deletion src/locale/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@
"Wallet": {
"Title": "{{appname}} - Dompet",
"Header": "Dompet",
"Anonymous": "Please Login to access this feature",
"Anonymous": "Anda belum masuk. Masuk dengan dompet kripto untuk menggunakan fitur ini",
"Tab": {
"Balance": "Saldo",
"History": "Riwayat",
Expand Down
2 changes: 1 addition & 1 deletion src/locale/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@
"Wallet": {
"Title": "{{appname}} - Кошелек",
"Header": "Кошелек",
"Anonymous": "Пожалуйста войдите чтобы воспользоваться",
"Anonymous": "You are signed-out. Sign-in with crypto wallet to access this feature.",
"Tab": {
"Balance": "Баланс",
"History": "История",
Expand Down

0 comments on commit 0d953a9

Please sign in to comment.