-
-
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.
Merge pull request #13 from SkywardAI/improve
Improve
- Loading branch information
Showing
13 changed files
with
131 additions
and
31 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,31 @@ | ||
import apiAddress from "../tools/apiAddress.js"; | ||
import createHook from "./createHook.js"; | ||
|
||
let currentSession = null, init = false; | ||
|
||
const { onmount, remount, dismount, updateAll } = createHook(); | ||
|
||
export default function useSessionId(updated) { | ||
const mount_key = onmount(updated) | ||
|
||
async function genSession() { | ||
const { token } = await (await fetch(apiAddress('auth/token'), { mode: 'no-cors' })).json(); | ||
currentSession = token; | ||
updateAll(currentSession); | ||
} | ||
|
||
function manualUpdateSession(sessionId) { | ||
currentSession = sessionId; | ||
updateAll(currentSession); | ||
} | ||
|
||
if(!currentSession && !init) { | ||
init = true; | ||
genSession(); | ||
} | ||
|
||
return { | ||
manualUpdateSession, genSession, | ||
componetDismount: dismount(mount_key), componentReMount:remount(mount_key) | ||
} | ||
} |
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 +1,2 @@ | ||
export const VERSION = '0.0.1' | ||
export const VERSION = '0.0.1' | ||
export const LOCAL_API_ADDRESS = 'http://localhost:8000/api' |
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,5 @@ | ||
import { LOCAL_API_ADDRESS } from "../settings.js"; | ||
|
||
export default function apiAddress(address) { | ||
return `${LOCAL_API_ADDRESS}/${address}`; | ||
} |