Skip to content

Commit

Permalink
Supabase datasource WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fgatti675 committed Sep 16, 2024
1 parent f3c40ba commit 8742251
Show file tree
Hide file tree
Showing 5 changed files with 635 additions and 119 deletions.
200 changes: 83 additions & 117 deletions examples/example_pro/src/SupabaseApp/SupabaseApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "@fontsource/jetbrains-mono";
import {
AppBar,
CircularProgressCenter,
DataSourceDelegate,
Drawer,
FireCMS,
ModeControllerProvider,
Expand All @@ -16,72 +15,39 @@ import {
SnackbarProvider,
useBuildLocalConfigurationPersistence,
useBuildModeController,
useBuildNavigationController,
useValidateAuthenticator
useBuildNavigationController
} from "@firecms/core";

import { useFirebaseStorageSource, useInitialiseFirebase, } from "@firecms/firebase";

import { productsCollection } from "./collections/products_collection";
import { CenteredView } from "@firecms/ui";
import { createClient } from "@supabase/supabase-js";
import { useSupabaseAuthController } from "./useSupabaseAuthController";
import { useSupabaseDelegate } from "./useSupabaseDataSourceDelegate";
import { productsCollection } from "./collections/products_collection";

const NEXT_PUBLIC_SUPABASE_URL="https://aqgwxulqziwzfzxkbhau.supabase.co"
const NEXT_PUBLIC_SUPABASE_ANON_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFxZ3d4dWxxeml3emZ6eGtiaGF1Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjUwNjU2NTcsImV4cCI6MjA0MDY0MTY1N30.NwtGlIkzoGGOJprGIfCQ-Ps_ZS5tevB2OFDtBlgrgBE"
const NEXT_PUBLIC_SUPABASE_URL = "https://aqgwxulqziwzfzxkbhau.supabase.co"
const NEXT_PUBLIC_SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFxZ3d4dWxxeml3emZ6eGtiaGF1Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjUwNjU2NTcsImV4cCI6MjA0MDY0MTY1N30.NwtGlIkzoGGOJprGIfCQ-Ps_ZS5tevB2OFDtBlgrgBE"

const supabase = createClient(NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_ANON_KEY)

async function getProducts() {
const { data } = await supabase.from("Products").select();
console.log(data);
}

getProducts();
function SupabaseApp() {

return "Yo";
// const name = "My FireCMS App";
//
// const {
// firebaseApp,
// firebaseConfigLoading,
// configError
// } = useInitialiseFirebase({
// firebaseConfig
// });
//
// const { app } = useInitRealmMongodb(atlasConfig);
//
// /**
// * Controller used to manage the dark or light color mode
// */
// const modeController = useBuildModeController();
//
// /**
// * Controller for saving some user preferences locally.
// */
// const userConfigPersistence = useBuildLocalConfigurationPersistence();
//
// const authController: MongoAuthController = useMongoDBAuthController({
// app
// });
//
// const cluster = "mongodb-atlas"
// const database = "todo"
//
// const mongoDataSourceDelegate = useMongoDBDelegate({
// app,
// cluster,
// database
// });
//
// /**
// * Controller used for saving and fetching files in storage
// */
// const storageSource = useFirebaseStorageSource({
// firebaseApp
// });
//
const name = "My FireCMS App";

/**
* Controller used to manage the dark or light color mode
*/
const modeController = useBuildModeController();

/**
* Controller for saving some user preferences locally.
*/
const userConfigPersistence = useBuildLocalConfigurationPersistence();

const authController = useSupabaseAuthController({
supabase
});

const supabaseDataSourceDelegate = useSupabaseDelegate({ supabase });

// /**
// * Validate authenticator
// */
Expand All @@ -92,75 +58,75 @@ function SupabaseApp() {
// } = useValidateAuthenticator({
// authController,
// authenticator: () => true,
// dataSourceDelegate: mongoDataSourceDelegate,
// dataSourceDelegate: supbaseDataSourceDelegate,
// storageSource
// });
//
// const navigationController = useBuildNavigationController({
// collections: [productsCollection],
// authController,
// dataSourceDelegate: mongoDataSourceDelegate
// });
//

const navigationController = useBuildNavigationController({
collections: [productsCollection],
authController,
dataSourceDelegate: supabaseDataSourceDelegate
});

// if (firebaseConfigLoading || !firebaseApp) {
// return <>
// <CircularProgressCenter/>
// </>;
// }
//

// if (configError) {
// return <CenteredView>{configError}</CenteredView>;
// }
//
// return (
// <SnackbarProvider>
// <ModeControllerProvider value={modeController}>
//
// <FireCMS
// navigationController={navigationController}
// authController={authController}
// userConfigPersistence={userConfigPersistence}
// dataSourceDelegate={mongoDataSourceDelegate}
// storageSource={storageSource}
//
// >
// {({
// context,
// loading
// }) => {
//
// let component;
// if (loading || authLoading) {
// component = <CircularProgressCenter size={"large"}/>;
// } else {
// if (!canAccessMainView) {
// component = (
// <MongoLoginView
// allowSkipLogin={false}
// authController={authController}
// registrationEnabled={true}
// notAllowedError={notAllowedError}/>
// );
// } else {
// component = (
// <Scaffold
// autoOpenDrawer={false}>
// <AppBar
// title={name}/>
// <Drawer/>
// <NavigationRoutes/>
// <SideDialogs/>
// </Scaffold>
// );
// }
// }
//
// return component;
// }}
// </FireCMS>
// </ModeControllerProvider>
// </SnackbarProvider>
// );

return (
<SnackbarProvider>
<ModeControllerProvider value={modeController}>

<FireCMS
navigationController={navigationController}
authController={authController}
userConfigPersistence={userConfigPersistence}
dataSourceDelegate={supabaseDataSourceDelegate}
// @ts-ignore
storageSource={null}
>
{({
context,
loading
}) => {

let component;
if (loading) {
component = <CircularProgressCenter size={"large"}/>;
} else {
// if (!canAccessMainView) {
// component = (
// <MongoLoginView
// allowSkipLogin={false}
// authController={authController}
// registrationEnabled={true}
// notAllowedError={notAllowedError}/>
// );
// } else {
component = (
<Scaffold
autoOpenDrawer={false}>
<AppBar
title={name}/>
<Drawer/>
<NavigationRoutes/>
<SideDialogs/>
</Scaffold>
);
// }
}

return component;
}}
</FireCMS>
</ModeControllerProvider>
</SnackbarProvider>
);
}

export default SupabaseApp;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { buildCollection } from "@firecms/core";

export const productsCollection = buildCollection<any>({
id: "products",
path: "products",
path: "Products",
name: "Products",
singularName: "Product",
group: "E-commerce",
Expand Down
Loading

0 comments on commit 8742251

Please sign in to comment.