Skip to content
Open
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
File renamed without changes.
1 change: 0 additions & 1 deletion src/components/movies/cardMovieItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const CardMovieItem = ({ product }: CardMovieItemProps) => {

const handleDelete = () => {
if (product?.id) {
dispatch(command.products.delete(product?.id));
dispatch(command.history.delete(product?.id));
navigate('/movies');
}
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions src/components/movies/recommendations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ const Recommendations = (Recommendations: RecommendationsProps) => {

return (
<>
{recommendations
? (
{recommendations?.length === 0
? <Typography> no data </Typography>
: (
<Box
className="keen-slider"
ref={ref}
Expand Down Expand Up @@ -114,8 +115,8 @@ const Recommendations = (Recommendations: RecommendationsProps) => {
</div>
))}
</Box>
)
: <Typography> no data </Typography>}
)}

</>
);
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 0 additions & 44 deletions src/models/products/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { ProductsActionType } from './types.js';

import type {
nowPlaying,
Product,
ProductDeleted,
ProductDetailModel,
ProductsAction,
ProductsModel,
Expand All @@ -26,34 +24,6 @@ import type {
} from './types.js';

const productsCommand = {
delete: (id: number) => {
return (dispatch) => {
if (id) {
const value: ProductDeleted = {
id
};

dispatch({
type: ProductsActionType.Delete,
value
});
}
};
},
create: (product: Product) => {
return (dispatch) => {
if (product) {
const value: ProductsModel = {
products: [product]
};

dispatch({
type: ProductsActionType.Create,
value
});
}
};
},
load: (options?: Readonly<FetchURLOptions>) => {
return async (dispatch) => {
try {
Expand Down Expand Up @@ -163,20 +133,6 @@ const productsCommand = {
console.error(err);
}
};
},
update: (product: Product) => {
return (dispatch) => {
if (product) {
const value: ProductsModel = {
products: [product]
};

dispatch({
type: ProductsActionType.Update,
value
});
}
};
}
} satisfies Command<RootModel, ProductsAction>;

Expand Down
32 changes: 0 additions & 32 deletions src/models/products/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ProductsActionType } from './types.js';

import type {
nowPlaying,
Product,
ProductDetailModel,
ProductsAction,
ProductsModel,
Expand All @@ -17,40 +16,9 @@ const productsReducer = (
state: ProductsModel = {},
action: Readonly<ProductsAction>
): ProductsModel => {
let newProducts: Product[] = [];
switch (action.type) {
case ProductsActionType.Load:
return !state.products ? { ...action.value } : { ...state };
case ProductsActionType.Delete:
const productIdToDelete = action.value; // Assuming action.value contains the ID of the product to delete

return {
...state,
products: state.products
? state.products.filter(
(product) => product.id !== productIdToDelete.id
)
: []
};
case ProductsActionType.Create:
newProducts = action.value?.products ?? [];

return {
...state,
products: state.products
? [...state.products, ...newProducts]
: newProducts
};
case ProductsActionType.Update:
const updatedProducts = action.value?.products ?? [];
const updatedProductId = updatedProducts[0]?.id;

return {
...state,
products: (state.products ?? []).map((product: Product) => (product.id === updatedProductId
? { ...product, ...updatedProducts[0] }
: product))
};

default:
return state;
Expand Down
11 changes: 0 additions & 11 deletions src/models/products/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,13 @@ interface ProductDetailModel {

enum ProductsActionType {
Load = 'products-load',
Delete = 'product-delete',
Detail = 'products-detail',
Create = 'products-create',
Update = 'products-update',
NowPlayingLoad = 'products-now_playing',
UpcomingLoad = 'products-upcoming',
TopratedLoad = 'product-toprated'
}

type ProductsAction = {
type: ProductsActionType.Create
value?: ProductsModel
} | {
type: ProductsActionType.Delete
value: ProductDeleted
} | {
type: ProductsActionType.Detail
value?: ProductDetailModel
} | {
Expand All @@ -83,8 +74,6 @@ type ProductsAction = {
} | {
type: ProductsActionType.UpcomingLoad
value?: upComing
} | { type: ProductsActionType.Update
value?: ProductsModel
} ;

export { ProductsActionType };
Expand Down
2 changes: 1 addition & 1 deletion src/pages/add/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const AddMovie: PageComponent = () => {
title: newTitle
};

dispatch(command.products.create(product));
// dispatch(command.products.create(product));
dispatch(command.history.create(product));
};

Expand Down
10 changes: 5 additions & 5 deletions src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import type { PageComponent } from '@nxweb/react';

import { useSettings } from '@hooks/use-settings';

import AddMovie from './addMovie';
import NowPlaying from './nowPlaying';
import TopSec from './top';
import TopThree from './topThree';
import Upcoming from './upcoming';
import AddMovie from '../../components/movies/addMovie';
import NowPlaying from '../../components/movies/nowPlaying';
import TopSec from '../../components/movies/top';
import TopThree from '../../components/movies/topThree';
import Upcoming from '../../components/movies/upcoming';

const Home: PageComponent = () => {
const {
Expand Down
9 changes: 7 additions & 2 deletions src/pages/movies/cardMovie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@ import { useEffect } from 'react';
import { Grid } from '@mui/material';

import CardMovieItem from '@components/movies/cardMovieItem';
import type { Product } from '@models/products/types';
import { useCommand, useStore } from '@models/store.js';

const CardMovie = () => {
const [state, dispatch] = useStore((store) => store.products);
const [state, dispatch] = useStore((store) => store);
const command = useCommand((cmd) => cmd);

useEffect(() => {
dispatch(command.products.load()).catch((err: unknown) => {
console.error(err);
});

dispatch(command.history.load());
}, []);

const product: Product[] = [...state.products?.products ?? [], ...state.history?.history ?? []];

return (
<Grid container={true} spacing={6}>
{state?.products?.map((row) => (
{product.map((row) => (
<Grid item={true} md={3} sx={{ pb: 4 }} xs={12}>
<CardMovieItem product={row} />
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/movies/{id}.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const Product: PageComponent = () => {
const command = useCommand((cmd) => cmd);

const product = useMemo(() => {
let product = state?.products?.products?.find(
let product = state?.history?.history?.find(
(o) => o.id.toString() === id
);
if (!product) {
Expand All @@ -54,7 +54,7 @@ const Product: PageComponent = () => {

const handleDelete = () => {
if (product?.id) {
dispatch(command.products.delete(product?.id));
// dispatch(command.products.delete(product?.id));
dispatch(command.history.delete(product?.id));
navigate('/movies');
}
Expand Down
5 changes: 2 additions & 3 deletions src/pages/update/{id}.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ const UpdateMovie: PageComponent = () => {
const command = useCommand((cmd) => cmd);

useEffect(() => {
dispatch(command.products.load());
dispatch(command.history.load());
}, []);

const currentMovie = useMemo(
() => state?.products?.products?.find((current) => current.id?.toString() === id),
() => state?.history?.history?.find((current) => current.id?.toString() === id),
[state, id]
);

Expand Down Expand Up @@ -174,7 +174,6 @@ const UpdateMovie: PageComponent = () => {
title: newTitle
};

dispatch(command.products.update(product));
dispatch(command.history.update(product));
}
};
Expand Down