-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inserting decks to AsyncStorage + reducer/action.
- Loading branch information
1 parent
1c6147c
commit 789f6e6
Showing
6 changed files
with
149 additions
and
44 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 |
---|---|---|
@@ -1,8 +1,16 @@ | ||
export const LOAD_DECKS = "LOAD_DECKS"; | ||
export const NEW_DECK = "NEW_DECK"; | ||
|
||
export function loadDecks(decks){ | ||
return { | ||
action: LOAD_DECKS, | ||
type: LOAD_DECKS, | ||
decks | ||
} | ||
} | ||
|
||
export function newDeck(deck){ | ||
return { | ||
type: NEW_DECK, | ||
deck | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
export function loadDecks() { | ||
return [ | ||
{ id: 1, name: 'Javascript 101', description: 'Basic questions about loops, data types and functions', cards: [], difficulty: 18, won: 10, lost: 3 }, | ||
{ id: 2, name: 'Cryptocurrency', description: 'Main algorithms, PoS, PoW, Bitcoin...', cards: [], difficulty: 58, won: 9, lost: 7 }, | ||
{ id: 3, name: 'Java threads', description: 'Concurrency framework, locks and APIs', cards: [], difficulty: 80, won: 18, lost: 12 }, | ||
{ id: 4, name: 'Unity 5 basics', description: 'Basic components and actions', cards: [], difficulty: 1, won: 6, lost: 1 }, | ||
{ id: 5, name: 'Pro React Native', description: 'Advanced and custom components', cards: [], difficulty: 70, won: 10, lost: 5 }, | ||
{ id: 6, name: 'RESTful', description: 'Verbs, scenarios and status codes', cards: [], difficulty: 60, won: 18, lost: 12 }, | ||
{ id: 7, name: 'Elixir', description: 'Basic structure, loops, running scripts', cards: [], difficulty: 1, won: 6, lost: 1 }, | ||
{ id: 8, name: 'Python 3', description: 'Concepts, changes and new apis', cards: [], difficulty: 22, won: 10, lost: 5 }, | ||
]; | ||
import { AsyncStorage } from 'react-native'; | ||
|
||
const FLASHCARDS_STORAGE_KEY = "Flashcards:decks" | ||
|
||
export async function persistDeck(deck){ | ||
await AsyncStorage.mergeItem(FLASHCARDS_STORAGE_KEY, JSON.stringify({ | ||
[deck.name]: deck | ||
})) | ||
} | ||
|
||
export async function loadDecks() { | ||
const decks = JSON.parse(await AsyncStorage.getItem(FLASHCARDS_STORAGE_KEY)); | ||
return decks !== null ? decks : []; | ||
} |