Skip to content

Commit

Permalink
Updates how current template is handled
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlanciaux committed Jan 22, 2024
1 parent e8c2ea8 commit 9758bd3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions apps/preview/app/src/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Collapsible from '@radix-ui/react-collapsible';
import classnames from 'classnames';
import { LayoutGroup, motion } from 'framer-motion';
import * as React from 'react';
import { Link } from 'react-router-dom';
import { Link, useLocation } from 'react-router-dom';

import type { TemplatePart } from '../types';

Expand Down Expand Up @@ -87,8 +87,11 @@ const SidebarSection = ({
isSubSection,
title = 'Email Templates'
}: SidebarSectionProps) => {
const { pathname: basePathName } = useLocation();
const pathname = basePathName.startsWith('/') ? basePathName.slice(1) : basePathName;

const [isOpen, setIsOpen] = React.useState(
!isSubSection || templateParts.some((item) => item.path === currentPageTitle)
!isSubSection || pathname.indexOf(title.toLowerCase()) > -1
);

return (
Expand Down Expand Up @@ -118,7 +121,7 @@ const SidebarSection = ({

{templateParts && templateParts.length > 0 && (
<Collapsible.Content
className={classnames('mt-1 collapsible-content', {
className={classnames('relative collapsible-content', {
'mt-1': isSubSection,
'mt-3': !isSubSection
})}
Expand All @@ -131,7 +134,7 @@ const SidebarSection = ({
<LayoutGroup id="sidebar">
{templateParts &&
templateParts.map((item) => {
const isCurrentPage = currentPageTitle === item.path;
const isCurrentPage = pathname === item.path;
const isParent = item.children && item.children.length > 0;
return isParent ? (
<div className="pl-4">
Expand Down

0 comments on commit 9758bd3

Please sign in to comment.