From 57ebcaddbbe8aef77c2d88380931322f208fdd4c Mon Sep 17 00:00:00 2001 From: Jan Tennert Date: Fri, 28 Jun 2024 12:49:37 +0200 Subject: [PATCH] feat: connect Kotlin example (#27313) * Add Kotlin connect * fix key * Fix some mistakes * Update content.tsx --- .../Home/Connect/Connect.constants.ts | 14 ++++ .../androidkotlin/supabasekt/content.tsx | 83 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 apps/studio/components/interfaces/Home/Connect/content/androidkotlin/supabasekt/content.tsx diff --git a/apps/studio/components/interfaces/Home/Connect/Connect.constants.ts b/apps/studio/components/interfaces/Home/Connect/Connect.constants.ts index 355050b9a7c..24bb9cec4a9 100644 --- a/apps/studio/components/interfaces/Home/Connect/Connect.constants.ts +++ b/apps/studio/components/interfaces/Home/Connect/Connect.constants.ts @@ -206,6 +206,20 @@ export const MOBILES: ConnectionType[] = [ }, ], }, + { + key: 'androidkotlin', + label: 'Android Kotlin', + icon: 'kotlin', + guideLink: 'https://supabase.com/docs/guides/getting-started/tutorials/with-kotlin', + children: [ + { + key: 'supabasekt', + label: 'supabase-kt', + children: [], + icon: 'supabase', + }, + ], + }, ] export const ORMS: ConnectionType[] = [ diff --git a/apps/studio/components/interfaces/Home/Connect/content/androidkotlin/supabasekt/content.tsx b/apps/studio/components/interfaces/Home/Connect/content/androidkotlin/supabasekt/content.tsx new file mode 100644 index 00000000000..7e866e184ea --- /dev/null +++ b/apps/studio/components/interfaces/Home/Connect/content/androidkotlin/supabasekt/content.tsx @@ -0,0 +1,83 @@ +import type { ContentFileProps } from 'components/interfaces/Home/Connect/Connect.types' + +import { + ConnectTabs, + ConnectTabTriggers, + ConnectTabTrigger, + ConnectTabContent, +} from 'components/interfaces/Home/Connect/ConnectTabs' +import SimpleCodeBlock from 'components/to-be-cleaned/SimpleCodeBlock' + +const ContentFile = ({ projectKeys }: ContentFileProps) => { + return ( + + + + + + + + + {` +@Serializable +data class TodoItem(val id: Int, val name: String) + `} + + + + + + {` +val supabase = createSupabaseClient( + supabaseUrl = "${projectKeys.apiUrl ?? 'your-project-url'}", + supabaseKey = "${projectKeys.anonKey ?? 'your-anon-key'}" + ) { + install(Postgrest) +} + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + MaterialTheme { + // A surface container using the 'background' color from the theme + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background + ) { + TodoList() + } + } + } + } +} + +@Composable +fun TodoList() { + var items by remember { mutableStateOf>(listOf()) } + LaunchedEffect(Unit) { + withContext(Dispatchers.IO) { + items = supabase.from("todos") + .select().decodeList() + } + } + LazyColumn { + items( + items, + key = { item -> item.id }, + ) { item -> + Text( + item.name, + modifier = Modifier.padding(8.dp), + ) + } + } +} +`} + + + + ) +} + +export default ContentFile