mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
feat: Add delete button to listing detail view (#304)
Co-authored-by: datenwurm <git@datenwurm.net>
This commit is contained in:
@@ -31,6 +31,7 @@ import {
|
|||||||
IconLink,
|
IconLink,
|
||||||
IconStar,
|
IconStar,
|
||||||
IconStarStroked,
|
IconStarStroked,
|
||||||
|
IconDelete,
|
||||||
IconExpand,
|
IconExpand,
|
||||||
IconGridView,
|
IconGridView,
|
||||||
} from '@douyinfe/semi-icons';
|
} from '@douyinfe/semi-icons';
|
||||||
@@ -39,7 +40,8 @@ import 'maplibre-gl/dist/maplibre-gl.css';
|
|||||||
import no_image from '../../assets/no_image.png';
|
import no_image from '../../assets/no_image.png';
|
||||||
import * as timeService from '../../services/time/timeService.js';
|
import * as timeService from '../../services/time/timeService.js';
|
||||||
import { distanceMeters, getBoundsFromCoords } from './mapUtils.js';
|
import { distanceMeters, getBoundsFromCoords } from './mapUtils.js';
|
||||||
import { xhrPost } from '../../services/xhr.js';
|
import { xhrPost, xhrDelete } from '../../services/xhr.js';
|
||||||
|
import ListingDeletionModal from '../../components/ListingDeletionModal.jsx';
|
||||||
|
|
||||||
import Headline from '../../components/headline/Headline.jsx';
|
import Headline from '../../components/headline/Headline.jsx';
|
||||||
import './ListingDetail.less';
|
import './ListingDetail.less';
|
||||||
@@ -59,6 +61,7 @@ export default function ListingDetail() {
|
|||||||
const mapContainer = useRef(null);
|
const mapContainer = useRef(null);
|
||||||
const map = useRef(null);
|
const map = useRef(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [deleteModalVisible, setDeleteModalVisible] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchListing() {
|
async function fetchListing() {
|
||||||
@@ -239,6 +242,18 @@ export default function ListingDetail() {
|
|||||||
};
|
};
|
||||||
}, [listing, loading, homeAddress]);
|
}, [listing, loading, homeAddress]);
|
||||||
|
|
||||||
|
const confirmDeletion = async (hardDelete) => {
|
||||||
|
try {
|
||||||
|
await xhrDelete('/api/listings/', { ids: [listing.id], hardDelete });
|
||||||
|
Toast.success('Listing successfully removed');
|
||||||
|
navigate('/listings');
|
||||||
|
} catch (e) {
|
||||||
|
Toast.error(e.message || 'Error deleting listing');
|
||||||
|
} finally {
|
||||||
|
setDeleteModalVisible(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleWatch = async () => {
|
const handleWatch = async () => {
|
||||||
try {
|
try {
|
||||||
await xhrPost('/api/listings/watch', { listingId: listing.id });
|
await xhrPost('/api/listings/watch', { listingId: listing.id });
|
||||||
@@ -330,6 +345,14 @@ export default function ListingDetail() {
|
|||||||
<IconLink style={{ marginRight: 6 }} />
|
<IconLink style={{ marginRight: 6 }} />
|
||||||
Open listing
|
Open listing
|
||||||
</a>
|
</a>
|
||||||
|
<Button
|
||||||
|
icon={<IconDelete />}
|
||||||
|
onClick={() => setDeleteModalVisible(true)}
|
||||||
|
theme="light"
|
||||||
|
type="danger"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -397,6 +420,12 @@ export default function ListingDetail() {
|
|||||||
<div ref={mapContainer} className="listing-detail__map-container" />
|
<div ref={mapContainer} className="listing-detail__map-container" />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<ListingDeletionModal
|
||||||
|
visible={deleteModalVisible}
|
||||||
|
onConfirm={confirmDeletion}
|
||||||
|
onCancel={() => setDeleteModalVisible(false)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user