Skip to content

Commit

Permalink
Inline prop types
Browse files Browse the repository at this point in the history
Removes unnecessary intermediate variables.
  • Loading branch information
victorlin committed Nov 13, 2024
1 parent 3b6015f commit 7fd86e0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 44 deletions.
19 changes: 11 additions & 8 deletions static-site/src/components/ExpandableTiles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ const expandPreviewHeight = 60 //pixels
const transitionDuration = "0.3s"
const transitionTimingFunction = "ease"

interface ExpandableTilesProps<AnyTile extends Tile> {
tiles: AnyTile[]
tileWidth: number
tileHeight: number
TileComponent: React.FunctionComponent<{ tile: AnyTile }>
}

export const ExpandableTiles = <AnyTile extends Tile>({tiles, tileWidth, tileHeight, TileComponent}: ExpandableTilesProps<AnyTile>) => {
export const ExpandableTiles = <AnyTile extends Tile>({
tiles,
tileWidth,
tileHeight,
TileComponent,
}: {
tiles: AnyTile[]
tileWidth: number
tileHeight: number
TileComponent: React.FunctionComponent<{ tile: AnyTile }>
}) => {

const [tilesContainerHeight, setTilesContainerHeight] = useState<number>(0);
const [isExpanded, setIsExpanded] = useState<boolean>(false);
Expand Down
31 changes: 19 additions & 12 deletions static-site/src/components/ListResources/IndividualResource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ export const ResourceLink = styled.a`
}
`;

interface NameProps {
function Name({
displayName,
href,
topOfColumn,
}: {
displayName: ResourceDisplayName
href: string
topOfColumn: boolean
}

function Name({displayName, href, topOfColumn}: NameProps) {
}) {
const [hovered, setHovered] = useState(false);

return (
Expand Down Expand Up @@ -88,15 +90,19 @@ export function TooltipWrapper({description, children}) {
)
}

interface IconContainerProps {
export function IconContainer({
Icon,
text,
handleClick,
color,
hoverColor,
}: {
Icon: IconType
text: string
handleClick?: () => void
color?: string
hoverColor?: string
}

export function IconContainer({Icon, text, handleClick, color, hoverColor}: IconContainerProps) {
}) {
const [hovered, setHovered] = useState(false);
const defaultColor = '#aaa';
const defaultHoverColor = "rgb(79, 75, 80)";
Expand All @@ -115,12 +121,13 @@ export function IconContainer({Icon, text, handleClick, color, hoverColor}: Icon
}


interface IndividualResourceProps {
export const IndividualResource = ({
resource,
isMobile,
}: {
resource: Resource
isMobile: boolean
}

export const IndividualResource = ({resource, isMobile}: IndividualResourceProps) => {
}) => {
const setModalResource = useContext(SetModalResourceContext);
if (!setModalResource) throw new Error("Context not provided!")

Expand Down
9 changes: 5 additions & 4 deletions static-site/src/components/ListResources/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ export const RAINBOW20 = ["#511EA8", "#4432BD", "#3F4BCA", "#4065CF", "#447ECC
const lightGrey = 'rgba(0,0,0,0.1)';


interface ResourceModalProps {
export const ResourceModal = ({
resource,
dismissModal,
}: {
resource?: Resource
dismissModal: () => void
}

export const ResourceModal = ({resource, dismissModal}: ResourceModalProps) => {
}) => {
const [ref, setRef] = useState(null);
const handleRef = useCallback((node) => {setRef(node)}, [])

Expand Down
32 changes: 21 additions & 11 deletions static-site/src/components/ListResources/ResourceGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ import { IndividualResource, getMaxResourceWidth, TooltipWrapper, IconContainer,
import { SetModalResourceContext } from "./Modal";
import { Group, QuickLink, Resource } from './types';

interface ResourceGroupHeaderProps {
const ResourceGroupHeader = ({
group,
isMobile,
setCollapsed,
collapsible,
isCollapsed,
resourcesToShowWhenCollapsed,
quickLinks,
}: {
group: Group
isMobile: boolean
setCollapsed: React.Dispatch<React.SetStateAction<boolean>>
collapsible: boolean
isCollapsed: boolean
resourcesToShowWhenCollapsed: number
quickLinks: QuickLink[]
}

const ResourceGroupHeader = ({group, isMobile, setCollapsed, collapsible, isCollapsed, resourcesToShowWhenCollapsed, quickLinks}: ResourceGroupHeaderProps) => {
}) => {
const setModalResource = useContext(SetModalResourceContext);
if (!setModalResource) throw new Error("Context not provided!")

Expand Down Expand Up @@ -112,18 +118,22 @@ const ResourceGroupHeader = ({group, isMobile, setCollapsed, collapsible, isColl
)
}

interface ResourceGroupProps {
/**
* Displays a single resource group (e.g. a single pathogen)
*/
export const ResourceGroup = ({
group,
elWidth,
numGroups,
sortMethod,
quickLinks,
}: {
group: Group
elWidth: number
numGroups: number
sortMethod: string
quickLinks: QuickLink[]
}

/**
* Displays a single resource group (e.g. a single pathogen)
*/
export const ResourceGroup = ({group, elWidth, numGroups, sortMethod, quickLinks}: ResourceGroupProps) => {
}) => {
const {collapseThreshold, resourcesToShowWhenCollapsed} = collapseThresolds(numGroups);
const collapsible = group.resources.length > collapseThreshold;
const [isCollapsed, setCollapsed] = useState(collapsible); // if it is collapsible, start collapsed
Expand Down
18 changes: 9 additions & 9 deletions static-site/src/components/ListResources/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import { ExpandableTiles } from "../ExpandableTiles";
import { FilterTile, FilterOption, Group, QuickLink, Resource, ResourceListingInfo, SortMethod } from './types';
import { HugeSpacer } from "../../layouts/generalComponents";

interface ListResourcesProps extends ListResourcesResponsiveProps {
elWidth: number
}

const LIST_ANCHOR = "list";

const SetSelectedFilterOptions = createContext<React.Dispatch<React.SetStateAction<readonly FilterOption[]>> | null>(null);
Expand All @@ -40,7 +36,9 @@ function ListResources({
groupDisplayNames,
tileData,
resourceListingCallback: resourceListingCallback,
}: ListResourcesProps) {
}: ListResourcesResponsiveProps & {
elWidth: number
}) {
const {groups, dataFetchError} = useDataFetch(
versioned,
defaultGroupLinks,
Expand Down Expand Up @@ -208,13 +206,15 @@ function SortOptions({sortMethod, changeSortMethod}: {
)
}

interface FilterProps {
function Filter({
options,
selectedFilterOptions,
setSelectedFilterOptions,
}: {
options: FilterOption[]
selectedFilterOptions: readonly FilterOption[]
setSelectedFilterOptions: React.Dispatch<React.SetStateAction<readonly FilterOption[]>>
}

function Filter({options, selectedFilterOptions, setSelectedFilterOptions}: FilterProps) {
}) {

const onChange = (options: MultiValue<FilterOption>) => {
if (options) {
Expand Down

0 comments on commit 7fd86e0

Please sign in to comment.