Skip to content

Commit

Permalink
added reactivity to collections
Browse files Browse the repository at this point in the history
  • Loading branch information
zurdi15 committed Jul 3, 2024
1 parent b1b55f1 commit 2a7def8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
5 changes: 2 additions & 3 deletions backend/endpoints/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def update_collection(
id: int,
remove_cover: bool = False,
artwork: UploadFile | None = None,
) -> MessageResponse:
) -> CollectionSchema:
"""Update collection endpoint
Args:
Expand Down Expand Up @@ -199,8 +199,7 @@ async def update_collection(
{"path_cover_s": path_cover_s, "path_cover_l": path_cover_l}
)

db_collection_handler.update_collection(id, cleaned_data)
return {"msg": f"Collection {cleaned_data['name']} updated successfully!"}
return db_collection_handler.update_collection(id, cleaned_data)


@protected_route(router.delete, "/collections/{id}", ["collections.write"])
Expand Down
2 changes: 1 addition & 1 deletion backend/handler/database/collections_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def update_collection(
.values(**data)
.execution_options(synchronize_session="evaluate")
)
return self.get_collection(id)
return session.query(Collection).filter_by(id=id).one()

@begin_session
def delete_collection(self, id: int, session: Session = None) -> int:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CollectionCard from "@/components/common/Collection/Card.vue";
import RDialog from "@/components/common/RDialog.vue";
import type { UpdatedCollection } from "@/services/api/collection";
import collectionApi from "@/services/api/collection";
import { type Collection } from "@/stores/collections";
import collectionStore, { type Collection } from "@/stores/collections";
import storeHeartbeat from "@/stores/heartbeat";
import type { Events } from "@/types/emitter";
import type { Emitter } from "mitt";
Expand All @@ -14,6 +14,7 @@ import { useDisplay, useTheme } from "vuetify";
const theme = useTheme();
const { mdAndUp } = useDisplay();
const show = ref(false);
const storeCollection = collectionStore();
const collection = ref<UpdatedCollection>({} as UpdatedCollection);
const imagePreviewUrl = ref<string | undefined>("");
const removeCover = ref(false);
Expand Down Expand Up @@ -63,6 +64,7 @@ async function editCollection() {
collection: collection.value,
})
.then(({ data }) => {
storeCollection.update(data);
emitter?.emit("snackbarShow", {
msg: `Collection updated successfully!`,
icon: "mdi-check-bold",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/api/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function updateCollection({
}: {
collection: UpdatedCollection;
removeCover?: boolean;
}): Promise<{ data: MessageResponse }> {
}): Promise<{ data: Collection }> {
const formData = new FormData();
formData.append("name", collection.name || "");
formData.append("description", collection.description || "");
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/stores/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export default defineStore("collections", {
this.all.push(collection);
this._reorder();
},
update(collection: Collection) {
this.all = this.all.map((value) =>
value.id === collection.id ? collection : value,
);
this._reorder();
},
exists(collection: Collection) {
return this.all.filter((p) => p.name == collection.name).length > 0;
},
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/views/Play/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ onMounted(async () => {
})) ?? []
"
/>
<!-- TODO: diisable selector when start playing -->
<!-- TODO: reset emulation to re-select -->
<!-- <v-select
class="my-1"
hide-details
Expand Down

0 comments on commit 2a7def8

Please sign in to comment.