Skip to content

Commit

Permalink
[ui] swipeList for ios
Browse files Browse the repository at this point in the history
  • Loading branch information
lts-po committed Apr 18, 2024
1 parent bb5b80f commit 607bb68
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions frontend/src/components/DNS/DNSOverrideList.ios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react'
import PropTypes from 'prop-types'

import {
HStack,
Pressable,
VStack,
CloseIcon,
Text
} from '@gluestack-ui/themed'

import ListHeader from 'components/List/ListHeader'
import { SwipeListView } from 'components/SwipeListView'
import DNSOverrideListItem from './DNSOverrideListItem'

const DNSOverrideList = ({ title, list, deleteListItem, ...props }) => {
const closeRow = (rowMap, rowKey) => {
if (rowMap[rowKey]) {
rowMap[rowKey].closeRow()
}
}

const deleteRow = (rowMap, rowKey) => {
closeRow(rowMap, rowKey)
let item = list.find((l) => l.Domain == rowKey)
deleteListItem(item)
}

const renderHiddenItem = (data, rowMap) => (
<HStack flex={1} pl="$2">
<Pressable
w={70}
ml="auto"
cursor="pointer"
bg="$red500"
justifyContent="center"
onPress={() => deleteRow(rowMap, data.item.Domain)}
>
<VStack alignItems="center" space="md">
<CloseIcon color="$white" />
<Text size="xs" color="$white" fontWeight="$medium">
Delete
</Text>
</VStack>
</Pressable>
</HStack>
)

return (
<>
<ListHeader title={title} description="Set rules for DNS queries">
{props.renderHeader ? props.renderHeader() : null}
</ListHeader>

<SwipeListView
data={list}
renderItem={({ item }) => (
<DNSOverrideListItem item={item} deleteListItem={deleteListItem} />
)}
renderHiddenItem={renderHiddenItem}
keyExtractor={(item, index) => item.Domain}
rightOpenValue={-70}
/>

{!list || !list.length ? (
<Text>{`No ${title.split(' ')[0]} rules configured`}</Text>
) : null}
</>
)
}

DNSOverrideList.propTypes = {
title: PropTypes.string.isRequired,
list: PropTypes.array,
notifyChange: PropTypes.func,
deleteListItem: PropTypes.func
}

export default DNSOverrideList

0 comments on commit 607bb68

Please sign in to comment.