Skip to content

Commit

Permalink
Check plan to duplicate (#3)
Browse files Browse the repository at this point in the history
* Check plan to duplicate
  • Loading branch information
kubk authored Jan 20, 2024
1 parent 4008512 commit 5e3ee74
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/screens/deck-review/deck-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const DeckPreview = observer(() => {
{t("add_card_short")}
</ButtonSideAligned>
) : null}
{userStore.isAdmin && (
{userStore.canDuplicateDecks && (
<ButtonSideAligned
icon={"mdi-content-duplicate mdi-24px"}
outline
Expand Down
1 change: 1 addition & 0 deletions src/store/deck-list-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ vi.mock("../api/api.ts", () => {
{ id: 4, type: "new", deck_id: 2 },
{ id: 5, type: "repeat", deck_id: 1 },
],
plans: [],
myDecks: [
{
id: 1,
Expand Down
2 changes: 1 addition & 1 deletion src/store/deck-list-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class DeckListStore {
.then(
action((result) => {
this.myInfo = result;
userStore.setUser(result.user);
userStore.setUser(result.user, result.plans);
}),
)
.finally(
Expand Down
13 changes: 12 additions & 1 deletion src/store/user-store.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { makeAutoObservable } from "mobx";
import { UserDbType } from "../../functions/db/user/upsert-user-db.ts";
import { assert } from "../lib/typescript/assert.ts";
import { PlansForUser } from "../../functions/db/plan/get-plans-for-user.ts";

export class UserStore {
userInfo?: UserDbType;
plans?: PlansForUser;

constructor() {
makeAutoObservable(this, {}, { autoBind: true });
}

setUser(user: UserDbType) {
setUser(user: UserDbType, plans: PlansForUser) {
this.userInfo = user;
this.plans = plans;
}

get user() {
Expand All @@ -25,6 +28,14 @@ export class UserStore {
return this.user?.is_admin ?? false;
}

get canDuplicateDecks() {
if (this.isAdmin) {
return true;
}

return this.plans?.some((plan) => plan.advanced_duplicate) ?? false;
}

get isSpeakingCardsEnabled() {
return this.user?.is_speaking_card_enabled ?? false;
}
Expand Down

0 comments on commit 5e3ee74

Please sign in to comment.