сделал обновление данных без проверки на кэширование

This commit is contained in:
Андрей Дувакин 2025-02-18 16:37:34 +05:00
parent 8b7c427602
commit 699bf958a9
4 changed files with 51 additions and 11 deletions

View File

@ -46,7 +46,7 @@ const LensListCard = ({ lens, handleEditLens, handleDeleteLens }) => {
<p><strong>🔬 Тор:</strong> {lens.tor} D</p> <p><strong>🔬 Тор:</strong> {lens.tor} D</p>
<p><strong>📏 Диаметр:</strong> {lens.diameter} мм</p> <p><strong>📏 Диаметр:</strong> {lens.diameter} мм</p>
<p><strong>🔄 Пресетная рефракция:</strong> {lens.preset_refraction} D</p> <p><strong>🔄 Пресетная рефракция:</strong> {lens.preset_refraction} D</p>
<p><strong> Перефирийная торичность:</strong> {lens.periphery_toricity} D</p> <p><strong> Периферийная торичность:</strong> {lens.periphery_toricity} D</p>
{lens.issued && <p><strong> Линза выдана</strong></p>} {lens.issued && <p><strong> Линза выдана</strong></p>}
</Card> </Card>

View File

@ -37,7 +37,7 @@ const LensViewModal = ({visible, onCancel, lens}) => {
<Col xs={24} md={12}> <Col xs={24} md={12}>
<div style={{marginBottom: 12}}> <div style={{marginBottom: 12}}>
<Title level={5}> Перефирийная торичность</Title> <Title level={5}> Периферийная торичность</Title>
<Text>{lens.periphery_toricity} D</Text> <Text>{lens.periphery_toricity} D</Text>
</div> </div>
@ -47,7 +47,7 @@ const LensViewModal = ({visible, onCancel, lens}) => {
</div> </div>
<div style={{marginBottom: 12}}> <div style={{marginBottom: 12}}>
<Title level={5}> Статус выдачи</Title> <Title level={5}>{lens.issued ? '✅' : '❌'} Статус выдачи</Title>
<Text>{lens.issued ? 'Выдана' : 'Не выдана'}</Text> <Text>{lens.issued ? 'Выдана' : 'Не выдана'}</Text>
</div> </div>
</Col> </Col>
@ -56,7 +56,7 @@ const LensViewModal = ({visible, onCancel, lens}) => {
<Divider/> <Divider/>
<div style={{marginBottom: 12}}> <div style={{marginBottom: 12}}>
<Title level={5}> Пробная линза (Trial)</Title> <Title level={5}>👀 Острота зрения (Trial)</Title>
<Text>{lens.trial.toFixed(2)} D</Text> <Text>{lens.trial.toFixed(2)} D</Text>
</div> </div>
</Modal> </Modal>

View File

@ -1,5 +1,5 @@
import {useState, useEffect} from "react"; import {useState, useEffect} from "react";
import {Input, Select, List, FloatButton, Row, Col, Spin} from "antd"; import {Input, Select, List, FloatButton, Row, Col, Spin, Checkbox} from "antd";
import {LoadingOutlined, PlusOutlined} from "@ant-design/icons"; import {LoadingOutlined, PlusOutlined} from "@ant-design/icons";
import LensCard from "../components/lenses/LensListCard.jsx"; import LensCard from "../components/lenses/LensListCard.jsx";
import getAllLenses from "../api/lenses/GetAllLenses.jsx"; import getAllLenses from "../api/lenses/GetAllLenses.jsx";
@ -21,12 +21,34 @@ const LensesPage = () => {
const [lenses, setLenses] = useState([]); const [lenses, setLenses] = useState([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [isModalVisible, setIsModalVisible] = useState(false); const [isModalVisible, setIsModalVisible] = useState(false);
const [showIssuedLenses, setShowIssuedLenses] = useState(false);
const [selectedLens, setSelectedLens] = useState(null); const [selectedLens, setSelectedLens] = useState(null);
useEffect(() => { useEffect(() => {
fetchLenses(); fetchLensWithCache();
}, []); }, []);
useEffect(() => {
if (!isModalVisible) {
const intervalId = setInterval(fetchLenses, 5000);
return () => clearInterval(intervalId);
}
}, [user, isModalVisible]);
const fetchLensWithCache = async () => {
const cachedData = localStorage.getItem("lensData");
const cacheTimestamp = localStorage.getItem("lensTimestamp");
if (cachedData && cacheTimestamp && (Date.now() - parseInt(cacheTimestamp)) < 60 * 1000) {
setLenses(JSON.parse(cachedData));
setLoading(false);
return;
}
await fetchLenses();
};
const fetchLenses = async () => { const fetchLenses = async () => {
if (!user || !user.token) return; if (!user || !user.token) return;
@ -43,7 +65,8 @@ const LensesPage = () => {
const filteredLenses = lenses.filter((lens) => const filteredLenses = lenses.filter((lens) =>
Object.values(lens).some((value) => Object.values(lens).some((value) =>
value?.toString().toLowerCase().includes(searchText.toLowerCase()) value?.toString().toLowerCase().includes(searchText.toLowerCase())
) ) &&
(showIssuedLenses || lens.issued === false)
).sort((a, b) => { ).sort((a, b) => {
return sortOrder === "asc" return sortOrder === "asc"
? a.preset_refraction - b.preset_refraction ? a.preset_refraction - b.preset_refraction
@ -88,7 +111,7 @@ const LensesPage = () => {
return ( return (
<div style={{padding: 20}}> <div style={{padding: 20}}>
<Row gutter={[16, 16]} style={{marginBottom: 20}}> <Row gutter={[16, 16]} style={{marginBottom: 20}}>
<Col xs={24} sm={16}> <Col xs={24} sm={12}>
<Input <Input
placeholder="Поиск линзы" placeholder="Поиск линзы"
value={searchText} value={searchText}
@ -107,10 +130,26 @@ const LensesPage = () => {
<Option value="desc">По убыванию рефракции</Option> <Option value="desc">По убыванию рефракции</Option>
</Select> </Select>
</Col> </Col>
<Col xs={24} sm={4}>
<Checkbox
onChange={(e) => {
setShowIssuedLenses(e.target.checked);
}}
>
Показать выданные
</Checkbox>
</Col>
</Row> </Row>
{loading ? ( {loading ? (
<Spin indicator={<LoadingOutlined style={{fontSize: 48}} spin/>}/> <div style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
height: "100vh",
}}>
<Spin indicator={<LoadingOutlined style={{fontSize: 64, color: "#1890ff"}} spin/>}/>
</div>
) : ( ) : (
<List <List
grid={{gutter: 16, xs: 1, sm: 1, md: 2, lg: 3, xl: 4}} grid={{gutter: 16, xs: 1, sm: 1, md: 2, lg: 3, xl: 4}}

View File

@ -30,7 +30,7 @@ const PatientsPage = () => {
useEffect(() => { useEffect(() => {
if (!isModalVisible) { if (!isModalVisible) {
const intervalId = setInterval(fetchPatientsWithCache, 5000); const intervalId = setInterval(fetchPatients, 5000);
return () => clearInterval(intervalId); return () => clearInterval(intervalId);
} }
}, [user, isModalVisible]); }, [user, isModalVisible]);
@ -181,7 +181,8 @@ const PatientsPage = () => {
height: "100vh", height: "100vh",
}}> }}>
<Spin indicator={<LoadingOutlined style={{fontSize: 64, color: "#1890ff"}} spin/>}/> <Spin indicator={<LoadingOutlined style={{fontSize: 64, color: "#1890ff"}} spin/>}/>
</div>) : ( </div>
) : (
<List <List
grid={{ grid={{
gutter: 16, gutter: 16,