Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/config/db.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mongoose from 'mongoose';
import User from '../models/User.js';
import { seedCompanyGuides } from './seedCompanyGuides.js';

const seedAdmin = async () => {
try {
Expand Down Expand Up @@ -59,6 +60,7 @@ const connectDB = async () => {
});
console.log(`MongoDB Connected (Primary): ${conn.connection.host}`);
await seedAdmin();
await seedCompanyGuides();
return;
} catch (error) {
console.warn(`Primary Database connection failed (${error.message}). Trying fallback local database...`);
Expand All @@ -70,6 +72,7 @@ const connectDB = async () => {
const conn = await mongoose.connect(fallbackURI);
console.log(`MongoDB Connected (Local Fallback): ${conn.connection.host}`);
await seedAdmin();
await seedCompanyGuides();
} catch (error) {
console.error(`Database Connection Error: ${error.message}`);
process.exit(1);
Expand Down
57 changes: 57 additions & 0 deletions backend/config/seedCompanyGuides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Company from '../models/Company.js';
import CompanyGuide from '../models/CompanyGuide.js';

const SEED_COMPANIES = [
{ name: 'Tata Consultancy Services', slug: 'tcs', industry: 'IT Services & Consulting', website: 'https://www.tcs.com/', logo: '/images/companies/tcs.png', legacyKeys: ['TCS', 'TCS NQT', 'Tata Consultancy Services'] },
{ name: 'Cognizant', slug: 'cognizant', industry: 'IT Services & Digital Engineering', website: 'https://www.cognizant.com/', logo: '/images/companies/cognizant.png', legacyKeys: ['Cognizant', 'CTS', 'GenC', 'Cognizant ACE'] },
{ name: 'Infosys', slug: 'infosys', industry: 'IT Services & Digital Transformation', website: 'https://www.infosys.com/', logo: '/images/companies/infosys.png', legacyKeys: ['Infosys', 'Infy', 'SP', 'DSE', 'Specialist Programmer'] },
{ name: 'LTIMindtree', slug: 'ltimindtree', industry: 'IT Services & Consulting (L&T Group)', website: 'https://www.ltimindtree.com/', logo: '/images/companies/ltimindtree.png', legacyKeys: ['LTIMindtree', 'LTI', 'Mindtree', 'GET'] },
{ name: 'ITC Infotech', slug: 'itc-infotech', industry: 'IT Services & Digital Engineering (ITC Group)', website: 'https://www.itcinfotech.com/', logo: '/images/companies/itc-infotech.png', legacyKeys: ['ITC Infotech', 'ITC', 'Associate IT Consultant'] },
{ name: 'EY', slug: 'ey', industry: 'IT Services & Technology Consulting (Big Four)', website: 'https://www.ey.com/en_in', logo: '/images/companies/ey.png', legacyKeys: ['EY', 'Ernst & Young', 'EY GDS', 'EY India', 'Associate Software Engineer'] },
{ name: 'PwC', slug: 'pwc', industry: 'IT Services & Technology Consulting (Big Four)', website: 'https://www.pwc.in/', logo: '/images/companies/pwc.png', legacyKeys: ['PwC', 'PricewaterhouseCoopers', 'PwC India', 'PwC SDC', 'Associate Software Development'] },
{ name: 'CloudKaptan', slug: 'cloudkaptan', industry: 'IT Services & Salesforce Cloud Consulting', website: 'https://www.cloudkaptan.com/', logo: '/images/companies/cloudkaptan.png', legacyKeys: ['CloudKaptan', 'Cloud Kaptan', 'CK', 'Apprenticeship', 'Trainee'] },
];

export const seedCompanyGuides = async () => {
try {
console.log('🌱 Starting Company & Company Guide production/deployment seeding...');

// 1. Seed/Upsert Companies
const companyMap = {};
for (const comp of SEED_COMPANIES) {
const updatedCompany = await Company.findOneAndUpdate(
{ slug: comp.slug },
{ $set: { ...comp, isActive: true } },
{ upsert: true, new: true, runValidators: true }
);
companyMap[comp.slug] = updatedCompany._id;
}
console.log(`✓ Seeded/Verified ${Object.keys(companyMap).length} company records.`);

// 2. Ensure all guides exist and are set to published + featured
const count = await CompanyGuide.countDocuments({ status: 'published' });
if (count < 8) {
console.log(`Found ${count} published guides. Running full company guides data sync...`);
// Update any existing guide records to published and featured
await CompanyGuide.updateMany(
{},
{ $set: { status: 'published', featured: true } }
);
}

// Verify all guides are published & featured
await CompanyGuide.updateMany(
{ status: { $ne: 'published' } },
{ $set: { status: 'published', featured: true } }
);
await CompanyGuide.updateMany(
{ featured: { $ne: true } },
{ $set: { featured: true } }
);

const activeFeaturedCount = await CompanyGuide.countDocuments({ status: 'published', featured: true });
console.log(`✅ Production Seeding Complete: ${activeFeaturedCount} company guides active, published & featured!`);
} catch (error) {
console.error('Error seeding company guides:', error.message);
}
};
4 changes: 4 additions & 0 deletions backend/runSeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { seedVerbalQuestions } from './config/seedVerbalQuestions.js';
import { seedBlueprints } from './config/seedBlueprints.js';
import { seedCodingQuestions } from './config/seedCodingQuestions.js';
import { seedTracks } from './config/seedTracks.js';
import { seedCompanyGuides } from './config/seedCompanyGuides.js';

const run = async () => {
try {
Expand Down Expand Up @@ -42,6 +43,9 @@ const run = async () => {
// Seed roadmaps/tracks
await seedTracks();

// Seed companies & company guides
await seedCompanyGuides();

await mongoose.disconnect();
console.log('MongoDB connection closed.');
process.exit(0);
Expand Down
3 changes: 3 additions & 0 deletions frontend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ VITE_API_URL=https://your-backend-name.onrender.com

# Google OAuth Client ID (same value as backend GOOGLE_CLIENT_ID)
VITE_GOOGLE_CLIENT_ID=your_google_client_id_here

# Google Analytics 4 (GA4) Measurement ID
VITE_GA_MEASUREMENT_ID=G-KNM0S28F9W
15 changes: 14 additions & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<!-- ── Content Security Policy (CSP) ────────────────────────────────── -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https:; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com data:; img-src 'self' data: https:; connect-src 'self' https: http://localhost:*;" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https: blob:; worker-src 'self' blob:; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://cdn.jsdelivr.net https://accounts.google.com; font-src 'self' https://fonts.gstatic.com data:; img-src 'self' data: https:; connect-src 'self' https: http://localhost:*; frame-src 'self' https://accounts.google.com;" />

<!-- ── Google Tag (gtag.js) — Google Analytics 4 ────────────────────── -->
<script async src="https://www.googletagmanager.com/gtag/js?id=%VITE_GA_MEASUREMENT_ID%"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

// Configure GA4 with send_page_view: false so React Router manages SPA page views
gtag('config', '%VITE_GA_MEASUREMENT_ID%', {
send_page_view: false
});
</script>

<!-- ── Favicon ──────────────────────────────────────────────────────── -->
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
Expand Down
20 changes: 18 additions & 2 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Frontend entrypoint - authored by Satyam
import React, { useContext } from 'react';
import React, { useContext, useEffect } from 'react';
import { BrowserRouter as Router, Routes, Route, useLocation, useNavigate } from 'react-router-dom';
import { GoogleOAuthProvider } from '@react-oauth/google';
import { AuthProvider, AuthContext } from './context/AuthContext';
import { ThemeProvider } from './context/ThemeContext';
import { AlertTriangle, X } from 'lucide-react';
import { trackPageView } from './utils/analytics';

// Components
import Navbar from './components/Navbar';
Expand Down Expand Up @@ -123,9 +123,25 @@ const Layout = ({ children }) => {
);
};

const AnalyticsTracker = () => {
const location = useLocation();

useEffect(() => {
const path = location.pathname + location.search;
// Small delay to ensure react-helmet-async has updated document.title
const timer = setTimeout(() => {
trackPageView(path, document.title);
}, 100);
return () => clearTimeout(timer);
}, [location.pathname, location.search]);

return null;
};

const AppContent = () => {
return (
<Layout>
<AnalyticsTracker />
<Routes>
{/* Public Routes */}
<Route path="/" element={<Home />} />
Expand Down
31 changes: 31 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,37 @@ iframe {
border-bottom-color: rgba(0, 0, 0, 0.05) !important;
}

/* ── Monaco Editor Focus Ring & Extension Overlay Fix ──────────────────── */
.monaco-editor,
.monaco-editor .overflow-guard,
.monaco-editor textarea,
.monaco-editor textarea.inputarea,
.monaco-editor *:focus,
.monaco-editor *:focus-visible,
.monaco-editor *:focus-within {
outline: none !important;
outline-style: none !important;
outline-width: 0 !important;
box-shadow: none !important;
}

.monaco-editor textarea.inputarea {
background: transparent !important;
background-color: transparent !important;
border: none !important;
resize: none !important;
}

/* Hide browser extension overlays (e.g. Grammarly / LanguageTool) inside Monaco */
.monaco-editor grammarly-extension,
.monaco-editor [data-grammarly-part] {
display: none !important;
}








24 changes: 20 additions & 4 deletions frontend/src/pages/ProblemArena.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,26 @@ const ProblemArena = () => {
if (!str) return '';
return str.replace(/\r\n/g, '\n').trim();
};
if (savedCode !== null && normalize(savedCode) !== '') {
setCode(savedCode);

const isCorruptedTemplate = (str) => {
if (!str) return false;
const idxWrite = str.indexOf('Write your code below:');
const idxDash = str.indexOf('// ----------');
if (idxWrite !== -1 && idxDash !== -1 && idxDash > idxWrite) {
return true;
}
return false;
};

if (savedCode !== null && normalize(savedCode) !== '' && !isCorruptedTemplate(savedCode)) {
const cleanCode = savedCode.replace(/^['`]\s*/, '');
setCode(cleanCode);
} else {
setCode(CODE_TEMPLATES[language] || '');
const defaultTemplate = CODE_TEMPLATES[language] || '';
setCode(defaultTemplate);
if (savedCode && isCorruptedTemplate(savedCode)) {
localStorage.setItem(`nqt_saved_code_${id}_${language}`, defaultTemplate);
}
}
}, [id, question, language]);

Expand Down Expand Up @@ -466,7 +482,7 @@ const ProblemArena = () => {
title="Go to Dashboard"
>
<img src="/logo.svg" alt="NQTCoder Logo" className="h-[30px] w-auto object-contain" />
<span className="text-xs sm:text-sm font-bold tracking-wider text-slate-200 group-hover:text-white transition-colors">
<span className="hidden sm:inline-block text-xs sm:text-sm font-bold tracking-wider text-slate-200 group-hover:text-white transition-colors">
NQT<span className="text-accentBlue">Coder</span>
</span>
</div>
Expand Down
15 changes: 11 additions & 4 deletions frontend/src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ const api = axios.create({
// Interceptor to inject JWT from localStorage
api.interceptors.request.use(
(config) => {
const userInfo = localStorage.getItem('userInfo')
? JSON.parse(localStorage.getItem('userInfo'))
: null;

let userInfo = null;
try {
const stored = localStorage.getItem('userInfo');
if (stored) {
userInfo = JSON.parse(stored);
}
} catch (e) {
console.error('Error parsing userInfo from localStorage:', e);
localStorage.removeItem('userInfo');
}

if (userInfo && userInfo.token) {
config.headers.Authorization = `Bearer ${userInfo.token}`;
}
Expand Down
34 changes: 34 additions & 0 deletions frontend/src/utils/analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Utility functions for Google Analytics 4 (GA4) using the official window.gtag
*/

export const GA_MEASUREMENT_ID = import.meta.env.VITE_GA_MEASUREMENT_ID || 'G-KNM0S28F9W';

/**
* Sends a page_view event to Google Analytics 4
* @param {string} path - The relative path including query params (e.g. '/practice?q=tcs')
* @param {string} [title] - Optional page title
*/
export const trackPageView = (path, title) => {
if (typeof window !== 'undefined' && typeof window.gtag === 'function') {
window.gtag('event', 'page_view', {
page_path: path,
page_title: title || document.title,
send_to: GA_MEASUREMENT_ID,
});
}
};

/**
* Tracks custom user events in Google Analytics 4
* @param {string} action - Event name (e.g., 'submit_solution', 'start_test')
* @param {object} [params] - Custom parameters for the event
*/
export const trackEvent = (action, params = {}) => {
if (typeof window !== 'undefined' && typeof window.gtag === 'function') {
window.gtag('event', action, {
...params,
send_to: GA_MEASUREMENT_ID,
});
}
};
Loading