/* * Kyoo - A portable and vast media library solution. * Copyright (c) Kyoo. * * See AUTHORS.md and LICENSE file in the project root for full license information. * * Kyoo is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * Kyoo is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Kyoo. If not, see . */ import { type Account, type KyooErrors, deleteAccount, logout, queryFn, useAccount, } from "@kyoo/models"; import { Alert, Avatar, Button, H1, Icon, Input, P, Popup, ts, usePopup } from "@kyoo/primitives"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import * as ImagePicker from "expo-image-picker"; import { type ComponentProps, useState } from "react"; import { useTranslation } from "react-i18next"; import { View } from "react-native"; import { rem, useYoshiki } from "yoshiki/native"; import { PasswordInput } from "../login/password-input"; import { Preference, SettingsContainer } from "./base"; import Username from "@material-symbols/svg-400/outlined/badge.svg"; import Mail from "@material-symbols/svg-400/outlined/mail.svg"; import Password from "@material-symbols/svg-400/outlined/password.svg"; import AccountCircle from "@material-symbols/svg-400/rounded/account_circle-fill.svg"; import Delete from "@material-symbols/svg-400/rounded/delete.svg"; import Logout from "@material-symbols/svg-400/rounded/logout.svg"; function dataURItoBlob(dataURI: string) { const byteString = atob(dataURI.split(",")[1]); const ab = new ArrayBuffer(byteString.length); const ia = new Uint8Array(ab); for (let i = 0; i < byteString.length; i++) { ia[i] = byteString.charCodeAt(i); } return new Blob([ab], { type: "image/jpeg" }); } export const AccountSettings = () => { const account = useAccount()!; const { css, theme } = useYoshiki(); const { t } = useTranslation(); const [setPopup, close] = usePopup(); const queryClient = useQueryClient(); const { mutateAsync } = useMutation({ mutationFn: async (update: Partial) => await queryFn({ path: ["auth", "me"], method: "PATCH", body: update, }), onSettled: async () => await queryClient.invalidateQueries({ queryKey: ["auth", "me"] }), }); const { mutateAsync: editPassword } = useMutation({ mutationFn: async (request: { newPassword: string; oldPassword: string }) => await queryFn({ path: ["auth", "password-reset"], method: "POST", body: request, }), }); return (