Skip to content

Commit

Permalink
feat: ability to remove article from bookmarks if it cannot be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
KestasVenslauskas committed Dec 17, 2024
1 parent b5ab7df commit 0aa84ce
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/Theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface Dictionary {
daily_question_vote: string;
close: string;
stream_blocked_warning: string;
remove_from_bookmarks: string;
}

export const strings: Dictionary = {
Expand Down Expand Up @@ -94,6 +95,7 @@ export const strings: Dictionary = {
daily_question_vote: 'BALSUOTI',
close: 'Uždaryti',
stream_blocked_warning: 'Transliacija internetu negalima dėl autorių teisių apribojimų.',
remove_from_bookmarks: 'Pašalinti iš išsaugotų',
};
//#endregion

Expand Down
2 changes: 2 additions & 0 deletions app/components/screenError/ScreenError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import TextComponent from '../text/Text';
interface Props {
style?: ViewStyle;
text: string;
actions?: JSX.Element;
}

const ScreenError: React.FC<React.PropsWithChildren<Props>> = (props) => {
Expand All @@ -16,6 +17,7 @@ const ScreenError: React.FC<React.PropsWithChildren<Props>> = (props) => {
<View style={[styles.container, props.style]}>
<IconScreenError size={64} color={colors.textError} />
<TextComponent style={styles.text}>{props.text}</TextComponent>
{props.actions ? props.actions : null}
</View>
);
};
Expand Down
29 changes: 26 additions & 3 deletions app/screens/article/ArticleScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, {useCallback} from 'react';
import {StyleSheet, View} from 'react-native';
import ArticleContentComponent, {ArticleSelectableItem} from './ArticleContentComponent';
import {ScreenLoader, ScreenError, AdultContentWarning} from '../../components';
import {ScreenLoader, ScreenError, AdultContentWarning, Text, TouchableDebounce} from '../../components';
import {useTheme} from '../../Theme';
import {isDefaultArticle} from '../../api/Types';
import {RouteProp} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
import {MainStackParamList} from '../../navigation/MainStack';
import useArticleScreenState from './useArticleScreenState';
import useArticleAnalytics from './useArticleAnalytics';
import {useArticleStorageStore} from '../../state/article_storage_store';

type ScreenRouteProp = RouteProp<MainStackParamList, 'Article'>;
type ScreenNavigationProp = StackNavigationProp<MainStackParamList, 'Article'>;
Expand All @@ -22,7 +23,13 @@ const ArticleScreen: React.FC<React.PropsWithChildren<Props>> = ({navigation, ro
const {articleId, isMedia} = route.params;
console.log(`articleId: ${articleId}, isMedia: ${isMedia}`);

const {strings} = useTheme();
const {colors, strings} = useTheme();

const articleStorage = useArticleStorageStore.getState();

const isBookmarked = useArticleStorageStore((state) =>
state.savedArticles.some((a) => a.id === route.params.articleId),
);

const [{article, loadingState}, acceptAdultContent] = useArticleScreenState(articleId, isMedia);

Expand Down Expand Up @@ -73,7 +80,23 @@ const ArticleScreen: React.FC<React.PropsWithChildren<Props>> = ({navigation, ro
case 'error': {
return (
<View style={styles.screen}>
<ScreenError text={strings.articleError} />
<ScreenError
text={strings.articleError}
actions={
isBookmarked ? (
<TouchableDebounce
style={{backgroundColor: colors.primary, borderRadius: 6, marginTop: 24}}
onPress={() => {
articleStorage.removeArticle(route.params.articleId);
navigation.goBack();
}}>
<Text style={{color: colors.onPrimary, padding: 12}} fontFamily="SourceSansPro-Regular">
{strings.remove_from_bookmarks}
</Text>
</TouchableDebounce>
) : undefined
}
/>
</View>
);
}
Expand Down

0 comments on commit 0aa84ce

Please sign in to comment.