Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rotate model hub banner on app launch until set #4542

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
)

/**
* 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
Loading