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

feat: toggle profiling logs (dev mode only) #873

Merged
merged 1 commit into from
Nov 2, 2023
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: 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