Skip to content

Commit 243a9fa

Browse files
authored
fix: show favorite only if operators (#75)
1 parent 1629a85 commit 243a9fa

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@nethesis/nethesis-brands-svg-icons": "github:nethesis/Font-Awesome#ns-brands",
5050
"@nethesis/nethesis-light-svg-icons": "github:nethesis/Font-Awesome#ns-light",
5151
"@nethesis/nethesis-solid-svg-icons": "github:nethesis/Font-Awesome#ns-solid",
52-
"@nethesis/phone-island": "^0.17.4",
52+
"@nethesis/phone-island": "^0.17.7",
5353
"@tailwindcss/forms": "^0.5.7",
5454
"@types/lodash": "^4.14.202",
5555
"@types/node": "^18.19.9",

src/renderer/src/components/Modules/NethVoice/Speeddials/hook/useFavouriteModule.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const useFavouriteModule = () => {
1313
const { NethVoiceAPI } = useLoggedNethVoiceAPI()
1414
useEffect(() => {
1515
rawSpeedDials && filterFavourites(rawSpeedDials, speeddialsModule?.favouriteOrder || FilterTypes.AZ)
16-
}, [rawSpeedDials, speeddialsModule?.favouriteOrder])
16+
}, [rawSpeedDials, speeddialsModule?.favouriteOrder, operators])
1717

1818
const getSorter = (order: FilterTypes) => {
1919
let sorter: ((a: ContactType, b: ContactType) => number) | undefined = undefined
@@ -32,14 +32,28 @@ export const useFavouriteModule = () => {
3232
}
3333

3434
const filterFavourites = (rawSpeeddials: ContactType[], order: FilterTypes) => {
35-
const favourites = rawSpeeddials.filter(isFavourite).sort(getSorter(order))
35+
const favourites = rawSpeeddials
36+
.filter(isFavourite)
37+
.filter(isActiveOperator)
38+
.sort(getSorter(order))
3639
setFavourites(() => [...favourites])
3740
}
3841

3942
const isFavourite = (contact: ContactType) => {
4043
return contact.notes?.includes(SpeeddialTypes.FAVOURITES)
4144
}
4245

46+
const isActiveOperator = (contact: ContactType) => {
47+
// If no operators data or no contact name, don't show the favorite
48+
if (!operators?.groups || !contact.name) {
49+
return false
50+
}
51+
// Check if the contact's username exists in any operator group
52+
return Object.values(operators.groups).some(group =>
53+
group.users.includes(contact.name!)
54+
)
55+
}
56+
4357
const isSearchAlsoAFavourite = (contact: SearchData) => {
4458
const foundedContact = favourites?.find((s) => s.speeddial_num === (contact.speeddial_num || contact.extension))
4559
if (foundedContact) {

src/shared/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type AvailableDevices = 'nethlink' | 'physical' | 'webrtc'
55

66
export enum PAGES {
77
SPLASHSCREEN = "splashscreenpage",
8-
LOGIN = "NethLink-Login",
8+
LOGIN = "Login",
99
PHONEISLAND = "phoneislandpage",
1010
NETHLINK = "NethLink",
1111
DEVTOOLS = "devtoolspage"

0 commit comments

Comments
 (0)