RC-10: create history and favorite pages
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
import { styled } from '@mui/material/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import FusePageSimple from '@fuse/core/FusePageSimple';
|
||||
import DemoContent from '@fuse/core/DemoContent';
|
||||
import { Paper } from '@mui/material';
|
||||
import { styled } from '@mui/material/styles';
|
||||
import { PROPERTIES_LAYOUTS } from 'app/configs/consts';
|
||||
import { selectUserFavorites, updateUserFavorites } from 'app/store/userSlice';
|
||||
import clsx from 'clsx';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { usePropertiesHeader } from 'src/app/hooks';
|
||||
import PropertiesHeader from '../shared-components/PropertiesHeader';
|
||||
import PropertyGridCard from '../shared-components/PropertyGridCard';
|
||||
import PropertyListItem from '../shared-components/PropertyListItem';
|
||||
|
||||
const Root = styled(FusePageSimple)(({ theme }) => ({
|
||||
'& .FusePageSimple-header': {
|
||||
@@ -16,21 +24,73 @@ const Root = styled(FusePageSimple)(({ theme }) => ({
|
||||
'& .FusePageSimple-sidebarContent': {},
|
||||
}));
|
||||
|
||||
function FavoritesPage(props) {
|
||||
const { t } = useTranslation('favoritesPage');
|
||||
function FavoritesPage() {
|
||||
const dispatch = useDispatch();
|
||||
const items = useSelector(selectUserFavorites);
|
||||
|
||||
const { categories, activeCategory, onCategory, layouts, activeLayout, onLayout, onItemDelete } =
|
||||
usePropertiesHeader(items);
|
||||
|
||||
const onFavorite = useCallback(
|
||||
(id) => {
|
||||
const targetItem = items.find((item) => item.id === id);
|
||||
if (!targetItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
onItemDelete(targetItem?.category);
|
||||
dispatch(updateUserFavorites(targetItem)).catch((error) => console.log(error));
|
||||
},
|
||||
[items, onItemDelete, dispatch]
|
||||
);
|
||||
|
||||
const renderedItems = useMemo(
|
||||
() =>
|
||||
items.map((item, idx) => {
|
||||
if (activeCategory !== 'all' && item.category !== activeCategory) {
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
return activeLayout === PROPERTIES_LAYOUTS.list ? (
|
||||
<PropertyListItem
|
||||
{...item}
|
||||
key={item.title + idx}
|
||||
onDelete={onFavorite}
|
||||
onFavorite={onFavorite}
|
||||
/>
|
||||
) : (
|
||||
<PropertyGridCard
|
||||
{...item}
|
||||
key={item.title + idx}
|
||||
onDelete={onFavorite}
|
||||
onFavorite={onFavorite}
|
||||
/>
|
||||
);
|
||||
}),
|
||||
[items, activeCategory, activeLayout, onFavorite]
|
||||
);
|
||||
|
||||
return (
|
||||
<Root
|
||||
// header={
|
||||
// <div className="p-24">
|
||||
// <h4>{t('TITLE')}</h4>
|
||||
// </div>
|
||||
// }
|
||||
content={
|
||||
<div className="p-24">
|
||||
<h4>Content</h4>
|
||||
<br />
|
||||
<DemoContent />
|
||||
<div className="w-full p-60">
|
||||
<Paper className="w-full h-320 mb-[30px] rounded-20 shadow-light" />
|
||||
<PropertiesHeader
|
||||
className="mb-40"
|
||||
categories={categories}
|
||||
layouts={layouts}
|
||||
onCategory={onCategory}
|
||||
onLayout={onLayout}
|
||||
/>
|
||||
<div
|
||||
className={clsx(
|
||||
'w-full flex flex-wrap justify-center gap-28',
|
||||
activeLayout === PROPERTIES_LAYOUTS.list && 'flex-col'
|
||||
)}
|
||||
>
|
||||
{renderedItems}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
scroll="content"
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { lazy } from 'react';
|
||||
import i18next from 'i18next';
|
||||
|
||||
import authRoles from '../../../configs/authRoles';
|
||||
import Favorites from './Favorites';
|
||||
import en from './i18n/en';
|
||||
|
||||
i18next.addResourceBundle('en', 'favoritesPage', en);
|
||||
|
||||
const Favorites = lazy(() => import('./Favorites'));
|
||||
|
||||
const FavoritesConfig = {
|
||||
settings: {
|
||||
layout: {
|
||||
@@ -22,28 +24,3 @@ const FavoritesConfig = {
|
||||
};
|
||||
|
||||
export default FavoritesConfig;
|
||||
|
||||
/**
|
||||
* Lazy load Example
|
||||
*/
|
||||
/*
|
||||
import React from 'react';
|
||||
|
||||
const Example = lazy(() => import('./Example'));
|
||||
|
||||
const ExampleConfig = {
|
||||
settings: {
|
||||
layout: {
|
||||
config: {},
|
||||
},
|
||||
},
|
||||
routes: [
|
||||
{
|
||||
path: 'example',
|
||||
element: <Example />,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export default ExampleConfig;
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
import { styled } from '@mui/material/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import FusePageSimple from '@fuse/core/FusePageSimple';
|
||||
import DemoContent from '@fuse/core/DemoContent';
|
||||
import { Paper } from '@mui/material';
|
||||
import { styled } from '@mui/material/styles';
|
||||
import { PROPERTIES_LAYOUTS } from 'app/configs/consts';
|
||||
import { selectUserHistory, updateUserFavorites, updateUserHistory } from 'app/store/userSlice';
|
||||
import clsx from 'clsx';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { usePropertiesHeader } from 'src/app/hooks';
|
||||
import PropertiesHeader from '../shared-components/PropertiesHeader';
|
||||
import PropertyGridCard from '../shared-components/PropertyGridCard';
|
||||
import PropertyListItem from '../shared-components/PropertyListItem';
|
||||
|
||||
const Root = styled(FusePageSimple)(({ theme }) => ({
|
||||
'& .FusePageSimple-header': {
|
||||
@@ -16,21 +24,83 @@ const Root = styled(FusePageSimple)(({ theme }) => ({
|
||||
'& .FusePageSimple-sidebarContent': {},
|
||||
}));
|
||||
|
||||
function HistoryPage(props) {
|
||||
const { t } = useTranslation('historyPage');
|
||||
function HistoryPage() {
|
||||
const dispatch = useDispatch();
|
||||
const items = useSelector(selectUserHistory);
|
||||
|
||||
const { categories, activeCategory, onCategory, layouts, activeLayout, onLayout, onItemDelete } =
|
||||
usePropertiesHeader(items);
|
||||
|
||||
const onDelete = useCallback(
|
||||
(id) => {
|
||||
const targetItem = items.find((item) => item.id === id);
|
||||
const newHistory = items.filter((item) => item.id !== id);
|
||||
|
||||
onItemDelete(targetItem?.category);
|
||||
dispatch(updateUserHistory(newHistory));
|
||||
},
|
||||
[items, onItemDelete, dispatch]
|
||||
);
|
||||
|
||||
const onFavorite = useCallback(
|
||||
(id) => {
|
||||
const targetItem = items.find((item) => item.id === id);
|
||||
if (!targetItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(updateUserFavorites(targetItem)).catch((error) => console.log(error));
|
||||
},
|
||||
[items, dispatch]
|
||||
);
|
||||
|
||||
const renderedItems = useMemo(
|
||||
() =>
|
||||
items.map((item, idx) => {
|
||||
if (activeCategory !== 'all' && item.category !== activeCategory) {
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
return activeLayout === PROPERTIES_LAYOUTS.list ? (
|
||||
<PropertyListItem
|
||||
{...item}
|
||||
key={item.title + idx}
|
||||
onDelete={onDelete}
|
||||
onFavorite={onFavorite}
|
||||
/>
|
||||
) : (
|
||||
<PropertyGridCard
|
||||
{...item}
|
||||
key={item.title + idx}
|
||||
onDelete={onDelete}
|
||||
onFavorite={onFavorite}
|
||||
/>
|
||||
);
|
||||
}),
|
||||
[items, activeCategory, activeLayout, onDelete, onFavorite]
|
||||
);
|
||||
|
||||
return (
|
||||
<Root
|
||||
// header={
|
||||
// <div className="p-24">
|
||||
// <h4>{t('TITLE')}</h4>
|
||||
// </div>
|
||||
// }
|
||||
content={
|
||||
<div className="p-24">
|
||||
<h4>Content</h4>
|
||||
<br />
|
||||
<DemoContent />
|
||||
<div className="w-full p-60">
|
||||
<Paper className="w-full h-320 mb-[30px] rounded-20 shadow-light" />
|
||||
<PropertiesHeader
|
||||
className="mb-40"
|
||||
categories={categories}
|
||||
layouts={layouts}
|
||||
onCategory={onCategory}
|
||||
onLayout={onLayout}
|
||||
/>
|
||||
<div
|
||||
className={clsx(
|
||||
'w-full flex flex-wrap justify-center gap-28',
|
||||
activeLayout === PROPERTIES_LAYOUTS.list && 'flex-col'
|
||||
)}
|
||||
>
|
||||
{renderedItems}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
scroll="content"
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { lazy } from 'react';
|
||||
import i18next from 'i18next';
|
||||
|
||||
import authRoles from '../../../configs/authRoles';
|
||||
import History from './History';
|
||||
import en from './i18n/en';
|
||||
|
||||
i18next.addResourceBundle('en', 'historyPage', en);
|
||||
|
||||
const History = lazy(() => import('./History'));
|
||||
|
||||
const HistoryConfig = {
|
||||
settings: {
|
||||
layout: {
|
||||
@@ -22,28 +24,3 @@ const HistoryConfig = {
|
||||
};
|
||||
|
||||
export default HistoryConfig;
|
||||
|
||||
/**
|
||||
* Lazy load Example
|
||||
*/
|
||||
/*
|
||||
import React from 'react';
|
||||
|
||||
const Example = lazy(() => import('./Example'));
|
||||
|
||||
const ExampleConfig = {
|
||||
settings: {
|
||||
layout: {
|
||||
config: {},
|
||||
},
|
||||
},
|
||||
routes: [
|
||||
{
|
||||
path: 'example',
|
||||
element: <Example />,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export default ExampleConfig;
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user