Skip to content

Commit

Permalink
fix: fixed rename of collection
Browse files Browse the repository at this point in the history
  • Loading branch information
mbret committed Jul 1, 2024
1 parent 0465baa commit c6c2493
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
collectionActionDrawerChangesState,
collectionActionDrawerState
} from "./useCollectionActionsDrawer"
import { EditCollectionDialog } from "./EditCollectionDialog"
import { RenameCollectionDialog } from "./RenameCollectionDialog"
import { differenceInMinutes } from "date-fns"
import { COLLECTION_METADATA_LOCK_MN } from "@oboku/shared"
import { useModalNavigationControl } from "../../navigation/useModalNavigationControl"
Expand Down Expand Up @@ -177,12 +177,11 @@ export const CollectionActionsDrawer: FC<{}> = () => {
}}
collectionId={collectionId}
/>
<EditCollectionDialog
id={isEditCollectionDialogOpenedWithId}
<RenameCollectionDialog
openWith={isEditCollectionDialogOpenedWithId}
onClose={() => {
setIsEditCollectionDialogOpenedWithId(undefined)
}}
open={!!isEditCollectionDialogOpenedWithId}
/>
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import { getMetadataFromCollection } from "../getMetadataFromCollection"
import { useCollection } from "../states"
import { useUpdateCollection } from "../useUpdateCollection"

export const EditCollectionDialog: FC<{
open: boolean
id: string | undefined
export const RenameCollectionDialog: FC<{
openWith: string | undefined
onClose: () => void
}> = ({ onClose, open, id }) => {
}> = ({ onClose, openWith }) => {
const [name, setName] = useState("")
const { data: collection } = useCollection({
id
id: openWith
})
const { mutate: editCollection } = useUpdateCollection()

Expand All @@ -37,11 +36,11 @@ export const EditCollectionDialog: FC<{

useEffect(() => {
setName((prev) => title || prev)
}, [title, id])
}, [title, openWith])

return (
<Dialog onClose={onInnerClose} open={open}>
<DialogTitle>{getMetadataFromCollection(collection)?.title}</DialogTitle>
<Dialog onClose={onInnerClose} open={!!openWith}>
<DialogTitle>{title}</DialogTitle>
<DialogContent>
<TextField
autoFocus
Expand All @@ -59,7 +58,7 @@ export const EditCollectionDialog: FC<{
<Button
onClick={() => {
onInnerClose()
id && onConfirm(id, name)
openWith && onConfirm(openWith, name)
}}
>
Save
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/collections/CollectionDetailsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import CollectionBgSvg from "../assets/series-bg.svg"
import { useCollection } from "./states"
import { BookListWithControls } from "../books/bookList/BookListWithControls"
import { useVisibleBookIds } from "../books/states"
import { useCollectionActionsDrawer } from "../library/collections/CollectionActionsDrawer/useCollectionActionsDrawer"
import { signal, useSignalValue } from "reactjrx"
import {
ListActionSorting,
ListActionViewMode
} from "../common/lists/ListActionsToolbar"
import { useCollectionActionsDrawer } from "./CollectionActionsDrawer/useCollectionActionsDrawer"

type ScreenParams = {
id: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CollectionDocType } from "@oboku/shared"
import { Cover } from "../../books/Cover"
import { useCollection } from "../states"
import { DeepReadonlyObject } from "rxdb"
import { useCollectionActionsDrawer } from "../../library/collections/CollectionActionsDrawer/useCollectionActionsDrawer"
import { useCollectionActionsDrawer } from "../CollectionActionsDrawer/useCollectionActionsDrawer"

const ListItem = styled(MuiListItem)(() => ({
height: `100%`,
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/collections/useUpdateCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export const useUpdateCollection = () => {
.findOne({ selector: { _id } })
.exec()

item?.atomicUpdate((old) => ({
return item?.atomicUpdate((old) => ({
...old,
...rest,
metadata: old.metadata?.map((entry) =>
entry.type === "user" ? { ...entry, name } : entry
entry.type === "user" ? { ...entry, title: name } : entry
)
}))
}
Expand Down

0 comments on commit c6c2493

Please sign in to comment.