|
@@ -4,21 +4,12 @@ import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.lifecycle.ViewModel
|
|
|
import androidx.lifecycle.viewModelScope
|
|
|
import com.example.fitmarcetplacekuzminiv.domain.Constants
|
|
|
-import com.example.fitmarcetplacekuzminiv.domain.Constants.supabase
|
|
|
-import com.google.android.gms.analytics.ecommerce.Product
|
|
|
import io.github.jan.supabase.gotrue.auth
|
|
|
import io.github.jan.supabase.gotrue.providers.builtin.Email
|
|
|
-import io.github.jan.supabase.postgrest.from
|
|
|
-import kotlinx.coroutines.flow.MutableStateFlow
|
|
|
-import kotlinx.coroutines.flow.StateFlow
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
-data class Product(val id: Int, val name: String, val price: Double)
|
|
|
-
|
|
|
class MainViewModel : ViewModel() {
|
|
|
|
|
|
- private val _products = MutableStateFlow<List<Product>>(emptyList())
|
|
|
- val products: StateFlow<List<Product>> = _products
|
|
|
// Состояние для хранения результата авторизации
|
|
|
var authResult = mutableStateOf("")
|
|
|
|
|
@@ -38,20 +29,4 @@ class MainViewModel : ViewModel() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //Обновление для извлечения данных
|
|
|
- fun fetchProducts() {
|
|
|
- viewModelScope.launch {
|
|
|
- try {
|
|
|
- // Fetch data from Supabase or other data source
|
|
|
- val productList = supabase.from("products").select().decodeList<Product>()
|
|
|
- _products.value = productList
|
|
|
- } catch (e: Exception) {
|
|
|
- // Handle the error
|
|
|
- println("Error fetching products: ${e.message}")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|