Destroy cards that are considered "learned"
The goal isn't to hoard unlimited storage space on the user's device, just use the space for as long as necessary to learn a word
This commit is contained in:
parent
51122cceef
commit
3edef0736c
@ -73,11 +73,11 @@ export async function addCategory(category: Category) {
|
|||||||
export async function removeExpression(expression_id: number) {
|
export async function removeExpression(expression_id: number) {
|
||||||
return await database.transaction(
|
return await database.transaction(
|
||||||
"rw",
|
"rw",
|
||||||
database.expression_sets,
|
database.expressions,
|
||||||
database.expression_to_category,
|
database.expression_to_category,
|
||||||
database.expression_to_expression_set,
|
database.expression_to_expression_set,
|
||||||
() => {
|
() => {
|
||||||
database.expression_sets.where({ id: expression_id }).delete();
|
database.expressions.where({ id: expression_id }).delete();
|
||||||
database.expression_to_category.where({ expression_id }).delete();
|
database.expression_to_category.where({ expression_id }).delete();
|
||||||
database.expression_to_expression_set.where({ expression_id }).delete();
|
database.expression_to_expression_set.where({ expression_id }).delete();
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,30 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import { useExpressionSetQueryId } from "../../hooks";
|
import { useExpressionSetQueryId } from "../../hooks";
|
||||||
import { assignExpressionToSet } from "../../model";
|
import { assignExpressionToSet, database, removeExpression } from "../../model";
|
||||||
|
|
||||||
// TODO fix promotion algorithm so it uses a destination expression_set_id
|
|
||||||
|
|
||||||
export interface PromoteExpressionButtonProps {
|
export interface PromoteExpressionButtonProps {
|
||||||
expression_id: number;
|
expression_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "Promote" action will destroy the card if it's learning level is already at top level
|
||||||
|
// TODO notify user of card deletion
|
||||||
|
|
||||||
export function PromoteExpressionButton({
|
export function PromoteExpressionButton({
|
||||||
expression_id,
|
expression_id,
|
||||||
}: PromoteExpressionButtonProps) {
|
}: PromoteExpressionButtonProps) {
|
||||||
const expression_set_id = useExpressionSetQueryId();
|
const expression_set_id = useExpressionSetQueryId();
|
||||||
const handleClick = useCallback(() => {
|
const handleClick = useCallback(async () => {
|
||||||
|
const existing_next_level = await database.expression_sets
|
||||||
|
.where({ id: expression_set_id + 1 })
|
||||||
|
.first();
|
||||||
|
if (existing_next_level) {
|
||||||
assignExpressionToSet({
|
assignExpressionToSet({
|
||||||
expression_id,
|
expression_id,
|
||||||
expression_set_id: expression_set_id + 1,
|
expression_set_id: expression_set_id + 1,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
removeExpression(expression_id);
|
||||||
|
}
|
||||||
}, [expression_id, expression_set_id]);
|
}, [expression_id, expression_set_id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user