-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: complete recent viewed feature
- Loading branch information
Showing
21 changed files
with
172 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Recent } from "@/types"; | ||
import { createContext } from "react"; | ||
|
||
export default createContext<RecentContextType>({ setRecent: () => {} }); | ||
|
||
export interface RecentContextType { | ||
recent?: Recent; | ||
setRecent: (recent: Recent) => void; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,28 +1,52 @@ | ||
import { Pressable, Text, View } from "react-native"; | ||
import Doc from "@/assets/icons/doc.svg"; | ||
import ArrowRight from "@/assets/icons/arrow_right.svg"; | ||
import { router } from "expo-router"; | ||
import { router, useFocusEffect } from "expo-router"; | ||
import { storage } from "@/utils"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { Recent } from "@/types"; | ||
|
||
export function MainCard() { | ||
const [recent, setRecent] = useState<Recent>(); | ||
useFocusEffect( | ||
useCallback(() => { | ||
let recentJSON = storage.getString("recent"); | ||
if (recentJSON) setRecent(JSON.parse(recentJSON)); | ||
}, []) | ||
); | ||
|
||
return ( | ||
<View className="mt-5 bg-lotion w-full rounded-[17px] px-6 relative py-6"> | ||
<View className="h-8 flex flex-col justify-center"> | ||
<Text className="font-HelveticaRoman text-xl pt-2 text-primary"> | ||
الفاتحة | ||
</Text> | ||
<Text className="text-secondary/30 font-HelveticaLight">الأية : 1</Text> | ||
</View> | ||
<Pressable | ||
className="flex-[0.2] h-8 flex-row items-center absolute right-3 top-6" | ||
onPress={() => { | ||
router.push("/surah/1"); | ||
}} | ||
> | ||
<Text className=" font-HelveticaBold text-primary"> | ||
متابعة القراءة | ||
{recent ? ( | ||
<> | ||
<View className="h-10 flex flex-col justify-center"> | ||
<Text className="font-HelveticaRoman text-xl text-primary"> | ||
{recent.type === "surah" ? recent?.name : `الجزء ${recent.id}`} | ||
</Text> | ||
<Text className="text-secondary/30 font-HelveticaLight"> | ||
{recent.type === "surah" | ||
? `الأية : ${recent?.aya}` | ||
: `${recent.name} الأية : ${recent?.aya}`} | ||
</Text> | ||
</View> | ||
<Pressable | ||
className="flex-[0.2] h-8 flex-row items-center absolute right-3 top-6" | ||
onPress={() => { | ||
router.push( | ||
`/${recent.type === "surah" ? "surah" : "jozz"}/${recent.id}` | ||
); | ||
}} | ||
> | ||
<Text className=" font-HelveticaBold text-primary"> | ||
متابعة القراءة | ||
</Text> | ||
<ArrowRight width={22} height={12} className="mt-2" /> | ||
</Pressable> | ||
</> | ||
) : ( | ||
<Text className="text-center font-HelveticaRoman text-primary/20"> | ||
لم يتم قراءة شئ موخرا | ||
</Text> | ||
<ArrowRight width={22} height={12} className="mt-2" /> | ||
</Pressable> | ||
)} | ||
</View> | ||
); | ||
} |
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
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
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,19 @@ | ||
import { useRef } from "react"; | ||
import useOnChange from "./useOnChange"; | ||
import { onAyaChanged } from "."; | ||
|
||
const useOnAyaScrolling = ({ type }: { type?: "surah" | "jozz" }) => { | ||
const { onChange } = useOnChange({ delay: 1000 }); | ||
|
||
const onViewableItemsChanged = ({ viewableItems }: any) => { | ||
onAyaChanged({ viewableItems, onChange, type }); | ||
}; | ||
|
||
const viewabilityConfigCallbackPairs = useRef([{ onViewableItemsChanged }]); | ||
|
||
return { | ||
viewabilityConfigCallbackPairs, | ||
}; | ||
}; | ||
|
||
export default useOnAyaScrolling; |
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,17 @@ | ||
import { useState } from "react"; | ||
|
||
const useOnChange = ({ delay }: { delay?: number }) => { | ||
const [timeout, setTimeOutValue] = useState<NodeJS.Timeout>(); | ||
|
||
const onChange = (callback: () => void) => { | ||
if (timeout) clearTimeout(timeout); | ||
setTimeOutValue( | ||
setTimeout(function () { | ||
callback(); | ||
}, delay || 1000) | ||
); | ||
}; | ||
return { onChange }; | ||
}; | ||
|
||
export default useOnChange; |