Skip to content

Commit

Permalink
add linkvertise page
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-luger committed Aug 20, 2024
1 parent a532028 commit abda4ca
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 2 deletions.
32 changes: 31 additions & 1 deletion api/ApiHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2539,6 +2539,35 @@ export function initAPI(returnSSRResponse: boolean = false): API {
})
}

let getLinkvertiseLink = (): Promise<string> => {
return new Promise((resolve, reject) => {
let googleId = sessionStorage.getItem('googleId')
if (!googleId) {
toast.error('You need to be logged in to do linkvertise tasks.')
reject()
return
}

httpApi.sendApiRequest({
type: RequestType.GET_LINKVERTISE_LINK,
customRequestURL: `${getApiEndpoint()}/linkvertise`,
requestMethod: 'GET',
data: '',
requestHeader: {
GoogleToken: googleId,
'Content-Type': 'application/json'
},
resolve: link => {
resolve(link)
},
reject: (error: any) => {
apiErrorHandler(RequestType.GET_LINKVERTISE_LINK, error)
reject(error)
}
})
})
}

return {
search,
trackSearch,
Expand Down Expand Up @@ -2630,7 +2659,8 @@ export function initAPI(returnSSRResponse: boolean = false): API {
getPublishedConfigs,
updateConfig,
requestArchivedAuctions,
exportArchivedAuctionsData
exportArchivedAuctionsData,
getLinkvertiseLink
}
}

Expand Down
3 changes: 2 additions & 1 deletion api/ApiTypes.d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export enum RequestType {
GET_PUBLISHED_CONFIGS = 'publishedConfigs',
UPDATE_CONFIG = 'updateConfig',
ARCHIVED_AUCTIONS = 'archivedAuctions',
EXPORT_ARCHIVED_AUCTIONS = 'exportArchivedAuctions'
EXPORT_ARCHIVED_AUCTIONS = 'exportArchivedAuctions',
GET_LINKVERTISE_LINK = 'getLinkvertiseLink'
}

export enum SubscriptionType {
Expand Down
23 changes: 23 additions & 0 deletions app/linkvertise/fail/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Container } from 'react-bootstrap'
import NavBar from '../../../components/NavBar/NavBar'
import Link from 'next/link'
import { getHeadMetadata } from '../../../utils/SSRUtils'

export default async function Page() {
return (
<>
<Container>
<h2>
<NavBar />
Linkvertise task failed
</h2>
<hr />
<p>
Unfortunately something went wrong. You can try again <Link href="/linkvertise">here</Link>.
</p>
</Container>
</>
)
}

export const metadata = getHeadMetadata('Linkvertise', 'Linkvertise task failed')
23 changes: 23 additions & 0 deletions app/linkvertise/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Container } from 'react-bootstrap'
import { initAPI } from '../../api/ApiHelper'
import LowSupply from '../../components/LowSupply/LowSupply'
import NavBar from '../../components/NavBar/NavBar'
import { getHeadMetadata } from '../../utils/SSRUtils'
import Linkvertise from '../../components/Linkvertise/Linkvertise'

export default async function Page() {
return (
<>
<Container>
<h2>
<NavBar />
Linkvertise
</h2>
<Linkvertise />
<hr />
</Container>
</>
)
}

export const metadata = getHeadMetadata('Linkvertise', 'Linkvertise task successful')
20 changes: 20 additions & 0 deletions app/linkvertise/success/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Container } from 'react-bootstrap'
import NavBar from '../../../components/NavBar/NavBar'
import { getHeadMetadata } from '../../../utils/SSRUtils'

export default async function Page() {
return (
<>
<Container>
<h2>
<NavBar />
Linkvertise task successful
</h2>
<hr />
<p>You successfully completed the Linkvertise task. You can close this page now.</p>
</Container>
</>
)
}

export const metadata = getHeadMetadata('Linkvertise', 'Linkvertise task successful')
45 changes: 45 additions & 0 deletions components/Linkvertise/Linkvertise.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use client'
import { useState } from 'react'
import api from '../../api/ApiHelper'
import { getLoadingElement } from '../../utils/LoadingUtils'
import { useWasAlreadyLoggedIn } from '../../utils/Hooks'
import GoogleSignIn from '../GoogleSignIn/GoogleSignIn'
import { useRouter } from 'next/navigation'

export default function LowSupply() {
let [isLoggedIn, setIsLoggedIn] = useState(false)
let wasAlreadyLoggedIn = useWasAlreadyLoggedIn()
let [isRedirecting, setIsRedirecting] = useState(false)
let router = useRouter()

function onLogin() {
let googleId = sessionStorage.getItem('googleId')
if (googleId) {
setIsLoggedIn(true)
loadRedirectLink()
}
}

function loadRedirectLink() {
setIsRedirecting(true)
api.getLinkvertiseLink()
.then(link => {
router.push(link)
})
.finally(() => {
setIsRedirecting(false)
})
}

function onLoginFail() {
setIsLoggedIn(false)
}

return (
<>
{!isLoggedIn && !wasAlreadyLoggedIn && <p>To use Linkvertise, please login with Google: </p>}
{isRedirecting && getLoadingElement(<span>Redirecting...</span>)}
<GoogleSignIn onAfterLogin={onLogin} onLoginFail={onLoginFail} />
</>
)
}
1 change: 1 addition & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ interface API {
updateConfig(configName: string, updateNotes: string = ''): Promise<void>
requestArchivedAuctions(itemTag: string, itemFilter?: ItemFilter): Promise<ArchivedAuctionResponse>
exportArchivedAuctionsData(itemTag: string, itemFilter: ItemFilter, discordWebhookUrl: string, flags: string[]): Promise<void>
getLinkvertiseLink(): Promise<string>
}

interface CacheUtils {
Expand Down

0 comments on commit abda4ca

Please sign in to comment.