Skip to content

Commit

Permalink
Added icons
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeBellTMH committed May 23, 2023
1 parent 05d8537 commit 7bf041b
Show file tree
Hide file tree
Showing 15 changed files with 1,435 additions and 701 deletions.
2 changes: 2 additions & 0 deletions amplify/backend/api/jcmobile/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,7 @@ type Menu
name:String
action:String
params:String
icon:Image
readGroups:[UserGroupType]
subItems: [SubMenu] @connection(name:"subMenuMenu",keyField: "menuID",sortField:"order")

Expand All @@ -1434,6 +1435,7 @@ type SubMenu
menu:Menu @connection(name:"subMenuMenu",keyField:"menuID")
name:String
action:String
icon:Image
params:String
readGroups:[UserGroupType]
}
Expand Down
Binary file added assets/20x20.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import {
StyleSheet,
Text,
TouchableOpacity,
useWindowDimensions,
View,
useWindowDimensions,
} from "react-native"
import { ListMenusQuery } from "src/API-customqueries"
import SearchInactiveIcon from "../../assets/Facelift/svg/Search-2.svg"
import { Data } from "../../components/Data/Data"
import JCImage, { JCImageQuality, JCImageStyle } from "../../components/ProfileImage/JCImage"
import { constants } from "../../src/constants"
import { JCCognitoUser } from "../../src/types"
import SearchBar from "../Forms/SearchBar/SearchBar"
Expand Down Expand Up @@ -278,6 +279,14 @@ export default function HeaderJC(props: Props) {
openScreen(subItem.action ?? "", subItem.params)
}}
>
<View style={{ width: 25, height: 20 }}>
<JCImage
style={JCImageStyle.IconSmall}
quality={JCImageQuality.small}
type={"icon"}
image={subItem.icon}
/>
</View>
<Text testID="header-resources-all" style={headerStyles.dropdownText}>
{subItem.name}
</Text>
Expand Down
89 changes: 89 additions & 0 deletions components/ProfileImage/JCImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { useEffect, useRef } from "react"
import {
Animated,
Image,
ImageSourcePropType,
ImageStyle,
StyleSheet,
View,
ViewStyle,
} from "react-native"
import { ImageInput } from "src/API"
import DefaultImage from "../../assets/20x20.png"
import useJCImage from "./useJCImage"

export enum JCImageQuality {
small = "small",
medium = "medium",
large = "large",
}
export enum JCImageStyle {
IconSmall = "IconSmall",
}
type JCImageType = "icon" | "resource"
export type JCImageProps = {
containerStyle?: ViewStyle
imageStyle?: ImageStyle
style: JCImageStyle
quality: JCImageQuality
type: JCImageType
image: ImageInput | null | undefined
linkToProfile?: boolean
showNameInToolTip?: boolean
}

export const ProfileImageStyles = StyleSheet.create({
Bordered: {
borderColor: "#E4E1E1",
borderWidth: 0,
// for some reason, borderWidth:1 breaks the image spacing on Chrome browser randomly
// not sure what's going on here
},
ImageContainer: {
backgroundColor: "#fff",
},
IconSmall: {
height: 20,
width: 20,
},
})
export default function JCImage(props: JCImageProps) {
const { url, isLoading = true } = useJCImage(props)
const fadeAnim = useRef(new Animated.Value(0)).current
const fadeAnim2 = useRef(new Animated.Value(1)).current
const fade = () => {
Animated.timing(fadeAnim, {
toValue: 1,
duration: 1000,
useNativeDriver: true,
}).start()
Animated.timing(fadeAnim2, {
toValue: 0,
duration: 1000,
useNativeDriver: true,
}).start()
}
useEffect(() => {
if (url && !isLoading) fade()
}, [url, isLoading])
return (
<View>
<Animated.View style={{ opacity: fadeAnim2, position: "absolute" }}>
<Image
resizeMode={"cover"}
style={[ProfileImageStyles[props.style], props.imageStyle, ProfileImageStyles.Bordered]}
source={DefaultImage}
/>
</Animated.View>
{!isLoading && url ? (
<Animated.View style={{ opacity: fadeAnim }}>
<Image
resizeMode={props.type === "icon" ? "contain" : "cover"}
style={[ProfileImageStyles[props.style], props.imageStyle, ProfileImageStyles.Bordered]}
source={url as ImageSourcePropType}
/>
</Animated.View>
) : null}
</View>
)
}
49 changes: 49 additions & 0 deletions components/ProfileImage/useJCImage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Storage } from "aws-amplify"
import { useEffect, useState } from "react"
import { JCImageProps } from "./JCImage"

export default function useJCImage(props: JCImageProps) {
const [url, setUrl] = useState<string>("")
const [isLoading, setIsLoading] = useState(true)
useEffect(() => {
const loadImageFromStorage = async () => {
let imgUrl: string | null | undefined
switch (props.quality) {
case "large":
imgUrl = props.image?.filenameLarge
break
case "medium":
imgUrl = props.image?.filenameMedium
break
case "small":
imgUrl = props.image?.filenameSmall
break
default:
imgUrl = props.image?.filenameMedium
break
}
try {
setIsLoading(true)
if (imgUrl) {
// Storage.get() not throwing error when file does not exist
// Current implementation shows default image while loading
// Errored requests that don't throw an error will maintain loading state,
const pfImage = await Storage.get(imgUrl, {
level: "protected",
contentType: "image/png",
identityId: props.image?.userId ?? "",
})
setIsLoading(false)
setUrl(pfImage)
} else {
console.log("No Image URL Found.")
}
} catch (err) {
console.log({ err })
setUrl("")
}
}
if (props.image) loadImageFromStorage()
}, [props.quality, props.image])
return { url: url, isLoading }
}
3 changes: 2 additions & 1 deletion components/ResourceViewer/ResourceImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Props {
fileName: string
currentImage: ImageInput | null | undefined
onUpdate(image: ImageInput): void
style?: ButtonTypes
}
interface State extends JCState {
uploading: boolean
Expand Down Expand Up @@ -46,7 +47,7 @@ class ResourceImage extends JCComponent<Props, State> {
) : (
<>
<JCButton
buttonType={ButtonTypes.Transparent}
buttonType={this.props.style ?? ButtonTypes.Transparent}
onPress={() => {
null
}}
Expand Down
35 changes: 34 additions & 1 deletion screens/Admin/AdminMenuScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { Data } from "../../components/Data/Data"
import JCButton, { ButtonTypes } from "../../components/Forms/JCButton"
import JCModal from "../../components/Forms/JCModal"
import Header from "../../components/Header/Header"
import { ListSubMenusQuery, UserGroupType } from "../../src/API"
import JCImage, { JCImageQuality, JCImageStyle } from "../../components/ProfileImage/JCImage"
import ResourceImage from "../../components/ResourceViewer/ResourceImage"
import { ImageInput, ListSubMenusQuery, UserGroupType } from "../../src/API"
import { UserContext } from "../HomeScreen/UserContext"
interface Props {
navigation: StackNavigationProp<any, any>
Expand All @@ -31,6 +33,7 @@ export default function AdminScreen(props: Props) {
const [menuName, setMenuName] = useState<string>()
const [menuProps, setMenuProps] = useState<string>()
const [subMenuName, setSubMenuName] = useState<string>()
const [subMenuImage, setSubMenuImage] = useState<ImageInput>()
const [menuAction, setMenuAction] = useState<string>()
const [subMenuAction, setSubMenuAction] = useState<string>()
const [subMenuProps, setSubMenuProps] = useState<string>()
Expand Down Expand Up @@ -103,6 +106,7 @@ export default function AdminScreen(props: Props) {
const z = await Data.updateSubMenu({
id: showEditSubMenuItem,
name: subMenuName,
icon: subMenuImage,
action: subMenuAction,
params: subMenuProps,
readGroups: groupData,
Expand All @@ -112,6 +116,7 @@ export default function AdminScreen(props: Props) {
setSubMenuAction("")
setSubMenuProps("")
setGroupData([])
setSubMenuImage({})
await setInitialData()
closeAddSubMenuItem()
}
Expand All @@ -127,13 +132,15 @@ export default function AdminScreen(props: Props) {
params: subMenuProps,
readGroups: groupData,
menuID: showAddSubMenuItem,
icon: subMenuImage,
order: menus.filter((f) => f.id == showAddSubMenuItem)[0].subItems?.items.length,
})
console.log(z)
setSubMenuName("")
setSubMenuAction("")
setSubMenuProps("")
setGroupData([])
setSubMenuImage({})
await setInitialData()
closeAddSubMenuItem()
} catch (e) {
Expand Down Expand Up @@ -287,6 +294,14 @@ export default function AdminScreen(props: Props) {
value={subMenuProps}
style={styles.adminCRMModalInviteEmail}
></TextInput>
<ResourceImage
onUpdate={(image: ImageInput) => {
setSubMenuImage(image)
}}
style={ButtonTypes.AdminOutline}
fileName={"menus/upload/icon-test-"}
currentImage={subMenuImage}
></ResourceImage>
<Text style={styles.adminCRMModal}>Visible to:</Text>
{groupData
? groupData.map((item: any, index: number) => {
Expand Down Expand Up @@ -370,6 +385,7 @@ export default function AdminScreen(props: Props) {
setShowAddSubMenuItem(null)
setShowEditSubMenuItem(null)
setSubMenuName("")
setSubMenuImage({})
setSubMenuAction("")
setSubMenuProps("")
setGroupData([])
Expand All @@ -386,6 +402,7 @@ export default function AdminScreen(props: Props) {
const editSubMenuItem = (item: any) => {
setShowEditSubMenuItem(item.id)
setSubMenuName(item.name)
setSubMenuImage(item.icon)
setSubMenuAction(item.action)
setSubMenuProps(item.params)
setGroupData(item.readGroups)
Expand Down Expand Up @@ -525,6 +542,14 @@ export default function AdminScreen(props: Props) {
<div style={{ width: "100%" }}>
<div style={{ display: "flex", flexDirection: "row" }}>
<div style={{ display: "flex", flexGrow: 1, flexDirection: "row" }}>
<View style={{ width: 25 }}>
<JCImage
style={JCImageStyle.IconSmall}
quality={JCImageQuality.small}
type={"icon"}
image={item.icon}
/>
</View>
<Text>{item.name}</Text>
<JCButton
buttonType={ButtonTypes.AdminSmallOutline}
Expand Down Expand Up @@ -579,6 +604,14 @@ export default function AdminScreen(props: Props) {
<div style={{ display: "flex", flexDirection: "row" }}>
<div style={{ display: "flex", flexGrow: 1, flexDirection: "row" }}>
<Text>&nbsp;&nbsp;&nbsp;</Text>
<View style={{ width: 25 }}>
<JCImage
style={JCImageStyle.IconSmall}
quality={JCImageQuality.small}
type={"icon"}
image={item2.icon}
/>
</View>
<Text>{item2.name}</Text>
<JCButton
buttonType={ButtonTypes.AdminSmallOutline}
Expand Down

0 comments on commit 7bf041b

Please sign in to comment.