This repository has been archived by the owner on Jul 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add like and repost syndication targets to settings page
- Loading branch information
1 parent
bc05d11
commit 6cf510f
Showing
7 changed files
with
193 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const setSetting = (key, value) => { | ||
return { | ||
type: 'SET_SETTING', | ||
key: key, | ||
value: value, | ||
}; | ||
} |
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,36 @@ | ||
import { Map } from 'immutable'; | ||
|
||
const emptyState = { | ||
reactions: false, | ||
syndicationProviders: [], | ||
likeSyndication: [], | ||
repostSyndication: [], | ||
}; | ||
|
||
let initialState = new Map(); | ||
for (const key in emptyState) { | ||
const localValue = localStorage.getItem(`together-setting-${key}`); | ||
if (localValue) { | ||
initialState = initialState.set(key, JSON.parse(localValue)); | ||
} else { | ||
initialState = initialState.set(key, emptyState[key]); | ||
} | ||
} | ||
|
||
export default (state = initialState, payload) => { | ||
switch (payload.type) { | ||
case 'SET_SETTING': { | ||
localStorage.setItem(`together-setting-${payload.key}`, JSON.stringify(payload.value)); | ||
return state.set(payload.key, payload.value); | ||
} | ||
case 'LOGOUT': { | ||
return state.map((value, key) => { | ||
localStorage.removeItem(`together-setting-${key}`); | ||
return emptyState[key]; | ||
}); | ||
} | ||
default: { | ||
return state; | ||
} | ||
} | ||
}; |