Skip to content

Commit 7be11bb

Browse files
authored
Hide dot files by default (#368)
1 parent 81640f9 commit 7be11bb

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/components/Folder/Folder.module.css

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,36 @@
6666
}
6767
}
6868

69+
/* settings dropdown */
70+
.settings {
71+
margin-left: 8px;
72+
73+
& button::before {
74+
/* hide caret */
75+
display: none;
76+
}
77+
78+
& svg {
79+
opacity: 0.8;
80+
transition: opacity 0.2s;
81+
}
82+
83+
&:hover svg {
84+
opacity: 1;
85+
}
86+
}
87+
6988
/* search */
7089
.search {
7190
background: #fff url("../../assets/search.svg") no-repeat center right 8px;
7291
border: 1px solid transparent;
73-
border-radius: 12px;
92+
border-radius: 8px;
7493
flex-shrink: 1;
7594
font-size: 12px;
7695
height: 24px;
7796
min-width: 0;
7897
outline: none;
79-
padding: 4px 20px 2px 8px;
98+
padding: 5px 20px 5px 10px;
8099
width: 100px;
81100
transition-duration: 0.3s;
82101
transition-property: border, width;

src/components/Folder/Folder.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ import type { DirSource, FileMetadata } from '../../lib/sources/types.js'
44
import { cn, formatFileSize, getFileDate, getFileDateShort } from '../../lib/utils.js'
55
import Breadcrumb from '../Breadcrumb/Breadcrumb.js'
66
import Center from '../Center/Center.js'
7+
import Dropdown from '../Dropdown/Dropdown.js'
78
import Layout from '../Layout/Layout.js'
89
import Spinner from '../Spinner/Spinner.js'
910
import styles from './Folder.module.css'
1011

12+
const gearIcon = <svg fill='white' height='20' viewBox='0 0 24 24' width='20' xmlns='http://www.w3.org/2000/svg'>
13+
<path d='M19.14 12.94c.04-.31.06-.63.06-.94 0-.31-.02-.63-.06-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z' />
14+
</svg>
15+
1116
interface FolderProps {
1217
source: DirSource
1318
}
@@ -20,6 +25,7 @@ export default function Folder({ source }: FolderProps) {
2025
const [files, setFiles] = useState<FileMetadata[]>()
2126
const [error, setError] = useState<Error>()
2227
const [searchQuery, setSearchQuery] = useState('')
28+
const [showHiddenFiles, setShowHiddenFiles] = useState(false)
2329
const searchRef = useRef<HTMLInputElement>(null)
2430
const listRef = useRef<HTMLUListElement>(null)
2531
const { routes, customClass } = useConfig()
@@ -34,10 +40,14 @@ export default function Folder({ source }: FolderProps) {
3440
})
3541
}, [source])
3642

37-
// File search
43+
// File search and hidden files filtering
3844
const filtered = useMemo(() => {
39-
return files?.filter(file => file.name.toLowerCase().includes(searchQuery.toLowerCase()))
40-
}, [files, searchQuery])
45+
return files?.filter(file => {
46+
const matchesSearch = file.name.toLowerCase().includes(searchQuery.toLowerCase())
47+
const isHidden = file.name.startsWith('.')
48+
return matchesSearch && (showHiddenFiles || !isHidden)
49+
})
50+
}, [files, searchQuery, showHiddenFiles])
4151

4252
useEffect(() => {
4353
const searchElement = searchRef.current
@@ -90,6 +100,11 @@ export default function Folder({ source }: FolderProps) {
90100
return <Layout error={error} title={source.prefix}>
91101
<Breadcrumb source={source}>
92102
<input autoFocus className={cn(styles.search, customClass?.search)} placeholder='Search...' ref={searchRef} />
103+
<Dropdown className={styles.settings} label={gearIcon} align='right'>
104+
<button onClick={() => { setShowHiddenFiles(!showHiddenFiles) }}>
105+
{showHiddenFiles ? 'Hide hidden files' : 'Show hidden files'}
106+
</button>
107+
</Dropdown>
93108
</Breadcrumb>
94109

95110
{filtered === undefined ?

0 commit comments

Comments
 (0)