Skip to content

Commit

Permalink
feat: 4 column card view on wide screen
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-liu-smile committed Dec 29, 2022
1 parent 7d5c1f1 commit 28b53bb
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 18 deletions.
2 changes: 1 addition & 1 deletion apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
useOpenPDP,
useRefresh,
useRegisteredbctob2b,
} from '@/shared/hook'
} from '@/hooks'

import {
getChannelId,
Expand Down
23 changes: 23 additions & 0 deletions apps/storefront/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
import {
useRefresh,
} from './useRefresh'

import {
useOpenPDP,
} from './useOpenPDP'

import {
useRegisteredbctob2b,
} from './useRegisteredbctob2b'

import {
useCardListColumn,
} from './useCardListColumn'

export {
useMobile,
} from './useMobile'

export {
useDebounce,
} from './useDebounce'

export {
useRefresh,
useOpenPDP,
useRegisteredbctob2b,
useCardListColumn,
}
25 changes: 25 additions & 0 deletions apps/storefront/src/hooks/useCardListColumn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
useWindowSize,
} from '@b3/hooks'
import {
useEffect,
useState,
} from 'react'

export const useCardListColumn = () => {
const {
width,
} = useWindowSize()

const [isExtraLarge, setExtraLarge] = useState<boolean>(false)

useEffect(() => {
if (+width >= 1536) {
setExtraLarge(true)
} else {
setExtraLarge(false)
}
}, [width])

return isExtraLarge
}
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions apps/storefront/src/pages/address/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import {
getB2BAddressConfig,
} from '@/shared/service/b2b'

import {
useCardListColumn,
} from '@/hooks'

import {
filterFormConfig,
convertBCToB2BAddress,
Expand Down Expand Up @@ -89,6 +93,8 @@ const Address = () => {
dispatch,
} = useContext(GlobaledContext)

const isExtraLarge = useCardListColumn()

const addEditAddressRef = useRef<RefCurrntProps | null>(null)

const [isRequestLoading, setIsRequestLoading] = useState(false)
Expand Down Expand Up @@ -289,6 +295,7 @@ const Address = () => {
getRequestList={getAddressList}
searchParams={filterData || {}}
isCustomRender
itemXs={isExtraLarge ? 3 : 4}
requestLoading={setIsRequestLoading}
tableKey="id"
renderItem={(row: AddressItemType) => (
Expand Down
4 changes: 4 additions & 0 deletions apps/storefront/src/pages/shoppingLists/ShoppingLists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {

import {
useMobile,
useCardListColumn,
} from '@/hooks'

import {
Expand Down Expand Up @@ -65,6 +66,8 @@ const shoppingLists = () => {
},
} = useContext(GlobaledContext)

const isExtraLarge = useCardListColumn()

const isEnableBtnPermissions = true

const customItem = {
Expand Down Expand Up @@ -186,6 +189,7 @@ const shoppingLists = () => {
getRequestList={fetchList}
searchParams={filterSearch}
isCustomRender
itemXs={isExtraLarge ? 3 : 4}
requestLoading={setIsRequestLoading}
renderItem={(row: ShoppingListsItemsProps) => (
<ShoppingListsCard
Expand Down
5 changes: 5 additions & 0 deletions apps/storefront/src/pages/usermanagement/Usermanagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import {
Box,
} from '@mui/material'

import {
B3Sping,
} from '@/components/spin/B3Sping'
Expand Down Expand Up @@ -34,6 +35,7 @@ import {

import {
useMobile,
useCardListColumn,
} from '@/hooks'

import {
Expand Down Expand Up @@ -75,6 +77,8 @@ const Usermanagement = () => {

const [isMobile] = useMobile()

const isExtraLarge = useCardListColumn()

const {
state: {
companyInfo,
Expand Down Expand Up @@ -199,6 +203,7 @@ const Usermanagement = () => {
getRequestList={fetchList}
searchParams={filterSearch || {}}
isCustomRender
itemXs={isExtraLarge ? 3 : 4}
requestLoading={setIsRequestLoading}
renderItem={(row: UsersList) => (
<UserItemCard
Expand Down
17 changes: 0 additions & 17 deletions apps/storefront/src/shared/hook/index.ts

This file was deleted.

4 changes: 4 additions & 0 deletions packages/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export {
useMutationObservable,
} from './useMutationObservable'

export {
useWindowSize,
} from './useWindowSize'

export type {
OpenPageState,
} from './useB3AppOpen'
Expand Down
24 changes: 24 additions & 0 deletions packages/hooks/useWindowSize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
useState, useEffect, useCallback,
} from 'react'

export function useWindowSize() {
const [size, setSize] = useState({
width: window.innerWidth,
height: window.innerHeight,
})

const handleResize = useCallback(() => {
setSize({
width: window.innerWidth,
height: window.innerHeight,
})
}, [])

useEffect(() => {
window.addEventListener('resize', handleResize)
return () => window.removeEventListener('resize', handleResize)
}, [handleResize])

return size
}

0 comments on commit 28b53bb

Please sign in to comment.