Skip to content

Commit

Permalink
feat: remove user context (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
niktverd authored Apr 25, 2023
1 parent 94b98f6 commit 36e7112
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 29 deletions.
11 changes: 6 additions & 5 deletions src/components/PostInfo/components/Save.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, {useContext} from 'react';
import {useAnalytics} from '@gravity-ui/page-constructor';
import {Icon} from '@gravity-ui/uikit';

import {UserContext} from '../../../contexts/UserContext';
import {LikesContext} from '../../../contexts/LikesContext';
import metrika from '../../../counters/metrika.js';
import {MetrikaCounter} from '../../../counters/utils';
import {Save as SaveIcon} from '../../../icons/Save';
Expand Down Expand Up @@ -54,8 +54,9 @@ export const Save: React.FC<SaveProps> = ({
theme,
dataQa,
}) => {
const {uid} = useContext(UserContext);
const {toggleLike} = useContext(LikesContext);
const handleAnalytics = useAnalytics(DefaultEventNames.SaveButton);
const isLikeable = Boolean(toggleLike);

return (
<div
Expand All @@ -66,7 +67,7 @@ export const Save: React.FC<SaveProps> = ({
event.preventDefault();
event.nativeEvent.stopImmediatePropagation();

if (!uid) {
if (!isLikeable) {
return;
}

Expand All @@ -77,15 +78,15 @@ export const Save: React.FC<SaveProps> = ({
}}
data-qa={`${dataQa ? dataQa + '-' : ''}save`}
>
<div className={b('content', {cursor: Boolean(uid), theme})}>
<div className={b('content', {cursor: isLikeable, theme})}>
<span className={b('icon')}>
<Icon
data={hasUserLike ? SaveFilled : SaveIcon}
size={ICON_SIZE}
className={b({filled: Boolean(hasUserLike)})}
/>
</span>
<span className={b('title', {cursor: Boolean(uid)})}>{title}</span>
<span className={b('title', {cursor: isLikeable})}>{title}</span>
</div>
</div>
);
Expand Down
4 changes: 0 additions & 4 deletions src/constructor/BlogConstructorProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {DeviceContext, DeviceContextProps} from '../contexts/DeviceContext';
import {LocaleContext} from '../contexts/LocaleContext';
import {MobileContext} from '../contexts/MobileContext';
import {RouterContext, RouterContextProps} from '../contexts/RouterContext';
import {UserContext, UserContextProps} from '../contexts/UserContext';
import {ThemeValueContext, ThemeValueType} from '../contexts/theme/ThemeValueContext';
import {Locale} from '../models/locale';

Expand All @@ -16,7 +15,6 @@ export interface BlogConstructorProviderProps {
locale?: Locale;
router?: RouterContextProps;
theme?: ThemeValueType;
user?: UserContextProps;
device?: DeviceContextProps;
analytics?: AnalyticsContextProps;
children?: React.ReactNode;
Expand All @@ -27,7 +25,6 @@ export const BlogConstructorProvider: React.FC<BlogConstructorProviderProps> = (
locale = {} as Locale,
router = {} as RouterContextProps,
theme = DEFAULT_THEME,
user = {},
device = {},
analytics = {},
children,
Expand All @@ -37,7 +34,6 @@ export const BlogConstructorProvider: React.FC<BlogConstructorProviderProps> = (
<LocaleContext.Provider value={{locale}} key="locale-context" />,
<RouterContext.Provider value={router} key="router-context" />,
<MobileContext.Provider value={Boolean(isMobile)} key="is-mobile-context" />,
<UserContext.Provider value={user} key="user-context" />,
<DeviceContext.Provider value={device} key="device-context" />,
<AnalyticsContext.Provider value={analytics} key="analytics-context" />,
].reduceRight((prev, provider) => React.cloneElement(provider, {}, prev), children);
Expand Down
9 changes: 0 additions & 9 deletions src/constructor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ interface BlogConstructorProviderProps {
locale?: Locale;
router?: RouterContextProps;
theme?: ThemeValueType;
user?: UserContextProps;
device?: DeviceContextProps;
analytics?: AnalyticsContextProps;
children?: React.ReactNode;
Expand Down Expand Up @@ -55,14 +54,6 @@ interface RouterContextProps {
type ThemeValueType = 'light' | 'dark';
```

### `User` - info about user

```jsx
interface UserAccount {
uid: string;
}
```

### `Device` - information about device

```jsx
Expand Down
4 changes: 3 additions & 1 deletion src/containers/BlogPage/BlogPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type BlogPageProps = {
services?: Service[];
navigation?: NavigationData;
getPosts: GetPostsType;
hasLikes?: boolean;
toggleLike?: ToggleLikeCallbackType;
metaData?: MetaProps;
setQuery?: SetQueryType;
Expand All @@ -45,6 +46,7 @@ export const BlogPage = ({
services,
getPosts,
metaData,
hasLikes = false,
toggleLike,
navigation,
settings,
Expand All @@ -54,7 +56,7 @@ export const BlogPage = ({
<LikesContext.Provider
value={{
toggleLike: toggleLike,
hasLikes: Boolean(toggleLike),
hasLikes,
}}
>
<FeedContext.Provider
Expand Down
10 changes: 0 additions & 10 deletions src/contexts/UserContext.ts

This file was deleted.

0 comments on commit 36e7112

Please sign in to comment.