feat: Dynamically change the background image on the search homepage every day #2247 (#2338)

### What problem does this PR solve?

feat: Dynamically change the background image on the search homepage
every day #2247

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-09-10 11:25:12 +08:00
committed by GitHub
parent 7c8f159751
commit f1ad778250
5 changed files with 47 additions and 11 deletions

View File

@ -3,7 +3,7 @@ import { useTestChunkRetrieval } from '@/hooks/knowledge-hooks';
import { useSendMessageWithSse } from '@/hooks/logic-hooks';
import { IAnswer } from '@/interfaces/database/chat';
import api from '@/utils/api';
import { isEmpty, trim } from 'lodash';
import { get, isEmpty, trim } from 'lodash';
import { ChangeEventHandler, useCallback, useEffect, useState } from 'react';
export const useSendQuestion = (kbIds: string[]) => {
@ -99,3 +99,28 @@ export const useSendQuestion = (kbIds: string[]) => {
isFirstRender,
};
};
export const useFetchBackgroundImage = () => {
const [imgUrl, setImgUrl] = useState<string>('');
const fetchImage = useCallback(async () => {
try {
const res = await fetch(
'/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN',
);
const ret = await res.json();
const url = get(ret, 'images.0.url');
if (url) {
setImgUrl(url);
}
} catch (error) {
console.log('🚀 ~ fetchImage ~ error:', error);
}
}, []);
useEffect(() => {
fetchImage();
}, [fetchImage]);
return `https://cn.bing.com${imgUrl}`;
};