Feature/streamline backend requests (#297)

* Introduce "RequestManager"

* Use "RequestManager" - Simple replacements

 - Get rid of all "util/client" imports
 - replace old requests with new "RequestManager"
 - remove "fetcher" from global SWR config
     instead of using the SWR hooks by themselves, the "requestManager" is supposed to be used

* Use "RequestManager" - Do requests via SWR hooks

Use SWR hooks at places where it's easily usable

* Prevent trailing slashes in the "baseUrl"
This commit is contained in:
schroda
2023-05-18 13:25:19 +02:00
committed by GitHub
parent f86c7ea08a
commit a457d80c44
34 changed files with 950 additions and 333 deletions

View File

@@ -41,6 +41,7 @@ import { useTranslation } from 'react-i18next';
import LanguageIcon from '@mui/icons-material/Language';
import { langCodeToName } from 'util/language';
import CollectionsOutlinedBookmarkIcon from '@mui/icons-material/CollectionsBookmarkOutlined';
import requestManager from 'lib/RequestManager';
export default function Settings() {
const { t, i18n } = useTranslation();
@@ -52,7 +53,7 @@ export default function Settings() {
}, [t]);
const { darkTheme, setDarkTheme } = useContext(DarkTheme);
const [serverAddress, setServerAddress] = useLocalStorage<String>('serverBaseURL', '');
const [serverAddress, setServerAddress] = useLocalStorage<string>('serverBaseURL', '');
const [showNsfw, setShowNsfw] = useLocalStorage<boolean>('showNsfw', true);
const [useCache, setUseCache] = useLocalStorage<boolean>('useCache', true);
const [dialogOpen, setDialogOpen] = useState(false);
@@ -73,7 +74,9 @@ export default function Settings() {
const handleDialogSubmit = () => {
setDialogOpen(false);
setServerAddress(dialogValue);
const serverBaseUrl = dialogValue.replaceAll(/(\/)+$/g, '');
setServerAddress(serverBaseUrl);
requestManager.updateClient({ baseURL: serverBaseUrl });
};
const handleDialogOpenItemWidth = () => {