Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 0/cleanup #264

Merged
merged 8 commits into from
Nov 9, 2024
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
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
"@nivo/bar": "^0.87.0",
"@oclif/core": "^4.0.12",
"@oclif/plugin-warn-if-update-available": "^3.1.11",
"@sentry/nestjs": "^8.30.0",
"@sentry/profiling-node": "^8.30.0",
"@tanstack/react-query": "^5.48.0",
"axios": "^1.7.7",
"class-transformer": "^0.5.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ export const useGetAiWeeklyReport = (startOfWeek: string, email?: string) => {

export const useGenerateAiWeeklyReport = () => {
const queryClient = useQueryClient()
let startOfWeek: string
const mutationFn = (body: {
email: string
startOfWeek: string
weeklyReport: CodeClimbers.WeeklyScores
}) => {
startOfWeek = body.startOfWeek
return platformApiRequest({
url: `${PLATFORM_API_URL}/ai-weekly-report`,
method: 'POST',
Expand All @@ -34,9 +32,9 @@ export const useGenerateAiWeeklyReport = () => {
}
return useMutation({
mutationFn,
onSuccess: () => {
onSuccess: (_, variables) => {
queryClient.invalidateQueries({
queryKey: weeklyReportKeys.aiWeeklyReports(startOfWeek),
queryKey: weeklyReportKeys.aiWeeklyReports(variables.startOfWeek),
})
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
progress,
time,
}: SourceTimeChartProps) => {
const theme = useTheme()

Check warning on line 15 in packages/app/src/components/Home/Source/SourceTimeChart.tsx

View workflow job for this annotation

GitHub Actions / build

'theme' is assigned a value but never used

return (
<Grid2
Expand Down Expand Up @@ -41,7 +41,7 @@
/>
</Grid2>
<Grid2>
<Typography variant="body1" color={theme.palette.grey[300]}>
<Typography variant="body1" fontWeight="bold" color="text.secondary">
{time}
</Typography>
</Grid2>
Expand Down
36 changes: 27 additions & 9 deletions packages/app/src/components/common/CodeSnippit/CodeSnippit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,40 @@ export const CodeSnippit = ({ code, onCopy }: CodeSnippitProps) => {
}
}, [])

const copyToClipboard = () => {
const copyToClipboard = async () => {
if (errored || copied) return
if (onCopy) onCopy()
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(code)
setCopied(true)
handleTimer(() => {
setCopied(false)
})
} else {
const textArea = document.createElement('textarea')
textArea.value = code

if (navigator.clipboard) {
navigator.clipboard.writeText(code)?.then(() => {
textArea.style.position = 'absolute'
textArea.style.left = '-999999px'

document.body.prepend(textArea)
textArea.select()

try {
document.execCommand('copy')
setCopied(true)
handleTimer(() => {
setCopied(false)
})
})
} else {
setErrored(true)
handleTimer(() => {
setErrored(false)
})
} catch (error) {
setErrored(true)
handleTimer(() => {
setErrored(false)
})
console.error(error)
} finally {
textArea.remove()
}
}
}

Expand Down
29 changes: 12 additions & 17 deletions packages/app/src/services/feature.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,20 @@ export const isFeatureEnabled = (
state: FeatureState,
): boolean => {
const enabledFeatures = JSON.parse(
localStorage.getItem('enabled-features') || '{}',
localStorage.getItem(`enabled-features-${feature}`) || '',
)
return enabledFeatures[feature] === state
return enabledFeatures === state
}

export const setFeatureEnabled = (feature: FeatureKey, state: FeatureState) => {
const enabledFeatures = JSON.parse(
localStorage.getItem('enabled-features') || '{}',
)
const newEnabledFeatures = { ...enabledFeatures, [feature]: state }
localStorage.setItem('enabled-features', JSON.stringify(newEnabledFeatures))
posthog.capture('$set', {
$set: { 'enabled-features': newEnabledFeatures },
})
}

export const getFeaturePreferences = (): Record<FeatureKey, FeatureState> => {
const enabledFeatures = JSON.parse(
localStorage.getItem('enabled-features') || '{}',
)
return enabledFeatures
let stringState = ''
try {
stringState = JSON.stringify(state)
localStorage.setItem(`enabled-features-${feature}`, stringState)
posthog.capture('$set', {
$set: { [`enabled-features-${feature}`]: state },
})
} catch (error) {
console.error(`Error setting feature enabled-features-${feature}`, error)
}
}
26 changes: 26 additions & 0 deletions packages/server/commands/log/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// oclif command to get the latest 50 lines of error logs from the log file
import { Command, Flags } from '@oclif/core'
import path from 'node:path'
import fs from 'node:fs'
import { CODE_CLIMBER_META_DIR, ERROR_LOG_NAME } from '../../utils/node.util'

export default class Log extends Command {
static description = 'Get the latest 50 lines of error logs'

static flags = {
lines: Flags.string({
char: 'l',
description: 'Number of lines to get',
required: false,
}),
}

async run() {
const { flags } = await this.parse(Log)
const lines = flags.lines || 50
this.log(`Getting latest ${lines} lines of error logs...`)
const errorLogPath = path.join(CODE_CLIMBER_META_DIR, ERROR_LOG_NAME)
const errorLogContent = fs.readFileSync(errorLogPath, 'utf8')
this.log(errorLogContent.split('\n').slice(-lines).join('\n'))
}
}
26 changes: 26 additions & 0 deletions packages/server/commands/log/out.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// oclif command to get the latest 50 lines of error logs from the log file
import { Command, Flags } from '@oclif/core'
import path from 'node:path'
import fs from 'node:fs'
import { CODE_CLIMBER_META_DIR, LOG_NAME } from '../../utils/node.util'

export default class LogOut extends Command {
static description = 'Get the latest 50 lines of error logs'

static flags = {
lines: Flags.string({
char: 'l',
description: 'Number of lines to get',
required: false,
}),
}

async run() {
const { flags } = await this.parse(LogOut)
const lines = flags.lines || 50
this.log(`Getting latest ${lines} lines of logs...`)
const logPath = path.join(CODE_CLIMBER_META_DIR, LOG_NAME)
const logContent = fs.readFileSync(logPath, 'utf8')
this.log(logContent.split('\n').slice(-lines).join('\n'))
}
}
2 changes: 0 additions & 2 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
"@nestjs/schedule": "^4.1.1",
"@nestjs/serve-static": "^4.0.2",
"@oclif/core": "^4.0.17",
"@sentry/nestjs": "^8.25.0",
"@sentry/profiling-node": "^8.25.0",
"axios": "^1.7.7",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
Expand Down
2 changes: 0 additions & 2 deletions packages/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { AllExceptionsFilter } from './filters/allExceptions.filter'
import { RequestLoggerMiddleware } from './common/infrastructure/http/middleware/requestlogger.middleware'
import { ServeStaticModule } from '@nestjs/serve-static'
import { DbModule } from './v1/database/knex'
import { SentryModule } from '@sentry/nestjs/setup'
import { APP_DIST_PATH } from '../utils/node.util'
import { ScheduledTaskModule } from './common/scheduler.module'

@Module({
imports: [
SentryModule.forRoot(),
DbModule,
V1Module,
ScheduledTaskModule,
Expand Down
4 changes: 1 addition & 3 deletions packages/server/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Import this first!
import './sentry'
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
import { Logger, ValidationPipe } from '@nestjs/common'
Expand Down Expand Up @@ -40,7 +38,7 @@ export const bootstrap = async () => {
]
: [
'https://codeclimbers.io',
'chrome-extension://fdmoefklpgbjapealpjfailnmalbgpbe',
/chrome-extension.+$/,
'http://localhost:5173',
/\.codeclimbers\.io$/,
/\.web\.app$/,
Expand Down
15 changes: 0 additions & 15 deletions packages/server/src/sentry.ts

This file was deleted.

41 changes: 18 additions & 23 deletions packages/server/utils/node.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface INodeUtil {
PROJECT_ROOT: string
BIN_PATH: string
START_ERR_LOG_MESSAGE: string
LOG_NAME: string
ERROR_LOG_NAME: string
HOME_DIR: string
CODE_CLIMBER_META_DIR: string
DB_PATH: string
Expand All @@ -35,8 +37,15 @@ abstract class BaseNodeUtil implements INodeUtil {
: path.join(__dirname, '..', '..', '..')
BIN_PATH = path.join(this.PROJECT_ROOT, 'bin')
HOME_DIR = os.homedir()

abstract START_ERR_LOG_MESSAGE: string
LOG_NAME = 'codeclimbers.log'
ERROR_LOG_NAME = 'codeclimbers_error.log'
START_ERR_LOG_MESSAGE = pc.red(`
It seems the server is having trouble starting. Run the command

npx codeclimbers log:error -l 50

to investigate the issue further. You can also refer to https://github.com/CodeClimbersIO/cli/blob/release/docs/Troubleshooting.md or message us on our Discord
`)
abstract CODE_CLIMBER_META_DIR: string
abstract DB_PATH: string
APP_DIST_PATH = path.join(this.PROJECT_ROOT, 'packages', 'app', 'dist')
Expand All @@ -61,13 +70,6 @@ class DarwinNodeUtil extends BaseNodeUtil {
this.CODE_CLIMBER_META_DIR,
isTest() ? 'codeclimber.test.sqlite' : dbName,
)
START_ERR_LOG_MESSAGE = pc.red(`
It seems the server is having trouble starting. Run the command

${pc.white('cat ' + this.CODE_CLIMBER_META_DIR + '/codeclimbers_error.log')}

to investigate the issue further. You can also refer to https://github.com/CodeClimbersIO/cli/blob/release/docs/Troubleshooting.md or message us on our Discord
`)

NODE_PATH = (): string => {
const result = execSync('which node').toString().trim()
Expand All @@ -85,13 +87,8 @@ class WindowsNodeUtil extends BaseNodeUtil {
this.CODE_CLIMBER_META_DIR,
isTest() ? 'codeclimber.test.sqlite' : 'codeclimber.sqlite',
)
START_ERR_LOG_MESSAGE: string = pc.red(`
It seems the server is having trouble starting. Run the command in cmd (not powershell)

${pc.white('more ' + this.CODE_CLIMBER_META_DIR + '\\codeclimbers.err.log')}

to investigate the issue further. You can also refer to https://github.com/CodeClimbersIO/cli/blob/release/docs/Troubleshooting.md or message us on our Discord
`)
LOG_NAME = 'codeclimbers.out.log'
ERROR_LOG_NAME = 'codeclimbers.err.log'

NODE_PATH = (): string => {
const result = execSync('where node').toString().trim()
Expand All @@ -109,13 +106,7 @@ class LinuxNodeUtil extends BaseNodeUtil {
this.CODE_CLIMBER_META_DIR,
isTest() ? 'codeclimber.test.sqlite' : 'codeclimber.sqlite',
)
START_ERR_LOG_MESSAGE = pc.red(`
It seems the server is having trouble starting. Run the command

${pc.white('cat ' + this.CODE_CLIMBER_META_DIR + '/codeclimbers_error.log')}

to investigate the issue further
`)

NODE_PATH = (): string => {
const result = execSync('which node').toString().trim()
return path.dirname(result)
Expand Down Expand Up @@ -146,6 +137,8 @@ export const CODE_CLIMBER_META_DIR = nodeUtil.CODE_CLIMBER_META_DIR
export const DB_PATH = nodeUtil.DB_PATH
export const APP_DIST_PATH = nodeUtil.APP_DIST_PATH
export const CODE_CLIMBER_INI_PATH = nodeUtil.CODE_CLIMBER_INI_PATH
export const LOG_NAME = nodeUtil.LOG_NAME
export const ERROR_LOG_NAME = nodeUtil.ERROR_LOG_NAME
export const NODE_PATH = nodeUtil.NODE_PATH
export const initDBDir = nodeUtil.initDBDir

Expand All @@ -160,6 +153,8 @@ const logPaths = () => {
Logger.debug(HOME_DIR, 'HOME_DIR')
Logger.debug(APP_DIST_PATH, 'APP_DIST_PATH')
Logger.debug(CODE_CLIMBER_INI_PATH, 'CODE_CLIMBER_INI_PATH')
Logger.debug(LOG_NAME, 'LOG_NAME')
Logger.debug(ERROR_LOG_NAME, 'ERROR_LOG_NAME')
}

logPaths()
Expand Down
Loading