-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Feature/star history charts #949
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
Open
DipakHalkude
wants to merge
11
commits into
rahuldkjain:dev
Choose a base branch
from
DipakHalkude:feature/star-history-charts
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
97444be
feat: add star-history charts integration
DipakHalkude 5ad6298
Update src/components/sections/star-history.tsx
DipakHalkude 7e447b3
Update src/components/sections/star-history.tsx
DipakHalkude 7ee840e
Update src/components/sections/star-history.tsx
DipakHalkude 91980b0
Update src/components/sections/star-history.tsx
DipakHalkude b070768
Update src/components/sections/star-history.tsx
DipakHalkude b263899
Update src/components/sections/star-history.tsx
DipakHalkude 46d6d43
Update src/components/sections/star-history.tsx
DipakHalkude dc2f334
Update src/components/sections/star-history.tsx
DipakHalkude 0229328
fix(star-history): resolve theme consistency and UX issues
DipakHalkude 9c23d1b
Merge branch 'feature/star-history-charts' of https://github.com/Dipaβ¦
DipakHalkude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,248 @@ | ||
| 'use client'; | ||
|
|
||
| import { useState, useEffect } from 'react'; | ||
| import { UseFormRegister, UseFormWatch, UseFormSetValue } from 'react-hook-form'; | ||
| import { FormCheckbox } from '@/components/forms/form-checkbox'; | ||
| import { FormInput } from '@/components/forms/form-input'; | ||
| import { CollapsibleSection } from '@/components/ui/collapsible-section'; | ||
| import type { ProfileFormData } from '@/lib/validations'; | ||
| import { generateStarHistoryURL, parseRepos, validateRepos } from '@/lib/star-history'; | ||
|
|
||
| interface StarHistoryProps { | ||
| register: UseFormRegister<ProfileFormData>; | ||
| watch: UseFormWatch<ProfileFormData>; | ||
| setValue: UseFormSetValue<ProfileFormData>; | ||
| } | ||
|
|
||
|
|
||
| export function StarHistory({ register, watch, setValue }: StarHistoryProps) { | ||
| // Add this debug to check form values - use different variable names | ||
DipakHalkude marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const mainEnabled = watch('starHistory'); | ||
| const configData = watch('starHistoryConfig'); | ||
DipakHalkude marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const [reposInput, setReposInput] = useState<string>(''); | ||
| const [previewUrl, setPreviewUrl] = useState<string>(''); | ||
| const [loading, setLoading] = useState<boolean>(false); | ||
| const [errors, setErrors] = useState<string[]>([]); | ||
|
|
||
| // Watch form values | ||
| const starHistoryEnabled = watch('starHistory'); | ||
| const starHistoryConfig = watch('starHistoryConfig'); | ||
| const repos = starHistoryConfig?.repos || []; | ||
| const chartType = starHistoryConfig?.chartType || 'Date'; | ||
| const theme = starHistoryConfig?.theme || 'auto'; | ||
|
|
||
| // Initialize repos input only once when component mounts or repos change from empty | ||
| useEffect(() => { | ||
| // Only set reposInput if it's empty and we have repos | ||
| if (repos.length > 0 && reposInput === '') { | ||
| setReposInput(repos.join(', ')); | ||
| } | ||
| }, [repos]); // Remove reposInput from dependencies | ||
DipakHalkude marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
DipakHalkude marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Update preview when config changes | ||
| useEffect(() => { | ||
| updatePreview(); | ||
| }, [repos, chartType, theme]); | ||
DipakHalkude marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Add this useEffect to sync the states | ||
| useEffect(() => { | ||
| const mainEnabled = watch('starHistory'); | ||
DipakHalkude marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const configEnabled = configData?.enabled; | ||
|
|
||
| console.log('π Step 6 - Syncing states:', { mainEnabled, configEnabled }); | ||
|
|
||
| // If they're out of sync, fix it | ||
| if (mainEnabled !== configEnabled) { | ||
| console.log('π Fixing sync issue'); | ||
DipakHalkude marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| setValue('starHistoryConfig.enabled', mainEnabled, { shouldValidate: true }); | ||
| } | ||
| }, [watch('starHistory'), configData?.enabled, setValue]); | ||
|
|
||
DipakHalkude marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const updatePreview = async () => { | ||
| if (!starHistoryEnabled || repos.length === 0) { | ||
| setPreviewUrl(''); | ||
| return; | ||
| } | ||
|
|
||
| setLoading(true); | ||
| try { | ||
| const effectiveTheme = theme === 'auto' ? 'light' : theme; | ||
| const url = generateStarHistoryURL({ | ||
| repos: repos, | ||
| type: chartType, | ||
| theme: effectiveTheme as 'light' | 'dark' | ||
| }); | ||
| setPreviewUrl(url); | ||
| } catch (error) { | ||
| console.error('Error generating preview:', error); | ||
| setErrors(['Failed to generate preview']); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| const handleReposChange = (value: string) => { | ||
| setReposInput(value); | ||
|
|
||
| // Parse repositories | ||
| const parsedRepos = parseRepos(value); | ||
|
|
||
| // Validate | ||
| const validation = validateRepos(parsedRepos); | ||
| setErrors(validation.errors); | ||
|
|
||
| if (validation.valid) { | ||
| setValue('starHistoryConfig.repos', parsedRepos, { shouldValidate: true }); | ||
| } | ||
| else{ | ||
DipakHalkude marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Clear repos if invalid | ||
| setValue('starHistoryConfig.repos', [], { shouldValidate: true }); | ||
| } | ||
| }; | ||
|
|
||
| const handleChartTypeChange = (type: 'Date' | 'Timeline') => { | ||
| setValue('starHistoryConfig.chartType', type, { shouldValidate: true }); | ||
| }; | ||
|
|
||
| const handleThemeChange = (theme: 'light' | 'dark' | 'auto') => { | ||
| setValue('starHistoryConfig.theme', theme, { shouldValidate: true }); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="border-border mt-6 border-t pt-6"> | ||
| <div className={`rounded-lg p-4 transition-all ${starHistoryEnabled ? 'bg-accent/50' : 'bg-muted/30'}`}> | ||
| <h4 className="mb-2 flex items-center gap-2 text-sm font-semibold"> | ||
| <span>β</span> | ||
| <span>Star History Charts</span> | ||
| </h4> | ||
|
|
||
| <FormCheckbox | ||
| {...register('starHistory')} | ||
| id="starHistory" | ||
| label="Show Star History chart on profile" | ||
| /> | ||
|
|
||
| {starHistoryEnabled && ( | ||
| <div className="mt-4 space-y-4"> | ||
| {/* Repositories Input */} | ||
| <div> | ||
| <label className="block text-sm font-medium mb-2"> | ||
| Repositories (comma-separated): | ||
| </label> | ||
| <FormInput | ||
| id="starHistoryRepos" | ||
| value={reposInput} | ||
| onChange={(e) => handleReposChange(e.target.value)} | ||
| placeholder="facebook/react, vuejs/vue, microsoft/vscode" | ||
| helperText="π‘ Enter repositories in 'owner/repo' format. Example: facebook/react, vuejs/vue" | ||
| /> | ||
| {errors.length > 0 && ( | ||
| <div className="text-red-500 text-xs mt-2 space-y-1"> | ||
| {errors.map((error, index) => ( | ||
| <div key={index}>β’ {error}</div> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
| {/* Chart Type */} | ||
| <div> | ||
| <label className="block text-sm font-medium mb-2">Chart Type:</label> | ||
| <div className="flex flex-wrap gap-4"> | ||
| <label className="flex items-center"> | ||
| <input | ||
| type="radio" | ||
| name="chartType" | ||
| value="Date" | ||
| checked={chartType === 'Date'} | ||
| onChange={() => handleChartTypeChange('Date')} | ||
| className="mr-2" | ||
| /> | ||
| Date | ||
| </label> | ||
| <label className="flex items-center"> | ||
| <input | ||
| type="radio" | ||
| name="chartType" | ||
| value="Timeline" | ||
| checked={chartType === 'Timeline'} | ||
| onChange={() => handleChartTypeChange('Timeline')} | ||
| className="mr-2" | ||
| /> | ||
| Timeline | ||
| </label> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Theme */} | ||
| <div> | ||
| <label className="block text-sm font-medium mb-2">Theme:</label> | ||
| <div className="flex flex-wrap gap-4"> | ||
| <label className="flex items-center"> | ||
| <input | ||
| type="radio" | ||
| name="theme" | ||
| value="light" | ||
| checked={theme === 'light'} | ||
| onChange={() => handleThemeChange('light')} | ||
| className="mr-2" | ||
| /> | ||
| Light | ||
| </label> | ||
| <label className="flex items-center"> | ||
| <input | ||
| type="radio" | ||
| name="theme" | ||
| value="dark" | ||
| checked={theme === 'dark'} | ||
| onChange={() => handleThemeChange('dark')} | ||
| className="mr-2" | ||
| /> | ||
| Dark | ||
| </label> | ||
| <label className="flex items-center"> | ||
| <input | ||
| type="radio" | ||
| name="theme" | ||
| value="auto" | ||
| checked={theme === 'auto'} | ||
| onChange={() => handleThemeChange('auto')} | ||
| className="mr-2" | ||
| /> | ||
| Auto (match profile) | ||
| </label> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Preview */} | ||
| <div> | ||
| <label className="block text-sm font-medium mb-2">Preview:</label> | ||
| <div className="border rounded p-4 bg-gray-50 dark:bg-gray-900 min-h-[200px] flex items-center justify-center"> | ||
| {loading ? ( | ||
| <div className="text-gray-500">Loading preview...</div> | ||
| ) : previewUrl ? ( | ||
| <img | ||
| src={previewUrl} | ||
| alt="Star History Preview" | ||
| className="max-w-full h-auto" | ||
| onError={() => setErrors(['Failed to load preview. Check repository names.'])} | ||
| /> | ||
| ) : ( | ||
| <div className="text-gray-500">Enter repositories to see preview</div> | ||
| )} | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Help Text */} | ||
| <div className="bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded p-3"> | ||
| <p className="text-blue-800 dark:text-blue-300 text-sm"> | ||
| <strong>Tip:</strong> The Star History chart shows the growth of GitHub stars over time. | ||
| Perfect for showcasing project popularity and growth trends. | ||
| </p> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.