-
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.
Merge pull request #307 from digitalfabrik/LUN-132-favorites
LUN-132: Favorites
- Loading branch information
Showing
33 changed files
with
577 additions
and
218 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,6 @@ | ||
issue_key: LUN-132 | ||
show_in_stores: true | ||
platforms: | ||
- android | ||
- ios | ||
de: Favoriten können nun gespeichert werden. |
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,49 @@ | ||
import React, { ReactElement } from 'react' | ||
import { widthPercentageToDP as wp } from 'react-native-responsive-screen' | ||
import styled from 'styled-components/native' | ||
|
||
import { Document } from '../constants/endpoints' | ||
import AudioPlayer from './AudioPlayer' | ||
import FavoriteButton from './FavoriteButton' | ||
import ImageCarousel from './ImageCarousel' | ||
|
||
const AudioContainer = styled.View` | ||
position: absolute; | ||
bottom: ${wp('-4.5%')}px; | ||
align-self: center; | ||
` | ||
const FavoriteContainer = styled.View` | ||
position: absolute; | ||
top: 0; | ||
right: ${props => props.theme.spacings.md}; | ||
` | ||
|
||
const Container = styled.View` | ||
margin-bottom: ${props => props.theme.spacings.md}; | ||
` | ||
|
||
interface Props { | ||
document: Document | ||
audioDisabled?: boolean | ||
minimized?: boolean | ||
submittedAlternative?: string | null | ||
} | ||
|
||
const DocumentImageSection = ({ | ||
document, | ||
audioDisabled = false, | ||
minimized = false, | ||
submittedAlternative | ||
}: Props): ReactElement => ( | ||
<Container> | ||
<ImageCarousel images={document.document_image} minimized={minimized} /> | ||
<AudioContainer> | ||
<AudioPlayer document={document} disabled={audioDisabled} submittedAlternative={submittedAlternative} /> | ||
</AudioContainer> | ||
<FavoriteContainer> | ||
<FavoriteButton document={document} /> | ||
</FavoriteContainer> | ||
</Container> | ||
) | ||
|
||
export default DocumentImageSection |
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,62 @@ | ||
import { useFocusEffect } from '@react-navigation/native' | ||
import React, { ReactElement } from 'react' | ||
import { widthPercentageToDP as wp } from 'react-native-responsive-screen' | ||
import styled from 'styled-components/native' | ||
|
||
import { StarCircleIconGrey, StarCircleIconGreyFilled } from '../../assets/images' | ||
import { Document } from '../constants/endpoints' | ||
import useLoadAsync from '../hooks/useLoadAsync' | ||
import AsyncStorage from '../services/AsyncStorage' | ||
import { reportError } from '../services/sentry' | ||
|
||
const Icon = styled(StarCircleIconGreyFilled)` | ||
min-width: ${wp('9%')}px; | ||
min-height: ${wp('9%')}px; | ||
` | ||
const IconOutline = styled(StarCircleIconGrey)` | ||
min-width: ${wp('9%')}px; | ||
min-height: ${wp('9%')}px; | ||
` | ||
const Button = styled.TouchableOpacity` | ||
justify-content: center; | ||
align-items: center; | ||
shadow-color: ${props => props.theme.colors.shadow}; | ||
shadow-radius: 5px; | ||
shadow-offset: 1px 1px; | ||
shadow-opacity: 0.5; | ||
` | ||
|
||
interface Props { | ||
document: Document | ||
onFavoritesChanged?: () => void | ||
} | ||
|
||
const FavoriteButton = ({ document, onFavoritesChanged }: Props): ReactElement | null => { | ||
const { data: isFavorite, refresh } = useLoadAsync(AsyncStorage.isFavorite, document.id) | ||
|
||
useFocusEffect(refresh) | ||
|
||
const onPress = async () => { | ||
if (isFavorite) { | ||
await AsyncStorage.removeFavorite(document.id).catch(reportError) | ||
} else { | ||
await AsyncStorage.addFavorite(document.id).catch(reportError) | ||
} | ||
refresh() | ||
if (onFavoritesChanged) { | ||
onFavoritesChanged() | ||
} | ||
} | ||
|
||
if (isFavorite === null) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Button testID={isFavorite ? 'remove' : 'add'} onPress={onPress}> | ||
{isFavorite ? <Icon /> : <IconOutline />} | ||
</Button> | ||
) | ||
} | ||
|
||
export default FavoriteButton |
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,45 @@ | ||
import { NavigationContainer } from '@react-navigation/native' | ||
import { fireEvent, waitFor } from '@testing-library/react-native' | ||
import React from 'react' | ||
|
||
import AsyncStorage from '../../services/AsyncStorage' | ||
import DocumentBuilder from '../../testing/DocumentBuilder' | ||
import render from '../../testing/render' | ||
import FavoriteButton from '../FavoriteButton' | ||
|
||
describe('FavoriteButton', () => { | ||
const document = new DocumentBuilder(1).build()[0] | ||
|
||
const renderFavoriteButton = () => | ||
render( | ||
<NavigationContainer> | ||
<FavoriteButton document={document} /> | ||
</NavigationContainer> | ||
) | ||
|
||
it('should add favorite on click', async () => { | ||
await AsyncStorage.setFavorites([]) | ||
await expect(AsyncStorage.isFavorite(document.id)).resolves.toBe(false) | ||
|
||
const { getByTestId } = renderFavoriteButton() | ||
|
||
await waitFor(() => expect(getByTestId('add')).toBeTruthy()) | ||
fireEvent.press(getByTestId('add')) | ||
|
||
await waitFor(() => expect(getByTestId('remove')).toBeTruthy()) | ||
await expect(AsyncStorage.isFavorite(document.id)).resolves.toBe(true) | ||
}) | ||
|
||
it('should remove favorite on click', async () => { | ||
await AsyncStorage.setFavorites([document.id]) | ||
await expect(AsyncStorage.isFavorite(document.id)).resolves.toBe(true) | ||
|
||
const { getByTestId } = renderFavoriteButton() | ||
|
||
await waitFor(() => expect(getByTestId('remove')).toBeTruthy()) | ||
fireEvent.press(getByTestId('remove')) | ||
|
||
await waitFor(() => expect(getByTestId('add')).toBeTruthy()) | ||
await expect(AsyncStorage.isFavorite(document.id)).resolves.toBe(false) | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -147,5 +147,6 @@ | |
"word": "Wort", | ||
"words": "Wörter", | ||
"customModalCancel": "Zurück" | ||
} | ||
}, | ||
"favorites": "Favoriten" | ||
} |
Oops, something went wrong.