Skip to content

Commit

Permalink
feat: add autologin toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemSBulgakov committed Jul 14, 2024
1 parent 23ea058 commit 20ba8b5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/entrypoints/popup/Popup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect } from 'react'
import { AutologinToggle } from '@/features/autologin/AutologinToggle'
import { SearchField } from '@/features/search/SearchField'
import { SearchAutoSyncToggle } from '@/features/search-sync/SearchAutoSyncToggle'
import { UsefulLinksSection } from '@/features/useful-links/UsefulLinksSection'
Expand All @@ -17,6 +18,7 @@ export default function Popup() {
<UsefulLinksSection />
<SearchField />
<CoursesList />
<AutologinToggle />
<SearchAutoSyncToggle />
</div>
)
Expand Down
26 changes: 26 additions & 0 deletions src/features/autologin/AutologinToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { setStored, useStorage } from '@/shared/storage'
import { cn } from '@/shared/ui/utils'

export function AutologinToggle() {
const autologinEnabled = useStorage('autologinEnabled')

return (
<div className="w-full flex flex-row items-center justify-between gap-2 p-2">
<div className="flex items-center text-xs">
Enable autologin on Moodle (without entering your password)
</div>
<button
type="button"
className={cn(
'flex h-fit items-center justify-center rounded-lg px-2 py-1 text-xs font-normal text-base-content',
autologinEnabled === false ? 'bg-red-900' : 'bg-[#9747FF] hover:bg-[#6600CC]',
)}
onClick={() => {
setStored('autologinEnabled', !autologinEnabled)
}}
>
{autologinEnabled === false ? 'OFF' : 'ON'}
</button>
</div>
)
}
6 changes: 6 additions & 0 deletions src/features/autologin/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { moodle } from '@/shared/moodle-ws-api'
import { getStored, setStored } from '@/shared/storage'

export async function autoLogIn() {
const enabled = await getStored('autologinEnabled')
if (!enabled) {
console.log('Auto login is disabled, skipping')
return false
}

console.debug('Auto logging in...')
const privateToken = await getStored('privateToken')
if (!privateToken) {
Expand Down
4 changes: 2 additions & 2 deletions src/features/search-sync/SearchAutoSyncToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export function SearchAutoSyncToggle() {
const allowSendingCourses = useStorage('allowSyncingCourses')

return (
<div className="flex flex-row gap-2 p-2">
<div className="text-xs">
<div className="w-full flex flex-row items-center justify-between gap-2 p-2">
<div className="flex items-center text-xs">
Sync your Moodle courses contents with InNoHassle Search for indexing and using AI search engine
</div>
<button
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 @@ -9,6 +9,7 @@ export interface SharedStorage {
privateToken: string

// Autologin
autologinEnabled: boolean
autologinLastSuccessMS: number

// User info
Expand Down

0 comments on commit 20ba8b5

Please sign in to comment.