Skip to content

Commit

Permalink
Updates, optimization and bug fix mofification
Browse files Browse the repository at this point in the history
  • Loading branch information
Jersyfi committed Jan 8, 2023
1 parent 58d6cb4 commit 700fafe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 37 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to `react-cookify` will be documented in this file.

## v0.3.4-beta.1 - 2022-01-08

- Bump @rollup/plugin-typescript from 10.0.1 to 11.0.0
- Removed `changeDataState()` and directly integrated the code in `actionCheckbox()`
- Removed `setMemoryDataWithChange()` and directly integrated the code in `actionCheckbox()`
- Added script `build:watch` for development
- Modified `handleConsentObjectChange()` to fix the issue of [#2](https://github.com/Jersyfi/react-cookify/issues/2)

## v0.2.1-beta.1 - 2022-01-07

- Added `@rollup/plugin-terser` to minify and compress the code in build process
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "react-cookify",
"version": "0.2.1-beta.1",
"version": "0.3.4-beta.1",
"description": "Simple, customizable open source cookie consent banner for GDPR law",
"scripts": {
"lint": "eslint src/**/*.{js,jsx,ts,tsx,json}",
"build": "rollup -c --bundleConfigAsCjs"
"build": "rollup -c --bundleConfigAsCjs",
"build:watch": "rollup -c --bundleConfigAsCjs -w"
},
"repository": {
"type": "git",
Expand Down
50 changes: 15 additions & 35 deletions src/context/useCookify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,6 @@ export const useCookify = (options: CookifyOptionsType) => {
)
}

/**
* Set memory data with change
*/
const setMemoryDataWithChange = () => {
if (_this.saveWithChange === true) {
setMemoryData()
handleConsentTrackingChange()
}
}

/**
* Changes the cookie state and saves the data
*
* @param {string} type
* @param {boolean} value
*/
const changeDataState = (type: string, value: boolean) => {
const newConsentObjectViewed: boolean = consentObject.viewed
const newConsentObjectData: ConsentObjectDataType = consentObject.data

newConsentObjectData[type] = value

handleConsentObjectChange({
viewed: newConsentObjectViewed,
data: newConsentObjectData
})
setMemoryDataWithChange()
}

/**
* Event Listeners
*/
Expand All @@ -111,8 +82,20 @@ export const useCookify = (options: CookifyOptionsType) => {
* @param {string} type
*/
const actionCheckbox = (type: string) => {
changeDataState(type, !consentObject.data[type])
setMemoryDataWithChange()
const newConsentObjectViewed: boolean = consentObject.viewed
const newConsentObjectData: ConsentObjectDataType = consentObject.data

newConsentObjectData[type] = !consentObject.data[type]

handleConsentObjectChange({
viewed: newConsentObjectViewed,
data: newConsentObjectData
})

if (_this.saveWithChange === true) {
setMemoryData()
handleConsentTrackingChange()
}
}

/**
Expand Down Expand Up @@ -185,10 +168,7 @@ export const useCookify = (options: CookifyOptionsType) => {
const [consentTracking, setConsentTracking] = useState(0)

const handleConsentObjectChange = (newConsentObject: ConsentObjectType) => {
setConsentObject(prevConsentObject => ({
...prevConsentObject,
newConsentObject
}))
setConsentObject(newConsentObject)
}

const handleConsentDisplayedChange = (newConsentDisplayed: boolean) => {
Expand Down

0 comments on commit 700fafe

Please sign in to comment.