only allow admins to save annotation offset

This commit is contained in:
Josh Hawkins 2025-12-09 14:41:56 -06:00
parent 8d5349ca85
commit 9b85e66608
2 changed files with 29 additions and 21 deletions

View File

@ -10,6 +10,7 @@ import { Trans, useTranslation } from "react-i18next";
import { LuInfo } from "react-icons/lu"; import { LuInfo } from "react-icons/lu";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { isMobile } from "react-device-detect"; import { isMobile } from "react-device-detect";
import { useIsAdmin } from "@/hooks/use-is-admin";
type Props = { type Props = {
className?: string; className?: string;
@ -17,6 +18,7 @@ type Props = {
export default function AnnotationOffsetSlider({ className }: Props) { export default function AnnotationOffsetSlider({ className }: Props) {
const { annotationOffset, setAnnotationOffset, camera } = useDetailStream(); const { annotationOffset, setAnnotationOffset, camera } = useDetailStream();
const isAdmin = useIsAdmin();
const { mutate } = useSWRConfig(); const { mutate } = useSWRConfig();
const { t } = useTranslation(["views/explore"]); const { t } = useTranslation(["views/explore"]);
const [isSaving, setIsSaving] = useState(false); const [isSaving, setIsSaving] = useState(false);
@ -101,11 +103,13 @@ export default function AnnotationOffsetSlider({ className }: Props) {
<Button size="sm" variant="ghost" onClick={reset}> <Button size="sm" variant="ghost" onClick={reset}>
{t("button.reset", { ns: "common" })} {t("button.reset", { ns: "common" })}
</Button> </Button>
<Button size="sm" onClick={save} disabled={isSaving}> {isAdmin && (
{isSaving <Button size="sm" onClick={save} disabled={isSaving}>
? t("button.saving", { ns: "common" }) {isSaving
: t("button.save", { ns: "common" })} ? t("button.saving", { ns: "common" })
</Button> : t("button.save", { ns: "common" })}
</Button>
)}
</div> </div>
</div> </div>
<div <div

View File

@ -24,6 +24,7 @@ import { Input } from "@/components/ui/input";
import { Separator } from "@/components/ui/separator"; import { Separator } from "@/components/ui/separator";
import { Trans, useTranslation } from "react-i18next"; import { Trans, useTranslation } from "react-i18next";
import { useDocDomain } from "@/hooks/use-doc-domain"; import { useDocDomain } from "@/hooks/use-doc-domain";
import { useIsAdmin } from "@/hooks/use-is-admin";
type AnnotationSettingsPaneProps = { type AnnotationSettingsPaneProps = {
event: Event; event: Event;
@ -36,6 +37,7 @@ export function AnnotationSettingsPane({
setAnnotationOffset, setAnnotationOffset,
}: AnnotationSettingsPaneProps) { }: AnnotationSettingsPaneProps) {
const { t } = useTranslation(["views/explore"]); const { t } = useTranslation(["views/explore"]);
const isAdmin = useIsAdmin();
const { getLocaleDocUrl } = useDocDomain(); const { getLocaleDocUrl } = useDocDomain();
const { data: config, mutate: updateConfig } = const { data: config, mutate: updateConfig } =
@ -201,22 +203,24 @@ export function AnnotationSettingsPane({
> >
{t("button.apply", { ns: "common" })} {t("button.apply", { ns: "common" })}
</Button> </Button>
<Button {isAdmin && (
variant="select" <Button
aria-label={t("button.save", { ns: "common" })} variant="select"
disabled={isLoading} aria-label={t("button.save", { ns: "common" })}
className="flex flex-1" disabled={isLoading}
type="submit" className="flex flex-1"
> type="submit"
{isLoading ? ( >
<div className="flex flex-row items-center gap-2"> {isLoading ? (
<ActivityIndicator /> <div className="flex flex-row items-center gap-2">
<span>{t("button.saving", { ns: "common" })}</span> <ActivityIndicator />
</div> <span>{t("button.saving", { ns: "common" })}</span>
) : ( </div>
t("button.save", { ns: "common" }) ) : (
)} t("button.save", { ns: "common" })
</Button> )}
</Button>
)}
</div> </div>
</div> </div>
</form> </form>