Skip to content

Commit

Permalink
feat: toggle profiling logs (dev mode only)
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Nov 2, 2023
1 parent e93edf5 commit b69249d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/locales/lib/human/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -675,5 +675,6 @@
"include_sponsored": "Include Sponsored",
"showcase_color": "Showcase Color",
"partner_color": "Partner Color",
"disable": "Disable {{- name}}"
"disable": "Disable {{- name}}",
"profiling": "Profiling"
}
7 changes: 4 additions & 3 deletions src/components/Map.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
// @ts-check
import * as React from 'react'

import { useStatic } from '@hooks/useStore'
import { useStatic, useStore } from '@hooks/useStore'
import Utility from '@services/Utility'
import FilterPermCheck from './QueryData'

export default function Map() {
Utility.analytics(window.location.pathname)

const ready = useStatic((s) => !!s.map && !!s.Icons)
const ui = useStatic((state) => state.ui)
const ui = useStatic((s) => s.ui)
const profiling = useStore((s) => s.profiling)

if (!ready) return null
return (
<>
{Object.keys({ ...ui, ...ui.wayfarer, ...ui.admin }).map((category) => {
if (category === 'settings') return null
return process.env.NODE_ENV === 'development' ? (
return process.env.NODE_ENV === 'development' && profiling ? (
<React.Profiler
key={category}
id={category}
Expand Down
8 changes: 8 additions & 0 deletions src/components/layout/drawer/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import StyleIcon from '@mui/icons-material/Style'
import DevicesOtherIcon from '@mui/icons-material/DevicesOther'
import Brightness7Icon from '@mui/icons-material/Brightness7'
import CakeIcon from '@mui/icons-material/Cake'
import InsightsIcon from '@mui/icons-material/Insights'

import { useTranslation } from 'react-i18next'

Expand Down Expand Up @@ -162,6 +163,13 @@ export default function Settings() {
</ListItemIcon>
</BoolToggle>
))}
{process.env.NODE_ENV === 'development' && (
<BoolToggle field="profiling" label={t('profiling')}>
<ListItemIcon>
<InsightsIcon />
</ListItemIcon>
</BoolToggle>
)}
{!separateDrawerActions && (
<>
<Divider style={{ margin: '10px 0' }} />
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { persist } from 'zustand/middleware'
* scannerCooldown: number
* icons: Record<string, string>
* userSettings: Record<string, any>
* profiling: boolean
* setAreas: (areas: string | string[], validAreas: string[], unselectAll?: boolean) => void,
* }} UseStore
* @type {import("zustand").UseBoundStore<import("zustand").StoreApi<UseStore>>}
Expand Down Expand Up @@ -101,6 +102,7 @@ export const useStore = create(
},
motdIndex: 0,
scannerCooldown: 0,
profiling: false,
}),
{
name: 'local-state',
Expand Down

0 comments on commit b69249d

Please sign in to comment.