-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from builtbysuraj/style-refactor-client
Style refactor client
- Loading branch information
Showing
21 changed files
with
184 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const ENV = { | ||
API_BASE_URL: String(import.meta.env.VITE_API_BASE_URL), | ||
SERVER_URL: String(import.meta.env.VITE_SERVER_URL), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import axios from 'axios' | ||
import { | ||
PropsWithChildren, | ||
createContext, | ||
useContext, | ||
useEffect, | ||
useState, | ||
} from 'react' | ||
|
||
import { ENV } from '@/conf' | ||
|
||
type ServerStateType = { | ||
status: boolean | ||
message: string | ||
} | ||
|
||
export const ServerStatusContext = createContext<ServerStateType | null>(null) | ||
|
||
export default function ServerStatusProvider({ children }: PropsWithChildren) { | ||
const [serverStatus, setServerStatus] = useState<ServerStateType>({ | ||
status: false, | ||
message: '', | ||
}) | ||
|
||
useEffect(() => { | ||
const checkServerStatus = async () => { | ||
try { | ||
const { data } = await axios.get(`${ENV.SERVER_URL}/api/status`) | ||
|
||
if (data.status) { | ||
setServerStatus(data) | ||
} else { | ||
setServerStatus({ status: false, message: 'Server is not running' }) | ||
} | ||
} catch (error) { | ||
setServerStatus({ status: false, message: 'Wait for server to start' }) | ||
} | ||
} | ||
|
||
checkServerStatus() | ||
|
||
const intervalId = setInterval(checkServerStatus, 10000) | ||
|
||
// Clear interval on component unmount | ||
return () => clearInterval(intervalId) | ||
}, []) | ||
|
||
return ( | ||
<ServerStatusContext.Provider value={serverStatus}> | ||
{children} | ||
</ServerStatusContext.Provider> | ||
) | ||
} | ||
|
||
// eslint-disable-next-line react-refresh/only-export-components | ||
export const useServerStatus = () => { | ||
const context = useContext(ServerStatusContext) | ||
if (context === undefined) { | ||
throw new Error( | ||
'useServerStatus must be used within an ServerStatusProvider' | ||
) | ||
} | ||
return context | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import CategoryFilter from './CategoryFilter' | ||
import PriceSliderFilter from './PriceSliderFilter' | ||
import RatingFilter from './RatingFilter' | ||
import SortProductsFilter from './SortProductsFilter' | ||
import AppliedFilters from './applied-filters/AppliedFilters' | ||
import BrandFilter from './brand-filter/BrandFilter' | ||
import ClearFilter from './clear-filter/ClearFilter' | ||
|
||
export { | ||
AppliedFilters, | ||
BrandFilter, | ||
CategoryFilter, | ||
ClearFilter, | ||
PriceSliderFilter, | ||
RatingFilter, | ||
SortProductsFilter, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
import { useAppSelector } from '@/state/store' | ||
import type { CartType } from '@/types' | ||
import styles from './CartPage.module.css' | ||
import CartItem from './components/cart-item/CartItem' | ||
import CartPriceDetails from './components/cart-price-details/CartPriceDetails' | ||
import EmptyCart from './components/empty-cart/EmptyCart' | ||
import PlaceOrder from './components/place-order/PlaceOrder' | ||
import { CartItem, CartPriceDetails, EmptyCart, PlaceOrder } from './components' | ||
|
||
export default function CartPage() { | ||
const cartData = useAppSelector((state) => state.cart) | ||
|
||
if (!cartData?.length) { | ||
return <EmptyCart /> | ||
} | ||
if (!cartData?.length) return <EmptyCart /> | ||
|
||
return ( | ||
<div className={styles.cartContainer}> | ||
<div> | ||
{cartData?.map((product: CartType) => ( | ||
<CartItem product={product} key={product.id} /> | ||
))} | ||
<PlaceOrder cartData={cartData} /> | ||
<> | ||
<div className={styles.cartContainer}> | ||
<div> | ||
{cartData?.map((product: CartType) => ( | ||
<CartItem product={product} key={product.id} /> | ||
))} | ||
<PlaceOrder cartData={cartData} /> | ||
</div> | ||
<CartPriceDetails cartData={cartData} /> | ||
</div> | ||
<CartPriceDetails cartData={cartData} /> | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import CartItem from './cart-item/CartItem' | ||
import CartPriceDetails from './cart-price-details/CartPriceDetails' | ||
import EmptyCart from './empty-cart/EmptyCart' | ||
import PlaceOrder from './place-order/PlaceOrder' | ||
|
||
export { CartItem, CartPriceDetails, EmptyCart, PlaceOrder } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
interface ImportMeta { | ||
env: { | ||
VITE_API_BASE_URL: string | ||
VITE_SERVER_URL: string | ||
} | ||
} |
Oops, something went wrong.