-
-
Notifications
You must be signed in to change notification settings - Fork 610
Expand file tree
/
Copy pathindex.tsx
More file actions
157 lines (152 loc) · 4.95 KB
/
index.tsx
File metadata and controls
157 lines (152 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import {
faBorderAll,
faList,
faSyncAlt,
faArrowDownAZ,
faArrowDownZA,
faHardDrive as hardDriveSolid,
faFilter,
faFilterCircleXmark,
faShuffle
} from '@fortawesome/free-solid-svg-icons'
import { faHardDrive as hardDriveLight } from '@fortawesome/free-regular-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import React, { useContext } from 'react'
import { useTranslation } from 'react-i18next'
import ContextProvider from 'frontend/state/ContextProvider'
import FormControl from '../FormControl'
import './index.css'
import classNames from 'classnames'
import LibraryContext from 'frontend/screens/Library/LibraryContext'
import TourButton from 'frontend/components/Tour/TourButton'
import { LIBRARY_TOUR_ID } from 'frontend/screens/Library/components/LibraryTour'
import { SortOptions } from 'frontend/types'
interface ActionIconsProps {
'data-tour'?: string
}
export default React.memo(function ActionIcons({
'data-tour': dataTour
}: ActionIconsProps = {}) {
const { t } = useTranslation()
const { refreshLibrary, refreshing } = useContext(ContextProvider)
const {
handleLayout,
layout,
currentSort,
setCurrentSort,
sortInstalled,
setSortInstalled,
showAlphabetFilter,
onToggleAlphabetFilter
} = useContext(LibraryContext)
return (
<div className="ActionIcons" data-tour={dataTour}>
<FormControl segmented small>
{layout === 'grid' ? (
<button
className="FormControl__button"
title={t('library.toggleLayout.list', 'Toggle to a list layout')}
onClick={() => handleLayout('list')}
>
<FontAwesomeIcon
className="FormControl__segmentedFaIcon"
icon={faList}
data-tour="library-view-toggle"
/>
</button>
) : (
<button
className="FormControl__button"
title={t('library.toggleLayout.grid', 'Toggle to a grid layout')}
onClick={() => handleLayout('grid')}
>
<FontAwesomeIcon
className="FormControl__segmentedFaIcon"
icon={faBorderAll}
data-tour="library-view-toggle"
/>
</button>
)}
{currentSort === SortOptions.random ? (
<button
className="FormControl__button"
title={t('library.sortRandom', 'Sort Randomly')}
onClick={() => setCurrentSort(SortOptions.alphaAsc)}
>
<FontAwesomeIcon
className="FormControl__segmentedFaIcon"
icon={faShuffle}
/>
</button>
) : currentSort === SortOptions.alphaDesc ? (
<button
className="FormControl__button"
title={t('library.sortDescending', 'Sort Descending')}
onClick={() => setCurrentSort(SortOptions.random)}
>
<FontAwesomeIcon
className="FormControl__segmentedFaIcon"
icon={faArrowDownZA}
/>
</button>
) : (
<button
className="FormControl__button"
title={t('library.sortAscending', 'Sort Ascending')}
onClick={() => setCurrentSort(SortOptions.alphaDesc)}
>
<FontAwesomeIcon
className="FormControl__segmentedFaIcon"
icon={faArrowDownAZ}
/>
</button>
)}
<button
className="FormControl__button"
title={t('library.sortByStatus', 'Sort by Status')}
onClick={() => setSortInstalled(!sortInstalled)}
>
<FontAwesomeIcon
className="FormControl__segmentedFaIcon"
icon={sortInstalled ? hardDriveSolid : hardDriveLight}
data-tour="library-sort-installed"
/>
</button>
<button
className="FormControl__button"
title={
showAlphabetFilter
? t('library.hideAlphabetFilter', 'Hide Alphabet Filter')
: t('library.showAlphabetFilter', 'Show Alphabet Filter')
}
onClick={onToggleAlphabetFilter}
>
<FontAwesomeIcon
className="FormControl__segmentedFaIcon"
icon={showAlphabetFilter ? faFilterCircleXmark : faFilter}
/>
</button>
<button
className={classNames('FormControl__button', {
active: refreshing
})}
title={t('generic.library.refresh', 'Refresh Library')}
onClick={async () =>
refreshLibrary({
checkForUpdates: true
})
}
>
<FontAwesomeIcon
className={classNames('FormControl__segmentedFaIcon', {
['fa-spin']: refreshing
})}
data-tour="library-refresh"
icon={faSyncAlt}
/>
</button>
<TourButton tourId={LIBRARY_TOUR_ID} className="library-tour-button" />
</FormControl>
</div>
)
})