Skip to content

Commit

Permalink
[ui] use swipelist for ios, see #306
Browse files Browse the repository at this point in the history
  • Loading branch information
lts-po committed Apr 18, 2024
1 parent 607bb68 commit 340b5df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 83 deletions.
89 changes: 6 additions & 83 deletions frontend/src/components/DNS/DNSOverrideList.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
import React from 'react'
import PropTypes from 'prop-types'

import { AlertContext } from 'layouts/Admin'
import { blockAPI } from 'api/DNS'
import { format as timeAgo } from 'timeago.js'

import {
Box,
VStack,
FlatList,
HStack,
Text,
Button,
ButtonIcon,
CloseIcon
} from '@gluestack-ui/themed'
import { FlatList, Text } from '@gluestack-ui/themed'

import ListHeader from 'components/List/ListHeader'
import { ListItem } from 'components/List'

const DNSOverrideList = ({ title, list, ...props }) => {
const context = React.useContext(AlertContext)

const deleteListItem = async (item) => {
blockAPI
.deleteOverride(item)
.then((res) => {
props.notifyChange('config')
})
.catch((error) => {
context.error('API Failure: ' + error.message)
})
}
import DNSOverrideListItem from './DNSOverrideListItem'

const DNSOverrideList = ({ title, list, deleteListItem, ...props }) => {
return (
<>
<ListHeader title={title} description="Set rules for DNS queries">
Expand All @@ -45,59 +19,7 @@ const DNSOverrideList = ({ title, list, ...props }) => {
<FlatList
data={list}
renderItem={({ item }) => (
<ListItem>
<VStack
sx={{ '@md': { flexDirection: 'row' } }}
justifyContent="space-evenly"
flex={1}
space="md"
>
<VStack
flex={1}
space="md"
sx={{ '@md': { flexDirection: 'row' } }}
>
<Text bold>{item.Domain}</Text>
<HStack space={'md'}>
<Text
sx={{
'@base': { display: 'none' },
'@md': { display: 'flex' }
}}
color="$muted500"
>
=
</Text>
<Text>{item.ResultIP || '0.0.0.0'}</Text>
</HStack>
</VStack>

<VStack
flex={1}
space="md"
sx={{ '@md': { flexDirection: 'row' } }}
justifyContent="space-between"
>
<HStack space={'md'}>
<Text color="$muted500">Client:</Text>
<Text>{item.ClientIP}</Text>
</HStack>

<HStack space={'md'}>
<Text color="$muted500">Expiration:</Text>
<Text>
{item.Expiration
? timeAgo(new Date(item.Expiration * 1e3))
: 'Never'}
</Text>
</HStack>
</VStack>
</VStack>

<Button variant="link" onPress={() => deleteListItem(item)}>
<ButtonIcon as={CloseIcon} color="$red700" />
</Button>
</ListItem>
<DNSOverrideListItem item={item} deleteListItem={deleteListItem} />
)}
keyExtractor={(item) => item.Domain}
/>
Expand All @@ -108,7 +30,8 @@ const DNSOverrideList = ({ title, list, ...props }) => {
DNSOverrideList.propTypes = {
title: PropTypes.string.isRequired,
list: PropTypes.array,
notifyChange: PropTypes.func
notifyChange: PropTypes.func,
deleteListItem: PropTypes.func
}

export default DNSOverrideList
13 changes: 13 additions & 0 deletions frontend/src/views/DNS/DNSOverride.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ const DNSBlock = (props) => {
refreshConfig()
}

const deleteListItem = async (item) => {
blockAPI
.deleteOverride(item)
.then((res) => {
notifyChange('config')
})
.catch((error) => {
context.error('API Failure: ' + error.message)
})
}

if (!enabled) {
return <PluginDisabled plugin="dns" />
}
Expand All @@ -74,6 +85,7 @@ const DNSBlock = (props) => {
list={BlockDomains}
title="Block Custom Domain"
notifyChange={notifyChange}
deleteListItem={deleteListItem}
renderHeader={() => (
<ModalForm
title="Add Block for Custom Domain"
Expand All @@ -96,6 +108,7 @@ const DNSBlock = (props) => {
list={PermitDomains}
title="Permit Domain Override"
notifyChange={notifyChange}
deleteListItem={deleteListItem}
renderHeader={() => (
<ModalForm
title="Add Permit Domain Override"
Expand Down

0 comments on commit 340b5df

Please sign in to comment.