-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#86 - add progress bar in order to track requests limit
- Loading branch information
1 parent
f0b54fe
commit b35abd3
Showing
15 changed files
with
236 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "gloc", | ||
"version": "10.0.12", | ||
"version": "10.0.14", | ||
"engines": { | ||
"node": "16.19.0", | ||
"npm": "0.39.3" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/_lib/components/LinearProgressWithLabel/LinearProgressWithLabel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { FC } from 'react'; | ||
|
||
import { Box, LinearProgress, Typography } from '@mui/material'; | ||
|
||
import { LinearProgressWithLabelProps } from './LinearProgressWithLabel.types'; | ||
|
||
export const LinearProgressWithLabel: FC< | ||
LinearProgressWithLabelProps | ||
> = props => { | ||
return ( | ||
<Box sx={{ display: 'flex', alignItems: 'center' }}> | ||
<Box sx={{ width: '100%', mr: 1 }}> | ||
<LinearProgress | ||
variant='determinate' | ||
{...props} | ||
color={props.value < 100 ? 'primary' : 'error'} | ||
/> | ||
</Box> | ||
<Box sx={{ minWidth: 35 }}> | ||
<Typography | ||
variant='body2' | ||
sx={{ color: 'text.secondary' }} | ||
>{`${Math.round(props.value)}%`}</Typography> | ||
</Box> | ||
</Box> | ||
); | ||
}; |
5 changes: 5 additions & 0 deletions
5
src/_lib/components/LinearProgressWithLabel/LinearProgressWithLabel.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { LinearProgressProps } from '@mui/material'; | ||
|
||
export type LinearProgressWithLabelProps = LinearProgressProps & { | ||
value: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { SYSTEM_DEFAULTS } from '../../consts/defaults'; | ||
|
||
export type TrackEventsEventName = string; | ||
/** | ||
* YYYY-MM-DD format | ||
*/ | ||
export type TrackEventsCurrentDate = string; | ||
|
||
export type TrackEventsState = Record< | ||
TrackEventsEventName, | ||
{ | ||
hourly: [ | ||
number, | ||
number, | ||
number, | ||
number, | ||
number, | ||
|
||
number, | ||
number, | ||
number, | ||
number, | ||
number, | ||
|
||
number, | ||
number, | ||
number, | ||
number, | ||
number, | ||
|
||
number, | ||
number, | ||
number, | ||
number, | ||
number, | ||
|
||
number, | ||
number, | ||
number, | ||
number, | ||
]; | ||
daily: Record<TrackEventsCurrentDate, number>; | ||
} | ||
>; | ||
|
||
class TrackEvents { | ||
state: TrackEventsState = {}; | ||
|
||
trackEvent = (eventName: TrackEventsEventName) => { | ||
chrome?.storage?.sync?.get( | ||
{ | ||
[SYSTEM_DEFAULTS.STORAGE.EVENTS_STAT.KEY]: | ||
SYSTEM_DEFAULTS.STORAGE.EVENTS_STAT.DEFAULT_VALUE, | ||
}, | ||
result => { | ||
const now = new Date(); | ||
|
||
const currentHour = now.getHours(); | ||
const currentDate = now.toISOString().split('T')[0]; | ||
|
||
const state = { | ||
...result[SYSTEM_DEFAULTS.STORAGE.EVENTS_STAT.KEY], | ||
} as TrackEventsState; | ||
|
||
if (!state[eventName]) { | ||
state[eventName] = { | ||
// @ts-expect-error Everything is okay (array sizes are compatible. I think) | ||
hourly: Array(25).fill(0), | ||
daily: {}, | ||
}; | ||
} | ||
|
||
state[eventName].hourly[currentHour]++; | ||
|
||
if (!state[eventName].daily[currentDate]) { | ||
state[eventName].daily[currentDate] = 0; | ||
} | ||
|
||
state[eventName].daily[currentDate]++; | ||
|
||
chrome.storage?.sync?.set?.( | ||
{ [SYSTEM_DEFAULTS.STORAGE.EVENTS_STAT.KEY]: state }, | ||
() => {}, | ||
); | ||
}, | ||
); | ||
}; | ||
|
||
calculatePercentOfHourlyEventUsage = ({ | ||
state, | ||
eventName, | ||
limit, | ||
}: { | ||
state: TrackEventsState; | ||
eventName: TrackEventsEventName; | ||
limit: number; | ||
}): number => { | ||
const now = new Date(); | ||
|
||
const currentHour = now.getHours(); | ||
|
||
return state[eventName].hourly[currentHour] / (limit / 100); | ||
}; | ||
} | ||
|
||
export const TrackEventsService = new TrackEvents(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters