-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LUN-132: Favorites #307
Merged
Merged
LUN-132: Favorites #307
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
30ab80e
LUN-132: Add assets and fix names
steffenkleinle 230edbe
LUN-132: Add async storage methods and refactor usages
steffenkleinle 596f9a5
LUN-132: Add components and refactor
steffenkleinle 671b7cc
LUN-132: Fix merge
steffenkleinle a9a6421
LUN-132: Add favorites screen
steffenkleinle 79574ab
LUN-132: Handle refreshing and removing of favorites
steffenkleinle 2ca1739
LUN-132: Simplify and fix cannot update on unmounted component
steffenkleinle ca2854e
LUN-132: Fix label
steffenkleinle 80ce352
Merge remote-tracking branch 'origin/main' into LUN-132-favorites
steffenkleinle 6c7e40f
LUN-357: Fix tests
steffenkleinle 70500a2
LUN-357: Rename onFavoritesChanged
steffenkleinle ffcb8f6
LUN-132: Remove server response handling
steffenkleinle f40c041
LUN-132: Change FavoriteButton
ztefanie 5ad0d5a
LUN-132: Fix tests and type
steffenkleinle 23b2758
Merge pull request #311 from digitalfabrik/LUN-132-favorite-use-testID
steffenkleinle 26eda47
LUN-132: Change disciplineId to null if not available
steffenkleinle 3df04ca
LUN-132: Only save ids
steffenkleinle 5b67190
Merge remote-tracking branch 'origin/main' into LUN-132-favorites
steffenkleinle 09b44c8
LUN-132: Fix test
steffenkleinle 5d1959c
LUN-132: fix shadow and alignment
f1sh1918 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 = ({ | ||
steffenkleinle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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,69 @@ | ||
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 labels from '../constants/labels.json' | ||
import useLoadAsync from '../hooks/useLoadAsync' | ||
import AsyncStorage from '../services/AsyncStorage' | ||
import { reportError } from '../services/sentry' | ||
|
||
const Container = styled.View` | ||
padding: ${props => `${props.theme.spacings.xs} 0 ${props.theme.spacings.xs} ${props.theme.spacings.sm}`}; | ||
f1sh1918 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
align-self: center; | ||
` | ||
|
||
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-radius: 5px; | ||
f1sh1918 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
shadow-offset: 1px 1px; | ||
shadow-opacity: 0.5; | ||
` | ||
|
||
interface Props { | ||
document: Document | ||
refreshFavorites?: () => void | ||
} | ||
|
||
const FavoriteButton = ({ document, refreshFavorites }: Props): ReactElement | null => { | ||
const { data: isFavorite, refresh } = useLoadAsync(AsyncStorage.isFavorite, document) | ||
steffenkleinle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
useFocusEffect(refresh) | ||
|
||
const onPress = async () => { | ||
if (isFavorite) { | ||
await AsyncStorage.removeFavorite(document).catch(reportError) | ||
} else { | ||
await AsyncStorage.addFavorite(document).catch(reportError) | ||
} | ||
refresh() | ||
if (refreshFavorites) { | ||
refreshFavorites() | ||
} | ||
} | ||
|
||
if (isFavorite === null) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Container> | ||
<Button accessibilityLabel={isFavorite ? labels.favorites.remove : labels.favorites.add} onPress={onPress}> | ||
steffenkleinle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{isFavorite ? <Icon /> : <IconOutline />} | ||
</Button> | ||
</Container> | ||
) | ||
} | ||
|
||
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,38 @@ | ||
import { fireEvent, waitFor } from '@testing-library/react-native' | ||
import React from 'react' | ||
|
||
import labels from '../../constants/labels.json' | ||
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] | ||
|
||
it('should add favorite on click', async () => { | ||
await AsyncStorage.setFavorites([]) | ||
await expect(AsyncStorage.isFavorite(document)).resolves.toBe(false) | ||
|
||
const { getByA11yLabel } = render(<FavoriteButton document={document} />) | ||
|
||
await waitFor(() => expect(getByA11yLabel(labels.favorites.add)).toBeTruthy()) | ||
fireEvent.press(getByA11yLabel(labels.favorites.add)) | ||
|
||
expect(getByA11yLabel(labels.favorites.remove)).toBeTruthy() | ||
await waitFor(() => expect(AsyncStorage.isFavorite(document)).resolves.toBe(true)) | ||
}) | ||
|
||
it('should remove favorite on click', async () => { | ||
await AsyncStorage.setFavorites([document]) | ||
await expect(AsyncStorage.isFavorite(document)).resolves.toBe(true) | ||
|
||
const { getByA11yLabel } = render(<FavoriteButton document={document} />) | ||
|
||
await waitFor(() => expect(getByA11yLabel(labels.favorites.remove)).toBeTruthy()) | ||
fireEvent.press(getByA11yLabel(labels.favorites.remove)) | ||
|
||
expect(getByA11yLabel(labels.favorites.add)).toBeTruthy() | ||
await waitFor(() => expect(AsyncStorage.isFavorite(document)).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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this broke styling, button is not in the middle any more.