Skip to content

Commit

Permalink
Readded code to avoid refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay committed Jul 27, 2024
1 parent 3dea4a7 commit c915e50
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
20 changes: 6 additions & 14 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import ManageAssembliesModal from "@/modals/spawning/ManageAssembliesModal.tsx"
import World from "@/systems/World.ts"
import { AddRobotsModal, AddFieldsModal, SpawningModal } from "@/modals/spawning/SpawningModals.tsx"
import ImportLocalMirabufModal from "@/modals/mirabuf/ImportLocalMirabufModal.tsx"
import APS from "./aps/APS.ts"
import ImportMirabufPanel from "@/ui/panels/mirabuf/ImportMirabufPanel.tsx"
import Skybox from "./ui/components/Skybox.tsx"
import ChooseInputSchemePanel from "./ui/panels/configuring/ChooseInputSchemePanel.tsx"
Expand All @@ -71,18 +70,6 @@ import PreferencesSystem from "./systems/preferences/PreferencesSystem.ts"
const worker = new Lazy<Worker>(() => new WPILibWSWorker())

function Synthesis() {
const urlParams = new URLSearchParams(document.location.search)
const has_code = urlParams.has("code")
useEffect(() => {
if (has_code) {
const code = urlParams.get("code")
if (code) {
APS.convertAuthToken(code).then(() => {
document.location.search = ""
})
}
}
}, [])
const { openModal, closeModal, getActiveModalElement } = useModalManager(initialModals)
const { openPanel, closePanel, closeAllPanels, getActivePanelElements } = usePanelManager(initialPanels)
const { showTooltip } = useTooltipManager()
Expand All @@ -99,7 +86,12 @@ function Synthesis() {
const modalElement = getActiveModalElement()

useEffect(() => {
if (has_code) return
const urlParams = new URLSearchParams(document.location.search)
if (urlParams.has("code")) {
window.opener.convertAuthToken(urlParams.get("code"))
window.close()
return
}

World.InitWorld()

Expand Down
3 changes: 3 additions & 0 deletions fission/src/Window.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare interface Window {
convertAuthToken(code: string): void
}
2 changes: 1 addition & 1 deletion fission/src/aps/APS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class APS {

const url = `${ENDPOINT_AUTODESK_AUTHENTICATION_AUTHORIZE}?${params.toString()}`

window.open(url, "_self")
window.open(url)
} catch (e) {
console.error(e)
World.AnalyticsSystem?.Exception("APS Login Failure")
Expand Down
3 changes: 3 additions & 0 deletions fission/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ReactDOM from "react-dom/client"
import { Theme, ThemeProvider } from "@/ui/ThemeContext"
import Synthesis from "./Synthesis"
import "./index.css"
import APS from "./aps/APS"

const initialThemeName = "Default"
const defaultColors: Theme = {
Expand Down Expand Up @@ -72,6 +73,8 @@ const themes = {
Default: defaultColors,
}

window.convertAuthToken = code => APS.convertAuthToken(code)

ReactDOM.createRoot(document.getElementById("root")!).render(
<ThemeProvider initialThemeName={initialThemeName} themes={themes} defaultTheme={defaultColors}>
<Synthesis />
Expand Down

0 comments on commit c915e50

Please sign in to comment.