-
-
Notifications
You must be signed in to change notification settings - Fork 265
feat: add code explorer for the examples #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for tanstack ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
d673bae to
1e2231d
Compare
| const [expandedFolders, setExpandedFolders] = React.useState<Set<string>>( | ||
| () => { | ||
| const expanded = new Set<string>() | ||
| if (githubContents) { | ||
| const flattened = recursiveFlattenGithubContents(githubContents) | ||
| if (flattened.every((f) => f.depth === 0)) { | ||
| return expanded | ||
| } | ||
|
|
||
| // if the currentPath matches, then open | ||
| for (const file of flattened) { | ||
| if (file.path === currentPath) { | ||
| // Open all ancestors directories | ||
| const dirs = flattedOnlyToDirs(githubContents) | ||
| const ancestors = file.path.split('/').slice(0, -1) | ||
|
|
||
| while (ancestors.length > 0) { | ||
| const ancestor = ancestors.join('/') | ||
|
|
||
| if (dirs.some((d) => d.path === ancestor)) { | ||
| expanded.add(ancestor) | ||
| ancestors.pop() | ||
| } else { | ||
| break | ||
| } | ||
| } | ||
|
|
||
| break | ||
| } | ||
| } | ||
| } | ||
| return expanded | ||
| } | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! very well thought!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am amazed by the simplicity and effectiveness of this PR! Thank's for sharing!

No description provided.