Skip to content

Commit

Permalink
feat: allow to override search api url
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemSBulgakov committed Jul 13, 2024
1 parent 366a616 commit 53dc4b9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/entrypoints/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ chrome.runtime.onInstalled.addListener(() => {
onMessage('POPUP_OPEN', () => {
console.log('Background has received a message POPUP_OPEN')
fetchCourses()
syncCourses()
})

onMessage('MOODLE_LOAD', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/features/search-sync/SearchAutoSyncToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setStored, useStorage } from '@/shared/storage'
import { removeStored, setStored, useStorage } from '@/shared/storage'
import { cn } from '@/shared/ui/utils'

export function SearchAutoSyncToggle() {
Expand All @@ -17,6 +17,7 @@ export function SearchAutoSyncToggle() {
)}
onClick={() => {
setStored('allowSyncingCourses', !allowSendingCourses)
removeStored('syncCoursesLastUpdateMS')
}}
>
{allowSendingCourses === false ? 'OFF' : 'ON'}
Expand Down
7 changes: 7 additions & 0 deletions src/shared/innohassle-api/search/axios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AxiosRequestConfig } from 'axios'
import axios from 'axios'
import { getToken, invalidateToken } from '../token-store'
import { getStored } from '@/shared/storage'
import { INNOHASSLE_SEARCH_URL } from '@/shared/config/innohassle'

// Axios client for InNoHassle Search API
Expand All @@ -10,10 +11,16 @@ export const AxiosSearch = axios.create({

// Add token to Authorization header
AxiosSearch.interceptors.request.use(async (request) => {
const overrideBaseUrl = await getStored('innohassleSearchUrl')
if (overrideBaseUrl) {
request.baseURL = overrideBaseUrl
}

const token = await getToken()
if (token) {
request.headers.Authorization = `Bearer ${token}`
}

return request
})

Expand Down
1 change: 1 addition & 0 deletions src/shared/storage/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface SharedStorage {
innohassleToken: string
allowSyncingCourses: boolean
syncCoursesLastUpdateMS: number
innohassleSearchUrl: string
}

0 comments on commit 53dc4b9

Please # to comment.