-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
337ced7
commit 348dc08
Showing
2 changed files
with
26 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
'use client'; | ||
|
||
import { Suggestions } from "../components/Suggestions"; | ||
import { checkLogin } from "../lib/goldapps/auth"; | ||
import { redirect } from "next/navigation"; | ||
import { useRouter } from "next/navigation"; | ||
import { getSuggestions } from "../lib/goldapps/get-suggestions"; | ||
import { createGoldappsServerClient } from "../lib/goldapps/client-server"; | ||
import {useEffect, useState} from "react"; | ||
import {Suggestion} from "../lib/goldapps/types"; | ||
import {createGoldappsBrowserClient} from "../lib/goldapps/client-browser"; | ||
|
||
async function fetchSuggestions() { | ||
const goldappsClient = createGoldappsServerClient(); | ||
const redirectUri = await checkLogin(goldappsClient); | ||
if (redirectUri) { | ||
return redirect(redirectUri); | ||
} | ||
|
||
return getSuggestions(goldappsClient); | ||
} | ||
|
||
export default async function IndexPage() { | ||
const suggestions = await fetchSuggestions(); | ||
|
||
const router = useRouter(); | ||
const fetchSuggestions = async () => { | ||
const goldappsClient = createGoldappsBrowserClient(); | ||
const redirectUri = await checkLogin(goldappsClient); | ||
if (redirectUri) { | ||
return router.push(redirectUri); | ||
} | ||
|
||
return getSuggestions(goldappsClient); | ||
} | ||
|
||
const [suggestions, setSuggestions] = useState<Suggestion[]>([]); | ||
useEffect(() => { | ||
fetchSuggestions().then((suggestions) => { | ||
setSuggestions(suggestions || []); | ||
}); | ||
}, []); | ||
return <Suggestions suggestions={suggestions} />; | ||
} |
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