create button works

This commit is contained in:
ImAliant 2023-12-05 21:48:30 +01:00
parent c114ed74f6
commit 91bdab8f81
4 changed files with 6 additions and 8 deletions

View file

@ -53,8 +53,7 @@ fun HomeScreen(padding: PaddingValues, model: HomeViewModel = viewModel()) {
if (wantToCreate) {
CreationDialog(
annuler = {model.setCreation(false)},
confirmer = {model.setCreation(false)},
annuler = {(model::setCreation)(false)},
model = model
)
}
@ -114,7 +113,6 @@ fun HomeScreen(padding: PaddingValues, model: HomeViewModel = viewModel()) {
@Composable
fun CreationDialog(
annuler: () -> Unit,
confirmer: () -> Unit,
model : HomeViewModel = viewModel()
) {
val sujet by model.sujet
@ -126,13 +124,12 @@ fun CreationDialog(
OutlinedTextField(
sujet,
label = { Text("Nouveau sujet") },
onValueChange = { model.onSujetChange(it) }
onValueChange = model::onSujetChange
)
},
confirmButton = {
Button(
// TODO : on ajoute le sujet dans la liste des sujets
onClick = confirmer,
onClick = model::addSet,
content = { Text("Ajouter") }
)
},

View file

@ -7,7 +7,7 @@ import androidx.room.RoomDatabase
@Database(
entities = [SetQuestions::class, Question::class, Sets::class],
version = 1,
version = 2,
)
abstract class QuestionsDB : RoomDatabase() {
abstract fun memoDao(): MemoDao

View file

@ -4,7 +4,7 @@ import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
@Entity(indices = [Index(value = ["name"])])
@Entity(indices = [Index(value = ["name"], unique = true)])
data class SetQuestions(
@PrimaryKey(autoGenerate = true) val idSet: Int = 0,
val name: String,

View file

@ -56,6 +56,7 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
}
sujet.value = ""
wantToCreate.value = false
}
}