Skip to content

Commit

Permalink
new working stuff innit
Browse files Browse the repository at this point in the history
  • Loading branch information
BurhanCantCode committed Aug 3, 2024
1 parent 98fa455 commit 58bd8ca
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 110 deletions.
9 changes: 8 additions & 1 deletion .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=1038734866325
NEXT_PUBLIC_FIREBASE_APP_ID=1:1038734866325:web:22b09505809154eddb689c
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=G-5E30MTEKSN
NEXT_PUBLIC_GOOGLE_CLOUD_VISION_API_KEY=AIzaSyCmO5hd0NfYV0yaePAva9PKhb4_IN1CdB8
GOOGLE_APPLICATION_CREDENTIALS="D:\pantry tracker\vision-api-key.json"
CLIENT_ID=52357093190-fi3tj2kgdn3e2dsit34n4fu8nn9paj3s.apps.googleusercontent.com
CLIENT_SECRET=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
API_KEY=AIzaSyCmO5hd0NfYV0yaePAva9PKhb4_IN1CdB8
EMAIL=[email protected]
UNIQUE_ID=103921260899615311592
PROJECT_ID=mythic-chalice-425119-r6
PRIVATE_KEY_ID=0c662e178d7e35ea1594f3432d2f9d97b989bbca
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDSFm+rrDBGhGd3\n43KfN3erENOpqLttrM2denpOtNNNiNeaQwxs924wbIqfbsRda4gqlrAp4JIuSQnd\nLnpikGPcoJPaMgo7xeWz6LpBMoXsJHko5288szUL16wQV4svVtlLJXMlBDZ9WyYW\nhYsni9zGopdFGNLVpHCMGEia/jEzailRHxk6FKI5m8yxueriD2Nl9fk5Xh/Oyp7M\nkAHWOvVdfEBUm3li1HZEyKORIBFDaL0eXRrDPH08rveCzylYwXHo1cq5HvqvzMDa\nTtsedSrDXlpZ7sYlpS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UYJ5oqvgwBtqYAVT1CEDrkWeHrRx7vKxo0KX8\ndYEaJMMra0q1Z0Y2RxNe6MBJsxmay5aJBPxvEIZBAoGBAL6c9NER8NiUyTiU8U7G\nT1xeQgQTSTRA+BgI22T/wSNzkkgPoevA/z20mfzMfdS6JkamUop9eZ4yMiS56uvS\n5PsuYv38zT7MyIyFxxmkhi4eGNAHLyU6zIEqv7HhcCOAqynnulZM5I2j37zHgrK+\nOfRQB+3SkwhhLXTVt902f/BT\n-----END PRIVATE KEY-----\n"
42 changes: 6 additions & 36 deletions components/AddProductForm.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useState } from 'react';
import { TextField, Button, Box, Typography, CircularProgress, Dialog, DialogTitle, DialogContent, DialogActions, Snackbar, Alert } from '@mui/material';
import { TextField, Button, Box, Typography, CircularProgress, Dialog, DialogTitle, DialogContent, DialogActions } from '@mui/material';
import { useProducts } from '../hooks/useProducts';
import ImageCapture from './ImageCapture';
import { scanProduct } from '../utils/visionUtils';
import { useAuth } from '../hooks/useAuth';

const AddProductForm = () => {
const [name, setName] = useState('');
Expand All @@ -13,9 +12,7 @@ const AddProductForm = () => {
const [showConfirmation, setShowConfirmation] = useState(false);
const [error, setError] = useState<string | null>(null);
const [potentialLabels, setPotentialLabels] = useState<string[]>([]);
const [successOpen, setSuccessOpen] = useState(false);
const { addProduct } = useProducts();
const { user } = useAuth();

const handleImageCapture = async (imageData: string) => {
console.log('Image data length:', imageData.length);
Expand All @@ -38,7 +35,7 @@ const AddProductForm = () => {
setQuantity(result.quantity.toString());
setPotentialLabels(result.allLabels || []);
setShowConfirmation(true);
} catch (error) {
} catch (error: unknown) {
console.error('Error scanning product:', error);
setError('Failed to identify the product. Please try again or enter the details manually.');
} finally {
Expand All @@ -52,31 +49,10 @@ const AddProductForm = () => {

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!user) {
setError('You must be logged in to add a product');
return;
}
setLoading(true);
setError(null);
try {
await addProduct({ name, quantity: parseInt(quantity, 10) });
console.log('Product added:', { name, quantity });
setName('');
setQuantity('');
setSuccessOpen(true);
} catch (error) {
console.error('Error in handleSubmit:', error);
setError('Failed to add product');
} finally {
setLoading(false);
}
};

const handleCloseSuccess = (event?: React.SyntheticEvent | Event, reason?: string) => {
if (reason === 'clickaway') {
return;
}
setSuccessOpen(false);
await addProduct({ name, quantity: parseInt(quantity, 10) });
setName('');
setQuantity('');
setPrediction(null);
};

return (
Expand Down Expand Up @@ -138,12 +114,6 @@ const AddProductForm = () => {
</Button>
</DialogActions>
</Dialog>

<Snackbar open={successOpen} autoHideDuration={6000} onClose={handleCloseSuccess}>
<Alert onClose={handleCloseSuccess} severity="success" sx={{ width: '100%' }}>
Product added successfully!
</Alert>
</Snackbar>
</Box>
);
};
Expand Down
17 changes: 14 additions & 3 deletions components/AuthModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useAuth } from '../hooks/useAuth';
import { auth } from '../utils/firebaseConfig';
import { createUserWithEmailAndPassword, signInWithEmailAndPassword } from 'firebase/auth';
import { useRouter } from 'next/router';
import { FirebaseError } from 'firebase/app';

interface AuthModalProps {
buttonText?: string;
Expand All @@ -19,7 +20,7 @@ const AuthModal: React.FC<AuthModalProps> = ({ buttonText = "Sign In", fullWidth
const { signIn, signUp } = useAuth();
const router = useRouter();

const handleSubmit = async (e: React.FormEvent) => {
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
setError(null);
try {
Expand All @@ -30,12 +31,22 @@ const AuthModal: React.FC<AuthModalProps> = ({ buttonText = "Sign In", fullWidth
}
setOpen(false);
router.push('/'); // Redirect to the main page
} catch (error) {
} catch (error: unknown) {
console.error('Authentication error:', error);
setError(error.message);
if (error instanceof Error) {
setError(error.message);
} else {
setError('An unexpected error occurred');
}
}
};

// Helper function to extract error message
const getErrorMessage = (error: unknown): string => {
if (error instanceof Error) return error.message;
return String(error);
};

return (
<>
<Button
Expand Down
56 changes: 29 additions & 27 deletions components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Container, Typography, Link, Grid } from '@mui/material';
import { Box, Container, Typography, Link, Grid, IconButton } from '@mui/material';
import GitHubIcon from '@mui/icons-material/GitHub';
import TwitterIcon from '@mui/icons-material/Twitter';
import LinkedInIcon from '@mui/icons-material/LinkedIn';
Expand All @@ -16,37 +16,39 @@ const Footer = () => {
>
<Container maxWidth="lg">
<Grid container spacing={4} justifyContent="space-between">
<Grid item xs={12} sm={6} md={3}>
<Typography variant="h6" color="text.primary" gutterBottom>
Pantry Manager
</Typography>
<Typography variant="body2" color="text.secondary">
Manage your pantry efficiently and effortlessly.
</Typography>
</Grid>
<Grid item xs={12} sm={6} md={3}>
<Typography variant="h6" color="text.primary" gutterBottom>
Quick Links
</Typography>
<Link href="/" color="inherit" display="block">Home</Link>
<Link href="/inventory" color="inherit" display="block">Inventory</Link>
<Link href="/add-product" color="inherit" display="block">Add Product</Link>
</Grid>
<Grid item xs={12} sm={6} md={3}>
<Typography variant="h6" color="text.primary" gutterBottom>
Legal
</Typography>
<Link href="/privacy" color="inherit" display="block">Privacy Policy</Link>
<Link href="/terms" color="inherit" display="block">Terms of Service</Link>
</Grid>
{/* Existing grid items */}
<Grid item xs={12} sm={6} md={3}>
<Typography variant="h6" color="text.primary" gutterBottom>
Connect
</Typography>
<Box sx={{ display: 'flex', gap: 2 }}>
<GitHubIcon />
<TwitterIcon />
<LinkedInIcon />
<IconButton
component="a"
href="https://github.com/BurhanCantCode"
target="_blank"
rel="noopener noreferrer"
aria-label="GitHub"
>
<GitHubIcon />
</IconButton>
<IconButton
component="a"
href="www.linkedin.com/in/burhankhatri"
target="_blank"
rel="noopener noreferrer"
aria-label="LinkedIn"
>
<LinkedInIcon />
</IconButton>
<IconButton
component="a"
href="https://twitter.com/Burhan51712416"
target="_blank"
rel="noopener noreferrer"
aria-label="Twitter"
>
<TwitterIcon />
</IconButton>
</Box>
</Grid>
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions components/ProductList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});

const ProductList: React.FC = () => {
const { products, updateProduct, removeProduct } = useProducts();
const ProductList: React.FC<{ products: Product[] }> = ({ products }) => {
const { updateProduct, removeProduct } = useProducts();
const { user } = useAuth();
const router = useRouter();
const [successOpen, setSuccessOpen] = useState(false);
Expand Down
8 changes: 4 additions & 4 deletions context/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
const signIn = async (email: string, password: string) => {
try {
await signInWithEmailAndPassword(auth, email, password);
} catch (error) {
} catch (error: unknown) {
console.error('Sign in error:', error);
throw error;
throw error instanceof Error ? error : new Error('An unexpected error occurred');
}
};

Expand All @@ -39,9 +39,9 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
const userCredential = await createUserWithEmailAndPassword(auth, email, password);
setUser(userCredential.user);
await incrementUserCount(); // Increment user count on successful sign-up
} catch (error) {
} catch (error: unknown) {
console.error('Sign up error:', error);
throw error;
throw error instanceof Error ? error : new Error('An unexpected error occurred');
}
};

Expand Down
12 changes: 6 additions & 6 deletions hooks/useProducts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const useProducts = () => {
const fetchedProducts = await getProducts(user.uid);
setProducts(fetchedProducts);
setLoading(false);
} catch (err) {
} catch (err: unknown) {
console.error('Error fetching products:', err);
setError(`Failed to fetch products: ${err.message}`);
setError(`Failed to fetch products: ${err instanceof Error ? err.message : 'Unknown error'}`);
setLoading(false);
}
}, [user]);
Expand All @@ -38,10 +38,10 @@ export const useProducts = () => {
try {
const newProduct = await addProductToFirebase(user.uid, product);
setProducts(prevProducts => [...prevProducts, newProduct]);
} catch (err) {
} catch (err: unknown) {
console.error('Error adding product:', err);
setError('Failed to add product');
throw err;
throw err instanceof Error ? err : new Error('Failed to add product');
}
};

Expand All @@ -55,7 +55,7 @@ export const useProducts = () => {
setProducts(prevProducts =>
prevProducts.map(p => p.id === id ? { ...p, quantity } : p)
);
} catch (err) {
} catch (err: unknown) {
console.error('Error updating product:', err);
setError('Failed to update product');
}
Expand All @@ -69,7 +69,7 @@ export const useProducts = () => {
try {
await removeProductFromFirebase(user.uid, id);
setProducts(prevProducts => prevProducts.filter(p => p.id !== id));
} catch (err) {
} catch (err: unknown) {
console.error('Error removing product:', err);
setError('Failed to remove product');
}
Expand Down
9 changes: 9 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const webpack = require('webpack');
require('dotenv').config();

/** @type {import('next').NextConfig} */
const nextConfig = {
Expand All @@ -12,6 +13,14 @@ const nextConfig = {
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
NEXT_PUBLIC_FIREBASE_APP_ID: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
CLIENT_ID: process.env.CLIENT_ID,
CLIENT_SECRET: process.env.CLIENT_SECRET,
API_KEY: process.env.API_KEY,
EMAIL: process.env.EMAIL,
UNIQUE_ID: process.env.UNIQUE_ID,
PROJECT_ID: process.env.PROJECT_ID,
PRIVATE_KEY_ID: process.env.PRIVATE_KEY_ID,
PRIVATE_KEY: process.env.PRIVATE_KEY,
},
webpack: (config, { dev, isServer }) => {
if (!isServer) {
Expand Down
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"@google/generative-ai": "^0.16.0",
"@mui/icons-material": "^5.16.6",
"@mui/material": "^5.16.6",
"@vercel/analytics": "0.1.11",
"dotenv": "^16.4.5",
"firebase": "^9.23.0",
"framer-motion": "^11.3.19",
"next": "12.3.4",
Expand Down
2 changes: 2 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Layout from '../components/Layout';
import { lightTheme, darkTheme } from '../styles/theme';
import '../styles/globals.css';
import { auth } from '../utils/firebaseConfig'; // Import auth
import { Analytics } from '@vercel/analytics/react'

function MyApp({ Component, pageProps }: AppProps) {
const [isDarkMode, setIsDarkMode] = useState(false);
Expand All @@ -31,6 +32,7 @@ function MyApp({ Component, pageProps }: AppProps) {
<Layout toggleTheme={toggleTheme} isDarkMode={isDarkMode}>
<Component {...pageProps} />
</Layout>
<Analytics />
</ThemeProvider>
</AuthProvider>
);
Expand Down
Loading

0 comments on commit 58bd8ca

Please sign in to comment.