Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into mantine7merge
Browse files Browse the repository at this point in the history
  • Loading branch information
sickelap committed Nov 27, 2024
2 parents db46bb2 + 01e6cee commit cb7b5e2
Show file tree
Hide file tree
Showing 5 changed files with 886 additions and 936 deletions.
1 change: 0 additions & 1 deletion src/api_client/site-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const SiteSettingsSchema = z.object({
allow_registration: z.boolean(),
allow_upload: z.boolean(),
skip_patterns: z.string(),
heavyweight_process: z.number().nullable(),
map_api_key: z.string(),
map_api_provider: z.string(),
captioning_model: z.string(),
Expand Down
67 changes: 2 additions & 65 deletions src/layouts/settings/SiteSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
import {
Button,
Card,
Grid,
Group,
Modal,
NativeSelect,
Select,
Stack,
Switch,
Text,
TextInput,
Title,
} from "@mantine/core";
import { Button, Card, Grid, Group, Modal, Select, Stack, Switch, Text, TextInput, Title } from "@mantine/core";
import { useDisclosure } from "@mantine/hooks";
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";

import { useGetSettingsQuery, useUpdateSettingsMutation } from "../../api_client/site-settings";

const MAX_HEAVYWEIGHT_PROCESSES = 10;
const heavyweightProcessOptions = Array(MAX_HEAVYWEIGHT_PROCESSES)
.fill("")
.map((_, i) => (i + 1).toString());

const MAP_API_PROVIDERS = [
{ value: "mapbox", label: "Mapbox", data: { use_api_key: true, url: "https://www.mapbox.com/" } },
{ value: "maptiler", label: "MapTiler", data: { use_api_key: true, url: "https://www.maptiler.com/" } },
Expand Down Expand Up @@ -53,7 +35,6 @@ export function SiteSettings() {
const [skipPatterns, setSkipPatterns] = useState("");
const [mapApiKey, setMapApiKey] = useState("");
const [mapApiProvider, setMapApiProvider] = useState<string>("proton");
const [heavyweightProcess, setHeavyweightProcess] = useState(1);
const [allowRegistration, setAllowRegistration] = useState(false);
const [allowUpload, setAllowUpload] = useState(false);
const [captioningModel, setCaptioningModel] = useState("im2txt");
Expand All @@ -65,11 +46,6 @@ export function SiteSettings() {
const [opened, { open, close }] = useDisclosure(false);

const saveSettingsWithValidation = (input: any) => {
if (input.heavyweight_process && input.heavyweight_process > 3) {
setWarning("heavyweight");
open();
return;
}
if (input.captioning_model === "blip_base_capfilt_large") {
setWarning("blip");
open();
Expand All @@ -83,7 +59,6 @@ export function SiteSettings() {
setSkipPatterns(settings.skip_patterns);
setMapApiKey(settings.map_api_key);
setMapApiProvider(settings.map_api_provider);
setHeavyweightProcess(settings.heavyweight_process);
setAllowRegistration(settings.allow_registration);
setAllowUpload(settings.allow_upload);
setCaptioningModel(settings.captioning_model);
Expand All @@ -100,29 +75,19 @@ export function SiteSettings() {
setCaptioningModel("im2txt");
saveSettings({ captioning_model: "im2txt" });
}
if (warning === "heavyweight") {
setHeavyweightProcess(3);
saveSettings({ heavyweight_process: 3 });
}
close();
}}
title={<Title order={4}>{t("sitesettings.ram_warning_header")}</Title>}
>
<Stack>
<Text>
{warning === "blip" ? t("sitesettings.blip_warning") : t("sitesettings.heavyweight_process_warning")}
</Text>
<Text>{t("sitesettings.blip_warning")}</Text>
<Group>
<Button
onClick={() => {
if (warning === "blip") {
setCaptioningModel("im2txt");
saveSettings({ captioning_model: "im2txt" });
}
if (warning === "heavyweight") {
setHeavyweightProcess(3);
saveSettings({ heavyweight_process: 3 });
}
close();
}}
>
Expand All @@ -133,9 +98,6 @@ export function SiteSettings() {
if (warning === "blip") {
saveSettings({ captioning_model: captioningModel });
}
if (warning === "heavyweight") {
saveSettings({ heavyweight_process: heavyweightProcess });
}
close();
}}
color="red"
Expand Down Expand Up @@ -272,31 +234,6 @@ export function SiteSettings() {
}}
/>
</Grid.Col>
<Grid.Col span={8}>
<Stack gap={0}>
<Text>{t("sitesettings.headerheavyweight")}</Text>
<Text fz="sm" c="dimmed">
{t("sitesettings.heavyweight")}
</Text>
</Stack>
</Grid.Col>
<Grid.Col span={4}>
<NativeSelect
data={heavyweightProcessOptions}
value={heavyweightProcess}
onKeyDown={e => {
if (e.key === "Enter") {
saveSettingsWithValidation({ heavyweight_process: +e.currentTarget.value });
}
}}
onChange={e => {
if (/^([0-9\b]+)?$/.test(e.target.value)) {
setHeavyweightProcess(+e.currentTarget.value);
saveSettingsWithValidation({ heavyweight_process: +e.target.value });
}
}}
/>
</Grid.Col>
</Grid>
</Stack>
</Card>
Expand Down
Loading

0 comments on commit cb7b5e2

Please sign in to comment.