Skip to content

Commit

Permalink
chore: rotate model hub banner on app launch until set
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo committed Jan 29, 2025
1 parent 0a41a24 commit fe86efb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
21 changes: 18 additions & 3 deletions web/helpers/atoms/App.atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,28 @@ export const copyOverInstructionEnabledAtom = atomWithStorage(
)

/**
* App Hub Banner configured image
* App Banner Hub Atom - storage last banner setting - default undefined
*/
export const appBannerHubAtom = atomWithStorage<string>(
const appBannerHubStorageAtom = atomWithStorage<string | undefined>(
'appBannerHub',
'./images/HubBanner/banner-8.jpg',
undefined,
undefined,
{
getOnInit: true,
}
)
/**
* App Hub Banner configured image - Retrieve from appBannerHubStorageAtom - fallback a random banner
*/
export const getAppBannerHubAtom = atom<string>(
(get) =>
get(appBannerHubStorageAtom) ??

Check warning on line 50 in web/helpers/atoms/App.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

50 line is not covered with tests
`./images/HubBanner/banner-${Math.floor(Math.random() * 30) + 1}.jpg`
)

/**
* Set App Hub Banner - store in appBannerHubStorageAtom
*/
export const setAppBannerHubAtom = atom(null, (get, set, banner: string) => {
set(appBannerHubStorageAtom, banner)

Check warning on line 58 in web/helpers/atoms/App.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

58 line is not covered with tests
})
10 changes: 7 additions & 3 deletions web/screens/Hub/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ModelSource } from '@janhq/core'
import { ScrollArea, Button, Select, Tabs, useClickOutside } from '@janhq/joi'
import { motion as m } from 'framer-motion'

import { useAtom, useSetAtom } from 'jotai'
import { useAtom, useAtomValue, useSetAtom } from 'jotai'
import { ImagePlusIcon, UploadCloudIcon, UploadIcon } from 'lucide-react'

import { twMerge } from 'tailwind-merge'
Expand All @@ -33,7 +33,10 @@ import { fuzzySearch } from '@/utils/search'

import ModelPage from './ModelPage'

import { appBannerHubAtom } from '@/helpers/atoms/App.atom'
import {
getAppBannerHubAtom,
setAppBannerHubAtom,
} from '@/helpers/atoms/App.atom'
import { modelDetailAtom } from '@/helpers/atoms/Model.atom'

const sortMenus = [
Expand Down Expand Up @@ -70,7 +73,8 @@ const HubScreen = () => {
const [filterOption, setFilterOption] = useState('all')
const [hubBannerOption, setHubBannerOption] = useState('gallery')
const [showHubBannerSetting, setShowHubBannerSetting] = useState(false)
const [appBannerHub, setAppBannerHub] = useAtom(appBannerHubAtom)
const appBannerHub = useAtomValue(getAppBannerHubAtom)
const setAppBannerHub = useSetAtom(setAppBannerHubAtom)
const [selectedModel, setSelectedModel] = useState<ModelSource | undefined>(
undefined
)
Expand Down

0 comments on commit fe86efb

Please sign in to comment.