Skip to content

Commit

Permalink
📝 Add whats new for 5.6.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
SupremeTechnopriest committed Apr 14, 2023
1 parent 6e74183 commit 2650328
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
20 changes: 10 additions & 10 deletions docs/pages/docs/api/props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ set of properties. Examples of how they are used can be found in the

### onPresenceChange
<Property
description="Function to call when the user's presence state changes. This provides a single function to handle all state changes."
description="Function to call when the user's presence state changes. This provides a single function to handle all state changes. The IIdleTimer API is passed in as the second parameter."
type='(presence: PresenceType, idleTimer?: IIdleTimer) => void'
defaultValue='() => {}'
>
Expand All @@ -86,36 +86,36 @@ set of properties. Examples of how they are used can be found in the

### onPrompt
<Property
description='When `promptTimeout` is set, this function is called after the user becomes idle. This is useful for displaying a confirmation prompt. If the prompt timeout is reached, `onIdle` is then called.'
description='When `promptTimeout` is set, this function is called after the user becomes idle. This is useful for displaying a confirmation prompt. If the prompt timeout is reached, `onIdle` is then called. The IIdleTimer API is passed in as the second parameter.'
type='(event?: Event, idleTimer?: IIdleTimer) => void'
defaultValue='() => {}'
/>

### onIdle
<Property
description='Function to call when the user is idle.'
description='Function to call when the user is idle. The IIdleTimer API is passed in as the second parameter.'
type='(event?: Event, idleTimer?: IIdleTimer) => void'
defaultValue='() => {}'
/>

### onActive
<Property
description='Function to call when the user becomes active.'
description='Function to call when the user becomes active. The IIdleTimer API is passed in as the second parameter.'
type='(event?: Event, idleTimer?: IIdleTimer) => void'
defaultValue='() => {}'
/>

### onMessage
### onAction
<Property
description='Function to call when a `message` event is received.'
type='(data: any, idleTimer?: IIdleTimer) => void'
description='Function to call on user activity. The IIdleTimer API is passed in as the second parameter.'
type='(event?: Event, idleTimer?: IIdleTimer) => void'
defaultValue='() => {}'
/>

### onAction
### onMessage
<Property
description='Function to call on user activity.'
type='(event?: Event, idleTimer?: IIdleTimer) => void'
description='Function to call when a `message` event is received. The IIdleTimer API is passed in as the second parameter.'
type='(data: any, idleTimer?: IIdleTimer) => void'
defaultValue='() => {}'
/>

Expand Down
38 changes: 38 additions & 0 deletions docs/pages/docs/getting-started/new.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,44 @@ description: What's new in the latest IdleTimer release
The entire project has been rewritten in typescript for a more robust typescript experience. New issue and pull request templates have been added along with a [contributing](/docs/about/contributing) guide for anyone who would like to contribute to the project. Lastly, this documentation site has been created to serve as a knowledge base for all things related to the IdleTimer project. If you have any ideas for sections, demos or tutorials to add feel free to start a [discussion](https://github.com/supremetechnopriest/react-idle-timer/discussions) or open an [issue](https://github.com/supremetechnopriest/react-idle-timer/issues/new/choose).

## Additions in v5.6.0

All callback functions now pass the `IIdleTimer` interface as the second parameter. This will make it easier to interface with your timer during events. You won't have to rely on hoisting to access the API.

Here is an example using the new callback parameters to close a prompt on user activity:

```ts
const onAction = (event: Event, idleTimer: IIdleTimer) => {
if (idleTimer.isPrompted()) {
idleTimer.activate()
}
}

const onActive = (event: Event, idleTimer: IIdleTimer) => {
if (idleTimer.isPrompted()) {
setOpen(false)
}
}

const onPrompt = () => {
setOpen(true)
}

const onIdle = () => {
setOpen(false)
history.replace('/logout')
}

useIdleTimer({
timeout: 1000 * 60 * 5,
promptBeforeIdle: 1000 * 30,
onAction,
onActive,
onPrompt,
onIdle
})
```

## Deprecations in v5.5.0

The [promptTimeout](/docs/api/props#prompttimeout) property has been deprecated in favor of the [promptBeforeIdle](/docs/api/props#promptbeforeidle). Both properties will continue to work until version `6.0.0`, but it is encouraged to use the new [promptBeforeIdle](/docs/api/props#promptbeforeidle) property. It is easier to reason about one timeout rather than two. The [timeout](/docs/api/props#timeout) property becomes the time until idle and the [promptBeforeIdle](/docs/api/props#promptbeforeidle) property becomes how many milliseconds before idle to emit the [onPrompt](/docs/api/props@onprompt) event. For example, if you want a 30 minute time to idle and a 30 second prompt:
Expand Down
2 changes: 1 addition & 1 deletion docs/public/locales/en/common.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"announcement": {
"message": "⚡️ Version 5.5 is now released!",
"message": "⚡️ Version 5.6 is now released!",
"link": {
"href": "/docs/getting-started/new",
"title": "Find out whats new"
Expand Down

1 comment on commit 2650328

@vercel
Copy link

@vercel vercel bot commented on 2650328 Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.