Skip to content

Commit

Permalink
add github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
moatazeldebsy committed Dec 3, 2024
1 parent 43ff34a commit ab5cb3c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { HashRouter as Router, Routes, Route } from 'react-router-dom';
import { Navbar } from './components/layout/Navbar';
import { Navigation } from './components/layout/Navigation';
Expand Down
25 changes: 25 additions & 0 deletions src/database/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { UserDB } from './db';
import { predefinedUsers } from '../data/users';

export async function initializeDatabase() {
try {
// Check if test user exists
const testUser = await UserDB.findByEmail('[email protected]');

if (!testUser) {
// Initialize predefined users if they don't exist
for (const user of predefinedUsers) {
const existingUser = await UserDB.findByEmail(user.email);
if (!existingUser) {
await UserDB.create({
email: user.email,
password: user.password,
name: user.name
});
}
}
}
} catch (error) {
console.error('Failed to initialize database:', error);
}
}
14 changes: 9 additions & 5 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.tsx';
import './index.css';
import { initializeDatabase } from './database/init';

createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>
);
// Initialize database before rendering
initializeDatabase().then(() => {
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>
);
});
5 changes: 4 additions & 1 deletion src/store/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,16 @@ export const useStore = create<Store>((set, get) => ({

set((state) => ({
orders: [...state.orders, order],
cart: [], // Clear the cart after successful order
}));
}
},
getOrders: async () => {
const { auth } = get();
if (!auth.user) return [];
return await OrderDB.findByUser(auth.user.id);
const orders = await OrderDB.findByUser(auth.user.id);
set({ orders }); // Update the orders in the store
return orders;
},

// Auth
Expand Down

0 comments on commit ab5cb3c

Please sign in to comment.