Skip to content

Commit

Permalink
bookmark reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
cglotr committed May 15, 2024
1 parent 7709c55 commit 7f8bd86
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/apis/user_api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface UserApi {
getUserPointer: (email: string, token: string) => Promise<string>
advanceUserPointer: (email: string, token: string) => Promise<string>
reverseUserPointer: (email: string, token: string) => Promise<string>
}
14 changes: 14 additions & 0 deletions src/apis/user_api_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,18 @@ export class UserApiImpl implements UserApi {
const json = await response.json()
return json.data.current_pointer
}

async reverseUserPointer(email: string, token: string): Promise<string> {
const response = await fetch(getUrl("/user/pointer/reverse"), {
method: 'PATCH',
body: JSON.stringify({
email,
}),
headers: {
'x-access-token': token,
}
})
const json = await response.json()
return json.data.current_pointer
}
}
6 changes: 3 additions & 3 deletions src/components/app_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const AppNav = () => {
background: (router.route === '/' || router.route === '/surahs/[id]') ? 'gainsboro' : 'none'
}}
>
Koran
koran
</Button>
&nbsp;
&nbsp;
Expand All @@ -64,7 +64,7 @@ export const AppNav = () => {
background: router.pathname === '/bookmark' ? 'gainsboro' : 'none'
}}
>
Bookmark
bookmark
</Button>
&nbsp;
&nbsp;
Expand All @@ -74,7 +74,7 @@ export const AppNav = () => {
background: router.pathname === '/favs' ? 'gainsboro' : 'none'
}}
>
Favorite
favorite
</Button>
</div>
<LoginButton />
Expand Down
60 changes: 54 additions & 6 deletions src/pages/bookmark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default function BookmarkPage() {
textDecoration: isFav ? undefined : "underline"
}}
>
{!isFav ? "favorite" : <div style={{ fontSize: `${FONT.FONT_SIZE_S}` }}>❤️</div>}
{!isFav ? "🩶" : "❤️"}
</Button>
)
}
Expand All @@ -129,7 +129,7 @@ export default function BookmarkPage() {
})
}}
>
{bookmarkSettings.hideVerse ? "show" : "hide"}&nbsp;verse
{bookmarkSettings.hideVerse ? "🛐" : "☪️"}
</Button>
)
}
Expand All @@ -144,7 +144,7 @@ export default function BookmarkPage() {
})
}}
>
{bookmarkSettings.hideTranslation ? "show" : "hide"}&nbsp;translation
{bookmarkSettings.hideTranslation ? "📕" : "📖"}
</Button>
)
}
Expand Down Expand Up @@ -178,7 +178,42 @@ export default function BookmarkPage() {
justifyContent: 'right'
}}
>
Next
next
</Button>
</>
)
}

const renderReverse = () => {
return (
<>
<Break size={DIMENSIONS.SZ_8} />
<Button
onClick={async () => {
if (isLoading) {
return
}
setIsLoading(true)
triggerGtmUserclick(TRACKING_ACTIONS.BOOKMARK_NEXT)
if (authContext.isLoggedIn() && authContext.user) {
const currentPointer = await wireContext.userApi().reverseUserPointer(authContext.user.email, authContext.user.token)
const parsed = getSurahVerseId(currentPointer)
const verse = await wireContext.koranApi().getVerse(parsed.surah, parsed.verse)

setCurrentPointer(currentPointer)
setVerse(verse)
}
setIsLoading(false)
}}
isLoading={isLoading}
style={{
height: '100vh',
width: '100%',
display: 'flex',
justifyContent: 'left'
}}
>
reverse
</Button>
</>
)
Expand Down Expand Up @@ -216,10 +251,23 @@ export default function BookmarkPage() {
</div>
<div
style={{
textAlign: "right",
display: 'flex',
}}
>
{renderNext()}
<div
style={{
flex: 1,
}}
>
{renderReverse()}
</div>
<div
style={{
flex: 1,
}}
>
{renderNext()}
</div>
</div>
</>
)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function ProfilePage() {
paddingRight: 0,
}}
>
Logout
logout
</Button>
</div>
)
Expand Down

0 comments on commit 7f8bd86

Please sign in to comment.