Skip to content

Commit

Permalink
Add update category feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Mar 23, 2023
1 parent c110ca3 commit 7f80daa
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions app/accounts/[id]/categories.tsx
Expand Up @@ -9,6 +9,7 @@ import {
createCategory,
newAccount,
restoreAccount,
updateCategory,
} from "../../../lib/account";
import { createEvent, getEvents } from "../../../lib/api";

Expand All @@ -29,8 +30,10 @@ export default function Categories(): JSX.Element {
<View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
<CategoryList
data={account.categories}
onPressCategory={(_category) => {
// TODO: edit
onPressCategory={(category) => {
setName(category.name);
setCategoryId(category.id);
setEditDialogVisible(true);
}}
/>
<FAB
Expand Down Expand Up @@ -64,7 +67,22 @@ export default function Categories(): JSX.Element {
setCategoryId(null);
setEditDialogVisible(false);
} else {
// TODO: update
// update local state
const [newAccount, newEvent] = updateCategory(
account,
categoryId,
name
);

// update remote state
setAccount(newAccount);
createEvent(newEvent).catch((_) => {
setAccount(account);
});

setName("");
setCategoryId(null);
setEditDialogVisible(false);
}
}}
visible={editDialogVisible}
Expand Down

0 comments on commit 7f80daa

Please sign in to comment.