Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit Important mobile view #558

Merged
merged 2 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/Page/Page.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const useStyles = makeStyles(
padding: theme.spacing(0, 5),
},
},
pageMobile:{},
}),
{ name: 'Page' },
);
9 changes: 7 additions & 2 deletions src/components/Page/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import React, { useContext } from 'react';
import { Container } from '@material-ui/core';
import { useStyles } from './Page.styles';
import { ScreenContext } from '../../old/provider/MobileProvider/ScreenContext';

export interface IPageProps {
component: React.ComponentType;
Expand All @@ -9,8 +10,12 @@ export interface IPageProps {
const Page: React.FC<IPageProps> = (props) => {
const classes = useStyles();

const { mobile } = useContext(ScreenContext);

return (
<Container className={classes.page} disableGutters>
<Container
className={mobile ? classes.pageMobile : classes.page} disableGutters
>
<props.component />
</Container>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import { makeStyles, Theme } from '@material-ui/core';

interface IStyleProps {
backgroundImageUrl: string;
size: 'small' | 'large';
size: 'small' | 'mobile' | 'large';
}

const sizeModes = {
mobile: {
root: {
height: 585,
padding: [0],
},
},
small: {
root: {
height: 200,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Posts/Cards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IPost } from '../../../old/lib/types';

export interface IPostPreviewCardProps {
post: IPost;
size?: 'small' | 'large';
size?: 'small' | 'large' | 'mobile';
shouldNotUseLink?: boolean;
resetPage?: () => void;
}
19 changes: 19 additions & 0 deletions src/old/lib/components/Carousel/Carousel.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,23 @@ export const useStyles = makeStyles((theme) => ({
background: theme.palette.common.white,
},
},
dotsMobile:{
width:'auto',
bottom: 30,
textAlign: 'left',
left: 30,
'& li button': {
width: theme.spacing(2),
height: theme.spacing(2),
border: '2px solid',
borderColor: theme.palette.common.white,
borderRadius: '50%',
'&::before': {
content: 'none',
},
},
'& li.slick-active button': {
background: theme.palette.common.white,
},
}
}));
8 changes: 6 additions & 2 deletions src/old/lib/components/Carousel/Carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* eslint-disable react/jsx-props-no-spreading */
import React, { useRef } from 'react';
import React, { useContext, useRef } from 'react';
import Slider, { Settings } from 'react-slick';
import { useStyles } from './Carousel.styles';
import { ScreenContext } from '../../../provider/MobileProvider/ScreenContext';

const Carousel: React.FC = ({ children }) => {
const sliderRef = useRef<Slider>(null);
const classes = useStyles();

const { mobile } = useContext(ScreenContext);

const settings: Settings = {
arrows: false,
dots: true,
Expand All @@ -14,7 +18,7 @@ const Carousel: React.FC = ({ children }) => {
draggable: false,
autoplay: true,
autoplaySpeed: 5000,
dotsClass: `slick-dots ${classes.dots}`,
dotsClass: `slick-dots ${mobile ? classes.dotsMobile : classes.dots}`,
};
return (
<>
Expand Down
9 changes: 6 additions & 3 deletions src/old/modules/main/components/ImportantContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useContext, useEffect } from 'react';
import { useSelector } from 'react-redux';
import Carousel from '../../../lib/components/Carousel/Carousel';
import { useStyles } from '../styles/ImportantContainer.styles';
Expand All @@ -11,6 +11,7 @@ import {
} from '../../../../models/main';
import { useActions } from '../../../../shared/hooks';
import { IPost } from '../../../lib/types';
import { ScreenContext } from '../../../provider/MobileProvider/ScreenContext';

interface IImportantContainer {
customPosts?: IPost[];
Expand All @@ -28,14 +29,16 @@ export const ImportantContainer: React.FC<IImportantContainer> = ({

const [boundFetchImportantPosts] = useActions([fetchImportantPosts]);

const { mobile } = useContext(ScreenContext);

useEffect(() => {
if (!customPosts) {
boundFetchImportantPosts();
}
}, []);

return (
<div className={classes.container}>
<div className={mobile ? classes.containerMobile : classes.container}>
{loading === 'pending' ? (
<LoadingContainer loading={loading} />
) : (
Expand All @@ -45,7 +48,7 @@ export const ImportantContainer: React.FC<IImportantContainer> = ({
<ImportantPostPreviewCard
post={post}
key={post.title}
size="large"
size={mobile ? 'mobile' : 'large'}
/>
))}
</Carousel>
Expand Down
6 changes: 6 additions & 0 deletions src/old/modules/main/styles/ImportantContainer.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const useStyles = makeStyles(
flexDirection: 'column',
justifyContent: 'center',
},
containerMobile:{
minHeight: 585,
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
}
},
{ name: 'ImportantContainer' },
);
4 changes: 2 additions & 2 deletions src/old/provider/MobileProvider/ScreenProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ScreenContext } from './ScreenContext';

export const ScreenProvider: React.FC = ({ children }) => {
const theme = useTheme();
const mobile = useMediaQuery(theme.breakpoints.down('sm'));
const tablet = useMediaQuery(theme.breakpoints.down('md'));
const mobile = !useMediaQuery(theme.breakpoints.up('sm'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a convention in JS to use is, has, etc. prefixes for boolean values.

So, isMobile should be better.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what was the problem with using .down('sm) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should works like on this image
Screenshot_6

but with this solution it works like this
Screenshot_3

const tablet = !useMediaQuery(theme.breakpoints.up('md'));
return (
<ScreenContext.Provider value={{ mobile, tablet }}>
{children}
Expand Down