mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-24 13:39:35 +02:00
Fixed state bug while updating categories. Fixed bug with bookmarks not being displayed under categories.
This commit is contained in:
parent
0d5a4c418e
commit
f127a354ef
5 changed files with 18 additions and 14 deletions
|
@ -40,10 +40,10 @@ export const Apps = (props: Props): JSX.Element => {
|
||||||
const [appInUpdate, setAppInUpdate] = useState<App>(appTemplate);
|
const [appInUpdate, setAppInUpdate] = useState<App>(appTemplate);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (apps.length === 0) {
|
if (!apps.length) {
|
||||||
getApps();
|
getApps();
|
||||||
}
|
}
|
||||||
}, [getApps]);
|
}, []);
|
||||||
|
|
||||||
const toggleModal = (): void => {
|
const toggleModal = (): void => {
|
||||||
setModalIsOpen(!modalIsOpen);
|
setModalIsOpen(!modalIsOpen);
|
||||||
|
@ -85,7 +85,7 @@ export const Apps = (props: Props): JSX.Element => {
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<Spinner />
|
<Spinner />
|
||||||
) : !isInEdit ? (
|
) : !isInEdit ? (
|
||||||
<AppGrid apps={apps} searching />
|
<AppGrid apps={apps} searching={props.searching} />
|
||||||
) : (
|
) : (
|
||||||
<AppTable updateAppHandler={toggleUpdate} />
|
<AppTable updateAppHandler={toggleUpdate} />
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -15,8 +15,8 @@ interface Props {
|
||||||
export const BookmarkGrid = (props: Props): JSX.Element => {
|
export const BookmarkGrid = (props: Props): JSX.Element => {
|
||||||
let bookmarks: JSX.Element;
|
let bookmarks: JSX.Element;
|
||||||
|
|
||||||
if (props.categories.length > 0) {
|
if (props.categories.length) {
|
||||||
if (props.searching && props.categories[0].bookmarks.length === 0) {
|
if (props.searching && !props.categories[0].bookmarks.length) {
|
||||||
bookmarks = (
|
bookmarks = (
|
||||||
<p className={classes.BookmarksMessage}>
|
<p className={classes.BookmarksMessage}>
|
||||||
No bookmarks match your search criteria
|
No bookmarks match your search criteria
|
||||||
|
|
|
@ -41,8 +41,6 @@ export const Bookmarks = (props: Props): JSX.Element => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { getCategories } = bindActionCreators(actionCreators, dispatch);
|
const { getCategories } = bindActionCreators(actionCreators, dispatch);
|
||||||
|
|
||||||
const { searching = false } = props;
|
|
||||||
|
|
||||||
const [modalIsOpen, setModalIsOpen] = useState(false);
|
const [modalIsOpen, setModalIsOpen] = useState(false);
|
||||||
const [formContentType, setFormContentType] = useState(ContentType.category);
|
const [formContentType, setFormContentType] = useState(ContentType.category);
|
||||||
const [isInEdit, setIsInEdit] = useState(false);
|
const [isInEdit, setIsInEdit] = useState(false);
|
||||||
|
@ -56,10 +54,10 @@ export const Bookmarks = (props: Props): JSX.Element => {
|
||||||
useState<Bookmark>(bookmarkTemplate);
|
useState<Bookmark>(bookmarkTemplate);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (categories.length === 0) {
|
if (!categories.length) {
|
||||||
getCategories();
|
getCategories();
|
||||||
}
|
}
|
||||||
}, [getCategories]);
|
}, []);
|
||||||
|
|
||||||
const toggleModal = (): void => {
|
const toggleModal = (): void => {
|
||||||
setModalIsOpen(!modalIsOpen);
|
setModalIsOpen(!modalIsOpen);
|
||||||
|
@ -148,7 +146,7 @@ export const Bookmarks = (props: Props): JSX.Element => {
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<Spinner />
|
<Spinner />
|
||||||
) : !isInEdit ? (
|
) : !isInEdit ? (
|
||||||
<BookmarkGrid categories={categories} searching />
|
<BookmarkGrid categories={categories} searching={props.searching} />
|
||||||
) : (
|
) : (
|
||||||
<BookmarkTable
|
<BookmarkTable
|
||||||
contentType={tableContentType}
|
contentType={tableContentType}
|
||||||
|
|
|
@ -47,14 +47,14 @@ export const Home = (): JSX.Element => {
|
||||||
if (!apps.length) {
|
if (!apps.length) {
|
||||||
getApps();
|
getApps();
|
||||||
}
|
}
|
||||||
}, [getApps]);
|
}, []);
|
||||||
|
|
||||||
// Load bookmark categories
|
// Load bookmark categories
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!categories.length) {
|
if (!categories.length) {
|
||||||
getCategories();
|
getCategories();
|
||||||
}
|
}
|
||||||
}, [getCategories]);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (localSearch) {
|
if (localSearch) {
|
||||||
|
|
|
@ -69,7 +69,10 @@ export const bookmarksReducer = (
|
||||||
...state,
|
...state,
|
||||||
categories: [
|
categories: [
|
||||||
...state.categories.slice(0, pinnedCategoryIdx),
|
...state.categories.slice(0, pinnedCategoryIdx),
|
||||||
action.payload,
|
{
|
||||||
|
...action.payload,
|
||||||
|
bookmarks: [...state.categories[pinnedCategoryIdx].bookmarks],
|
||||||
|
},
|
||||||
...state.categories.slice(pinnedCategoryIdx + 1),
|
...state.categories.slice(pinnedCategoryIdx + 1),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -96,7 +99,10 @@ export const bookmarksReducer = (
|
||||||
...state,
|
...state,
|
||||||
categories: [
|
categories: [
|
||||||
...state.categories.slice(0, updatedCategoryIdx),
|
...state.categories.slice(0, updatedCategoryIdx),
|
||||||
action.payload,
|
{
|
||||||
|
...action.payload,
|
||||||
|
bookmarks: [...state.categories[updatedCategoryIdx].bookmarks],
|
||||||
|
},
|
||||||
...state.categories.slice(updatedCategoryIdx + 1),
|
...state.categories.slice(updatedCategoryIdx + 1),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue