-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add watch history and preference page
- Loading branch information
1 parent
5051ef0
commit 9f90f7c
Showing
11 changed files
with
246 additions
and
71 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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ export interface Post { | |
title: string; | ||
link: string; | ||
image: string; | ||
provider?: string; | ||
} | ||
|
||
// getStream | ||
|
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,35 @@ | ||
import {create} from 'zustand'; | ||
import {Post} from '../providers/types'; | ||
import {MMKV} from '../Mmkv'; | ||
export interface History { | ||
history: Post[]; | ||
removeItem: (item: Post) => void; | ||
addItem: (item: Post) => void; | ||
clearHistory: () => void; | ||
} | ||
const showWatchHistory = MMKV.getBool('showRecentlyWatched'); | ||
|
||
const useWatchHistoryStore = create<History>(set => ({ | ||
history: JSON.parse(MMKV.getString('recentlyWatched') || '[]'), | ||
removeItem: item => { | ||
const history = JSON.parse(MMKV.getString('recentlyWatched') || '[]'); | ||
const newHistory = history.filter((i: Post) => i.link !== item.link); | ||
MMKV.setString('recentlyWatched', JSON.stringify(newHistory)); | ||
set({history: newHistory}); | ||
}, | ||
addItem: item => { | ||
if (showWatchHistory) { | ||
const history = JSON.parse(MMKV.getString('recentlyWatched') || '[]'); | ||
const newHistory = history.filter((i: Post) => i.link !== item.link); | ||
newHistory.unshift(item); | ||
MMKV.setString('recentlyWatched', JSON.stringify(newHistory)); | ||
set({history: newHistory}); | ||
} | ||
}, | ||
clearHistory: () => { | ||
MMKV.setString('recentlyWatched', '[]'); | ||
set({history: []}); | ||
}, | ||
})); | ||
|
||
export default useWatchHistoryStore; |
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.