Skip to content

Commit

Permalink
feat: support batch master the vocabulary
Browse files Browse the repository at this point in the history
Signed-off-by: saltbo <saltbo@foxmail.com>
  • Loading branch information
saltbo committed Apr 7, 2023
1 parent f65ab14 commit 0319dbe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
5 changes: 4 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ func (a *App) startup(ctx context.Context) {

func (a *App) shutdown(ctx context.Context) {
_ = a.rProxy.Stop(ctx)
_ = a.cm.Save()
if err := a.cm.Save(); err != nil {
log.Println(err)
return
}
}

func (a *App) getCtx() context.Context {
Expand Down
30 changes: 22 additions & 8 deletions frontend/src/components/Vocabulary.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue'
import { ref, reactive, computed, onMounted } from 'vue'
import { GetVocabulary, GetVocabularyList, MasteredWords } from '../../wailsjs/go/relingo/Client';
import { FindNewWords, SubmitVocabulary } from '../../wailsjs/go/service/WordService'
import { model } from '../../wailsjs/go/models';
Expand All @@ -11,11 +11,15 @@ const words = ref<any>([])
const refresh = async () => {
const masteredWords = await MasteredWords(masteredId.value)
const { id, type } = vocabularyTab.value
words.value = (await GetVocabulary(id, type)).map(el => ({ word: el })).filter((el) => {
return masteredWords.indexOf(el.word) == -1
})
words.value = (await GetVocabulary(id, type)).map(el => ({ word: el, checked: false, mastered: masteredWords.indexOf(el) == -1 }))
}
const selectedWords = computed(() => {
console.log(words.value.find((el: any) => el.checked == true));
return words.value.filter((el: any) => el.checked == true).map((el: any) => el.word)
})
const submitVocabulary = (words: string[]) => {
SubmitVocabulary(words).then(refresh)
}
Expand Down Expand Up @@ -55,16 +59,26 @@ onMounted(async () => {
<tbody>
<tr v-for="item in words" :key="item.name">
<td class="text-left">
<span>{{ item.word }}</span>
<v-checkbox :label="item.word" v-model="item.checked"></v-checkbox>
</td>
<td class="text-right">
<v-btn size="small" color="surface-variant ml-3" variant="text" icon="mdi-check-all"
@click="submitVocabulary([item.word || ''])"></v-btn>
<v-btn v-show="!item.mastered" size="small" color="surface-variant ml-3" variant="text"
icon="mdi-check-all" @click="submitVocabulary([item.word || ''])"></v-btn>
</td>
</tr>
</tbody>
</v-table>

<div class="ft" v-show="selectedWords && selectedWords.length > 0">
<v-btn @click="submitVocabulary(selectedWords)">一键掌握</v-btn>
</div>
</main>
</template>

<style scoped></style>
<style scoped>
.ft {
position: fixed;
bottom: 10px;
left: 50%;
}
</style>
1 change: 1 addition & 0 deletions pkg/relingo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (c *Client) MasteredWords(id string) ([]string, error) {
return c.GetVocabulary(id, "mastered")
}

// SubmitVocabulary 标记单词已掌握
func (c *Client) SubmitVocabulary(words []string) error {
vs, err := c.GetVocabularyList()
if err != nil {
Expand Down

0 comments on commit 0319dbe

Please sign in to comment.