Skip to content
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

feat: storage settings #53

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/screens/settings/components/storage-settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { TrashIcon } from 'lucide-react-native';
import React from 'react';
import { ToastAndroid } from 'react-native';

import { clearWatchedEpisodes } from '@/storage/episode';
import { clearMappings } from '@/storage/media-id';
import { Button, Text, View } from '@/ui';

const StorageSettings = () => {
const handleClearRecentlyData = () => {
clearWatchedEpisodes();

ToastAndroid.show('Cleared cache successfully', ToastAndroid.SHORT);
};

const handleClearMappingData = () => {
clearMappings();

ToastAndroid.show('Cleared cache successfully', ToastAndroid.SHORT);
};

return (
<View>
<Text className="mb-2 text-xl" weight="medium">
Storage
</Text>

<View className="w-full space-y-4">
<View className="flex w-full flex-row items-center justify-between">
<View className="w-4/6">
<Text weight="normal">Clear watched/read cache</Text>
<Text weight="light" className="text-gray-200">
Storing your recently episodes or chapters.
</Text>
</View>

<Button onPress={handleClearRecentlyData}>
<TrashIcon size={24} color="white" />
</Button>
</View>

<View className="flex flex-row items-center justify-between">
<View className="w-4/6">
<Text weight="normal">Clear mapping cache</Text>
<Text weight="light" className="text-gray-200">
Storing mapping between module's media ID and AniList ID.
</Text>
</View>

<Button onPress={handleClearMappingData}>
<TrashIcon size={24} color="white" />
</Button>
</View>
</View>
</View>
);
};

export default StorageSettings;
7 changes: 6 additions & 1 deletion src/screens/settings/screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ScrollView, Text, View } from '@/ui';
import AccountSettings from './components/account-settings';
import AppSettings from './components/app-settings';
import PlayerSettings from './components/player-settings';
import StorageSettings from './components/storage-settings';

const SettingsScreen = () => {
return (
Expand All @@ -22,9 +23,13 @@ const SettingsScreen = () => {
<AccountSettings />
</View>

<View>
<View className="mb-8">
<PlayerSettings />
</View>

<View>
<StorageSettings />
</View>
</View>
</ScrollView>
);
Expand Down
4 changes: 4 additions & 0 deletions src/storage/episode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ export function getWatchedEpisode(mediaId: number): WatchedEpisode | undefined {
(watchedEpisode) => watchedEpisode.mediaId === mediaId
);
}

export const clearWatchedEpisodes = () => {
storage.delete(episodeKey);
};
4 changes: 4 additions & 0 deletions src/storage/media-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ export function getMappings(): Mapping[] {
return [];
}
}

export const clearMappings = () => {
storage.delete(MAPPING_NAMESPACE);
};
Loading