-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from launchdarkly-labs/tony_remove_db
Tony remove db
- Loading branch information
Showing
12 changed files
with
409 additions
and
603 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,58 +5,33 @@ export const PersonaContext = createContext(null); | |
|
||
export const PersonaProvider = ({ children }) => { | ||
const [personas, setPersonas] = useState([]); | ||
const [error, setError] = useState(null); | ||
|
||
const getPersonas = async () => { | ||
fetch("/api/personas?personaToQuery=all") | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
setPersonas(data); | ||
}) | ||
.catch((error) => { | ||
setError(error.message); | ||
}); | ||
} | ||
|
||
const addPersona = async (newPersona) => { | ||
fetch('/api/personas', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
const getPersonas = () => { | ||
const starterPersonas = [ | ||
{ | ||
personaname: "Cody", | ||
personatype: "Standard User", | ||
personaimage: "standard.jpg", | ||
personaemail: "[email protected]", | ||
}, | ||
body: JSON.stringify(newPersona), | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data && data.error) { | ||
setError(data.error); | ||
} else { | ||
setPersonas(prevPersonas => [...prevPersonas, data]); | ||
} | ||
}) | ||
.catch(error => { | ||
setError('Failed to create new persona. Please try again.'); | ||
}); | ||
}; | ||
|
||
const deleteAllPersonas = async () => { | ||
fetch('/api/personas', { | ||
method: 'DELETE', | ||
}) | ||
.then(response => { | ||
if (response.ok) { | ||
setPersonas([]); | ||
} else { | ||
throw new Error('Failed to delete all personas'); | ||
} | ||
}) | ||
.catch(error => { | ||
setError(error.message); | ||
}); | ||
{ | ||
personaname: "Alysha", | ||
personatype: "Beta User", | ||
personaimage: "beta.png", | ||
personaemail: "[email protected]", | ||
}, | ||
{ | ||
personaname: "Jenn", | ||
personatype: "Developer", | ||
personaimage: "woman.png", | ||
personaemail: "[email protected]", | ||
}, | ||
]; | ||
setPersonas(starterPersonas); | ||
}; | ||
|
||
return ( | ||
<PersonaContext.Provider value={{ personas, error, addPersona, deleteAllPersonas, getPersonas }}> | ||
<PersonaContext.Provider value={{ personas, getPersonas }}> | ||
{children} | ||
</PersonaContext.Provider> | ||
); | ||
|
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
Oops, something went wrong.