Skip to content

Commit

Permalink
feat: 카드 뭉치 삭제/초기화/이름을 변경할 수 있다. (#17)
Browse files Browse the repository at this point in the history
* 🧪 LearnsetList test 추가

* ✨ Dashboard에서 카드 뭉치 목록 렌더링
  • Loading branch information
padosum committed Mar 1, 2023
1 parent 15ed894 commit c15aa96
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 11 deletions.
77 changes: 77 additions & 0 deletions src/components/LearnsetList.vue
@@ -0,0 +1,77 @@
<template>
<div>
<v-card class="mx-auto" variant="outlined">
<v-card-item>
<div>
<div class="text-h6 font-weight-bold mb-1">당신의 카드 뭉치</div>
<div class="text-caption">
학습을 위해 추가된 카드 뭉치 목록입니다.
</div>
</div>
</v-card-item>
<v-card-text>
<v-list lines="two">
<v-list-item
v-for="learnset in learnsets"
:key="learnset.id"
:title="learnset.name"
active-color="primary"
@click="moveLearnset(learnset.id)"
>
<template v-slot:append>
<BaseButton
text=""
color="grey-lighten-1"
variant="text"
@click.stop="deleteLearnset({ id: learnset.id })"
>
<v-icon icon="mdi-delete"></v-icon>
</BaseButton>
</template>
</v-list-item>
</v-list>
</v-card-text>
</v-card>
</div>
</template>

<script setup lang="ts">
import BaseButton from '@/components/BaseButton.vue';
import { MutationTypes } from '@/store/mutations';
import type { MyStore } from '@/store/types';
import type { Learnset } from '@/types/interfaces';
import type { PropType } from 'vue';
import { useRouter } from 'vue-router';
import { useStore } from 'vuex';
defineProps({
learnsets: {
type: Array as PropType<Array<Learnset>>,
required: true,
},
});
const store: MyStore = useStore();
const deleteLearnset = ({ id }: { id: string }) => {
const [learnset] = store.getters.learnset(id);
const deleteLearnset = confirm(
`"${learnset.name}" 카드 뭉치를 삭제하시겠습니까?`
);
if (deleteLearnset) {
router.push('/');
store.commit(MutationTypes.DELETE_LEARNSET, learnset);
}
return;
};
const router = useRouter();
const moveLearnset = (id: string) => {
router.push(`/learnset/${id}`);
};
</script>

<style scoped></style>
36 changes: 36 additions & 0 deletions src/components/__tests__/LearnsetList.spec.ts
@@ -0,0 +1,36 @@
import vuetify from '@/utils/setupVuetify';
import { render } from '@testing-library/vue';
import LearnsetList from '@/components/LearnsetList.vue';

describe(`LearnsetList Component`, () => {
it(`카드 뭉치 이름과 삭제 버튼이 렌더링된다.`, () => {
const learnsets = [
{
id: '',
name: '카드 뭉치 1',
created: 0,
cards: [],
},
{
id: '',
name: '카드 뭉치 2',
created: 0,
cards: [],
},
];

const { getByText, getAllByRole } = render(LearnsetList, {
global: {
plugins: [vuetify],
},
props: {
learnsets,
},
});

expect(getByText(learnsets[0].name)).toBeInTheDocument();
expect(getByText(learnsets[1].name)).toBeInTheDocument();

expect(getAllByRole('button').length).toBe(2);
});
});
48 changes: 37 additions & 11 deletions src/views/DashboardView.vue
@@ -1,14 +1,31 @@
<template>
<div class="d-flex">
<div class="pa-10">
<BaseButton text="카드 뭉치 추가하기" @click="importLearnset" />
<AddLearnsetModal
:learnset-title="mdFile.name"
title="카드 뭉치 추가하기"
ref="modal"
@add-learnset="addLearnset"
/>
<v-container class="container mb-10">
<div class="d-flex flex-column fill-height justify-center align-center">
<h1 class="text-h4 font-weight-black mb-4">FlashMD</h1>
<h4 class="subheading">
Markdown으로 작성된 파일로 flash card를 만들어 학습해 보세요!
</h4>
</div>
</v-container>
<div class="d-flex flex-column w-100 align-center">
<h5 class="font-weight-thin mb-2">
아래 버튼을 클릭해 카드 뭉치를 추가하거나 목록에서 카드 뭉치를 선택해
학습을 시작하세요.
</h5>
<BaseButton text="카드 뭉치 추가하기" @click="importLearnset" />
<AddLearnsetModal
:learnset-title="mdFile.name"
title="카드 뭉치 추가하기"
ref="modal"
@add-learnset="addLearnset"
/>

<v-divider></v-divider>
<v-container>
<v-sheet class="pa-6 mx-auto" max-width="1000">
<LearnsetList v-if="learnsets" :learnsets="learnsets" />
</v-sheet>
</v-container>
</div>
</template>

Expand All @@ -18,6 +35,7 @@ import type { File } from '@/types/interfaces';
import BaseButton from '@/components/BaseButton.vue';
import AddLearnsetModal from '@/components/AddLearnsetModal.vue';
import LearnsetList from '@/components/LearnsetList.vue';
import { ref, reactive } from 'vue';
Expand All @@ -28,8 +46,11 @@ import { MutationTypes } from '@/store/mutations';
import { useMarkdownIt } from '@/plugins/markdownit';
import { useRouter } from 'vue-router';
import type { MyStore } from '@/store/types';
const store = useStore();
const store: MyStore = useStore();
const learnsets = store.state.learnsets;
const md = useMarkdownIt();
Expand Down Expand Up @@ -75,4 +96,9 @@ const addLearnset = (name: string) => {
};
</script>

<style scoped></style>
<style scoped>
.container {
height: 300px;
background-color: #d1c4e9;
}
</style>

1 comment on commit c15aa96

@vercel
Copy link

@vercel vercel bot commented on c15aa96 Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

flashmd – ./

flashmd.vercel.app
flash.padosum.dev
flashmd-padosum.vercel.app
flashmd-git-main-padosum.vercel.app

Please sign in to comment.