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

View file

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

View file

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

View file

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