mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-05 07:44:38 +00:00
feat: add status preference edit
This commit is contained in:
parent
5f92074558
commit
8e34ff4a7d
3 changed files with 106 additions and 3 deletions
|
@ -18,6 +18,7 @@ export const ENDPOINTS = {
|
|||
favorite: `${API_PREFIX}/favorite`,
|
||||
settings: {
|
||||
my: `${API_PREFIX}/profile/preference/my`,
|
||||
statusEdit: `${API_PREFIX}/profile/preference/status/edit`,
|
||||
statsEdit: `${API_PREFIX}/profile/preference/privacy/stats/edit`,
|
||||
countsEdit: `${API_PREFIX}/profile/preference/privacy/counts/edit`,
|
||||
socialEdit: `${API_PREFIX}/profile/preference/privacy/social/edit`,
|
||||
|
|
|
@ -6,6 +6,7 @@ import useSWR from "swr";
|
|||
import { ENDPOINTS } from "#/api/config";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ProfileEditPrivacyModal } from "./Profile.EditPrivacyModal";
|
||||
import { ProfileEditStatusModal } from "./Profile.EditStatusModal";
|
||||
|
||||
const fetcher = async (url: string) => {
|
||||
const res = await fetch(url);
|
||||
|
@ -27,6 +28,7 @@ export const ProfileEditModal = (props: {
|
|||
token: string;
|
||||
}) => {
|
||||
const [privacyModalOpen, setPrivacyModalOpen] = useState(false);
|
||||
const [statusModalOpen, setStatusModalOpen] = useState(false);
|
||||
const [privacyModalSetting, setPrivacyModalSetting] = useState("none");
|
||||
const [privacySettings, setPrivacySettings] = useState({
|
||||
privacy_stats: 9,
|
||||
|
@ -38,6 +40,7 @@ export const ProfileEditModal = (props: {
|
|||
vk: false,
|
||||
google: false,
|
||||
});
|
||||
const [status, setStatus] = useState("");
|
||||
|
||||
const privacy_stat_act_social_text = {
|
||||
0: "Все пользователи",
|
||||
|
@ -68,6 +71,7 @@ export const ProfileEditModal = (props: {
|
|||
vk: data.is_vk_bound || data.isVkBound || false,
|
||||
google: data.is_google_bound || data.isGoogleBound || false,
|
||||
});
|
||||
setStatus(data.status);
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
|
@ -95,10 +99,17 @@ export const ProfileEditModal = (props: {
|
|||
Загрузить с устройства
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<button
|
||||
className="p-2 text-left rounded-md hover:bg-gray-100"
|
||||
onClick={() => {
|
||||
setStatusModalOpen(true);
|
||||
}}
|
||||
>
|
||||
<p className="text-lg">Изменить статус</p>
|
||||
<p className="text-base text-gray-500">{data.status}</p>
|
||||
</div>
|
||||
<p className="text-base text-gray-500 whitespace-pre">
|
||||
{status}
|
||||
</p>
|
||||
</button>
|
||||
<div>
|
||||
<p className="text-lg">Изменить никнейм</p>
|
||||
</div>
|
||||
|
@ -235,6 +246,13 @@ export const ProfileEditModal = (props: {
|
|||
privacySettings={privacySettings}
|
||||
setPrivacySettings={setPrivacySettings}
|
||||
/>
|
||||
<ProfileEditStatusModal
|
||||
isOpen={statusModalOpen}
|
||||
setIsOpen={setStatusModalOpen}
|
||||
token={props.token}
|
||||
status={status}
|
||||
setStatus={setStatus}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
84
app/components/Profile/Profile.EditStatusModal.tsx
Normal file
84
app/components/Profile/Profile.EditStatusModal.tsx
Normal file
|
@ -0,0 +1,84 @@
|
|||
"use client";
|
||||
|
||||
import { Button, Modal, Textarea } from "flowbite-react";
|
||||
import { ENDPOINTS } from "#/api/config";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export const ProfileEditStatusModal = (props: {
|
||||
isOpen: boolean;
|
||||
setIsOpen: (isOpen: boolean) => void;
|
||||
token: string;
|
||||
status: string;
|
||||
setStatus: (status: string) => void;
|
||||
}) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [_status, _setStatus] = useState("");
|
||||
const [_stringLength, _setStringLength] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
_setStatus(props.status);
|
||||
_setStringLength(props.status.length);
|
||||
}, [props.isOpen]);
|
||||
|
||||
function handleInput(e: any) {
|
||||
_setStatus(e.target.value);
|
||||
_setStringLength(e.target.value.length);
|
||||
}
|
||||
|
||||
function _setStatusSetting() {
|
||||
setLoading(true);
|
||||
fetch(ENDPOINTS.user.settings.statusEdit, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
status: _status,
|
||||
}),
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.ok) {
|
||||
setLoading(false);
|
||||
props.setStatus(_status);
|
||||
props.setIsOpen(false);
|
||||
} else {
|
||||
new Error("failed to send data");
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
setLoading(false);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
dismissible
|
||||
show={props.isOpen}
|
||||
onClose={() => props.setIsOpen(false)}
|
||||
size={"4xl"}
|
||||
>
|
||||
<Modal.Header>Изменить статус</Modal.Header>
|
||||
<Modal.Body>
|
||||
<Textarea
|
||||
rows={3}
|
||||
id="status"
|
||||
className="w-full"
|
||||
name="status"
|
||||
onChange={(e) => handleInput(e)}
|
||||
value={_status}
|
||||
maxLength={80}
|
||||
/>
|
||||
<p className="text-sm text-right text-gray-500 dark:text-gray-300">
|
||||
{_stringLength}/80
|
||||
</p>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button color="blue" onClick={() => _setStatusSetting()}>Сохранить</Button>
|
||||
<Button color="red" onClick={() => props.setIsOpen(false)}>
|
||||
Отмена
|
||||
</Button>
|
||||
</Modal.Footer>
|
||||
</Modal>
|
||||
);
|
||||
};
|
Loading…
Add table
Reference in a new issue