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

responsive web design on home page #86

Merged
merged 3 commits into from
May 2, 2023
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
Binary file added apps/web/public/hamburger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions apps/web/src/components/CommunityCard/CommunityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import Image from "next/image";
import {Badge} from "../Badge";
import {CommunityCardProps} from "./types";
import * as utils from "../../utils";
import {md_screen_image, md_screen_wrapper, sm_screen_image, sm_screen_wrapper} from "./style";

export const CommunityCard = (props: CommunityCardProps) => {
return (
<div
onClick={props.onClick}
className="flex flex-col-reverse md:flex-row min-h-[246px] border hover:drop-shadow-xl rounded-2xl bg-white">
className={`flex flex-col-reverse h-full min-h-[246px] border hover:drop-shadow-xl rounded-2xl bg-white mx-auto ${md_screen_wrapper} ${sm_screen_wrapper}`}>
<div className={"flex flex-col grow"}>
<div className="flex flex-col justify-start px-6 py-7">
<h2 className="mb-2 text-2xl font-medium line-clamp-1 break-all">
Expand All @@ -35,7 +36,7 @@ export const CommunityCard = (props: CommunityCardProps) => {
</div>
</div>
<Image
className="rounded-tr-2xl w-[100%] max-h-[246px] md:w-[229px] border-l rounded-b-2xl object-cover"
className={`rounded-tr-2xl w-[100%] max-h-[auto] border-l rounded-b-2xl object-cover ${md_screen_image} ${sm_screen_image}`}
src={props.communityAvatar}
width={229}
height={0}
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/components/CommunityCard/style.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const md_screen_wrapper = "min-1001:flex-row tablet:w-[250px] mobile:w-[400px]";
export const md_screen_image = "min-1001:w-[229px] tablet:max-h-[150px] mobile:max-h-[200px]";

export const sm_screen_wrapper = "mobile:w-full";
export const sm_screen_image = "mobile:max-h-[200px]";
10 changes: 8 additions & 2 deletions apps/web/src/components/LeftPanel/LeftPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ import * as utils from "../../utils";
import UserOnboard from "../UserOnboard/UserOnboard";
import {CommunityOnboard} from "../CommunityOnboard";
import {CommunityList} from "../CommunityList";
import {selectCommunity, useAppDispatch} from "../../store";
import {selectCommunity, useAppDispatch, useAppSelector} from "../../store";
import {GlobalAskQuestion} from "../GlobalAskQuestion";
import {md_screen} from "./styles";
import {useEffect} from "react";

const LeftPanel = (props: LeftPanelProp) => {
const {style} = props;
const router = useRouter();
const dispatch = useAppDispatch();
const isLeftPanelVisible = useAppSelector((state) => state.responsiveToggles.leftPanelToggle)

useEffect(() =>{
props.handleMargin(isLeftPanelVisible);
},[isLeftPanelVisible])

return (
<div
className={`fixed left-0 h-full border-r border-solid border-[#08010d12] ${style}`}
className={`fixed left-0 h-full border-r border-solid border-[#08010d12] bg-white z-[999] ${isLeftPanelVisible ? 'block' :md_screen} ${style}`}
>
<div className={`h-full flex flex-col justify-between`}>
<div
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/LeftPanel/styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const md_screen = "max-680:hidden min-680:block"
1 change: 1 addition & 0 deletions apps/web/src/components/LeftPanel/type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export type LeftPanelProp = {
style: string;
handleMargin: (value: boolean) => void;
};
2 changes: 1 addition & 1 deletion apps/web/src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {SearchProps} from "./types";

export const Search = (props: SearchProps) => {
return (
<div className="flex items-center lg:mx-0 lg:max-w-none xl:px-0">
<div className="flex items-center lg:mx-0 lg:max-w-none xl:px-0 relative z-[0]">
<div className="w-full">
<div className="relative">
<div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-4 text-gray-500">
Expand Down
10 changes: 8 additions & 2 deletions apps/web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { store } from "../store";
import { LeftPanel } from "../components/LeftPanel";
import {UserProfileWrapper} from "../sections";
import {UpdateCommunityWrapper} from "../sections/UpdateCommunity";
import {md_component} from "../styles/app_styels";
import {useState} from "react";

const projectId = config.walletConnect.projectId;
const chains = [
Expand Down Expand Up @@ -54,6 +56,10 @@ const client = createClient({
const ethereumClient = new EthereumClient(client, chains);

const MyApp: AppType = ({ Component, pageProps }) => {
const [margin, setMargin] = useState<boolean>(true);
const handleMargin = (value) =>{
setMargin(value);
}
return (
<>
<WagmiConfig client={client}>
Expand All @@ -71,8 +77,8 @@ const MyApp: AppType = ({ Component, pageProps }) => {
/>
<Provider store={store}>
<div className={"w-screen h-screen box-border"}>
<LeftPanel style={'w-[75px]'}/>
<div className={"max-w-full h-full ml-[75px] box-border"} >
<LeftPanel style={'w-[75px]'} handleMargin={handleMargin}/>
<div className={`max-w-full h-full ml-[75px] box-border ${!margin && md_component}`} >
<Component {...pageProps} />
<UserProfileWrapper />
<UpdateCommunityWrapper />
Expand Down
23 changes: 17 additions & 6 deletions apps/web/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {Search} from "../components/Search";
import {CommunityCard} from "../components/CommunityCard";
import {LoadMore} from "../components/Button/LoadMore";
import {useEffect} from "react";
import {useAppSelector} from "../store";
import {toggleLeftPanel, useAppDispatch, useAppSelector} from "../store";
import {isEmpty, isNil} from "lodash";
import {index_title, md_index_container, md_index_grid} from "../styles/app_styels";

const Home: NextPage = () => {
const newlyCreatedCommunity = useAppSelector((state) => state.community.newlyCreatedCommunity);

const dispatch = useAppDispatch();
const isLeftPanelVisible = useAppSelector((state) => state.responsiveToggles.leftPanelToggle)
// @ts-ignore
const {data, fetchNextPage, hasNextPage, refetch, isFetching} = trpc.public.fetchCommunities.useInfiniteQuery({
first: 10,
Expand All @@ -31,15 +33,24 @@ const Home: NextPage = () => {
fetchData();
}, [newlyCreatedCommunity])

const handleLeftpanelToggle = () =>{
dispatch(toggleLeftPanel(!isLeftPanelVisible))
}
return (
<div className="container mx-auto">
<h1 className="p-4 text-4xl font-medium">discover</h1>
<div className="mx-4 max-w-[682px]">
<div className={`.container mx-auto ${md_index_container}`}>
<div className={"flex row gap-[10px] items-center mx-4"} >
<div className={` ${index_title}`} onClick={handleLeftpanelToggle}>
<img src={"/hamburger.png"} alt={"hamburger"} width={"100%"} height={"100%"}/>
</div>
<h1 className="p-4 text-4xl font-medium">discover</h1>
</div>

<div className="mx-4 max-w-[682px] ">
<Search label={"Search by name or tags"} onQuery={() => {
}}/>
</div>

<div className="m-4 mt-12 grid gap-8 md:grid-cols-1 lg:grid-cols-2">
<div className={`m-4 mt-12 grid gap-8 ${md_index_grid}`}>
{data?.pages?.map((page) => {
return (
page?.edges?.map((community) => {
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/store/features/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./community";
export * from "./user";
export * from "./profile";
export * from "./responsive_toggles";
22 changes: 22 additions & 0 deletions apps/web/src/store/features/responsive_toggles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type {PayloadAction} from '@reduxjs/toolkit';
import {createSlice} from '@reduxjs/toolkit';

export interface ResponsiveToggles {
leftPanelToggle: boolean;
}
const initialState: ResponsiveToggles = {
leftPanelToggle: false,
};

export const responsiveTogglesSlice = createSlice({
name: 'responsiveToggle',
initialState,
reducers: {
toggleLeftPanel: (state, action: PayloadAction<boolean>) => {
state.leftPanelToggle = action.payload;
},
},
});

export const {toggleLeftPanel} = responsiveTogglesSlice.actions;
export default responsiveTogglesSlice.reducer;
2 changes: 2 additions & 0 deletions apps/web/src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import userReducer from "./features/user";
import communityReducer from "./features/community";
import profileReducer from "./features/profile";
import threadReducer from "./features/thread";
import responsiveToggleReducer from "./features/responsive_toggles";
import {loadFromLocalStorage, saveToLocalStorage} from "./storage";

export const store = configureStore({
Expand All @@ -11,6 +12,7 @@ export const store = configureStore({
user: userReducer,
profile: profileReducer,
thread: threadReducer,
responsiveToggles: responsiveToggleReducer,
},
preloadedState: loadFromLocalStorage(),
});
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/styles/app_styels.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const md_component = "max-680:ml-[0px]";

export const md_index_grid = "860-1001:grid-cols-3 521-861:grid-cols-2 min-1001:grid-cols-2";
export const md_index_container = "max-680";
export const index_title = "min-680:hidden";
17 changes: 17 additions & 0 deletions apps/web/tailwind.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ module.exports = {
accent: "#ff225b",
},
},
screens: {
'sm': '640px',
'md': '768px',
'lg': '1024px',
'xl': '1280px',
'2xl': '1536px',
'tablet': {'min':'520px','max':'1001px'},
'mobile': {'max':'521px'},
'860-1001': {'min':'860px','max':'1001px'},
'521-861': {'min':'521px','max':'861px'},
'max-680': {'max':'680px'},
'min-680': {'min':'680px'},
'min-500': {'min':'500px'},
'min-1001': {'min':'1001px'},
'max-1000': {'max':'1000px'},
// => @media (min-width: 1536px) { ... }
}
},
plugins: [
require('@tailwindcss/line-clamp'),
Expand Down