Skip to content
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

Google Fonts #525

Merged
merged 5 commits into from
Aug 16, 2024
Merged

Google Fonts #525

merged 5 commits into from
Aug 16, 2024

Conversation

chiragchhatrala
Copy link
Collaborator

@chiragchhatrala chiragchhatrala commented Aug 12, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new Google Font selection component for enhanced font customization.
    • Added a new API endpoint for fetching Google Fonts.
    • Implemented dynamic loading of selected fonts in forms.
    • Enhanced form customization with the ability to select font styles through a user-friendly interface.
  • Enhancements

    • Streamlined Google authentication configurations.
    • Improved form customization options with a new font family property.
    • Enhanced management of font and favicon links for improved readability and maintainability.
  • Bug Fixes

    • Ensured that the font family loading behaves correctly when not specified.

Copy link
Contributor

coderabbitai bot commented Aug 12, 2024

Walkthrough

This update enhances a Laravel application with improved Google Fonts integration. It adds a FontsController for efficient font retrieval and caching, along with a GoogleFontPicker component for an intuitive user experience. Forms now support dynamic styling based on user preferences, complemented by new environment variables and a migration to accommodate these features, promoting a seamless and customizable font experience.

Changes

File Change Summary
.env.example Updated GOOGLE_REDIRECT_URL and added GOOGLE_FONTS_API_KEY.
app/Http/Controllers/FontsController.php New controller for fetching Google Fonts with caching for optimized performance.
client/components/open/editors/GoogleFontPicker.vue New Vue.js component for selecting Google Fonts, featuring search and selection capabilities.
client/components/open/forms/OpenCompleteForm.vue Added getFontUrl method to dynamically load selected Google Fonts.
client/pages/forms/[slug]/index.vue Introduced computed properties for dynamic font and favicon management in the head.
client/components/open/forms/components/form-components/FormCustomization.vue New component for integrating font selection with the GoogleFontPicker.
routes/api.php New GET route for fetching fonts, handled by FontsController.

Poem

🐰 Hop, hop, hooray!
Fonts are here to stay!
With colors bright and styles bold,
A world of fonts to behold!
Choose your flair, let it shine,
In every form, your style divine! 🌈✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (1)
.env.example (1)

86-88: Document new environment variable.

The addition of GOOGLE_FONTS_API_KEY should be documented in the appropriate configuration documentation to inform developers of its purpose and usage.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5d3bea0 and 18ce6c6.

Files selected for processing (11)
  • .env.example (1 hunks)
  • app/Http/Controllers/FontsController.php (1 hunks)
  • app/Http/Requests/UserFormRequest.php (1 hunks)
  • app/Models/Forms/Form.php (2 hunks)
  • client/components/open/editors/GoogleFontPicker.vue (1 hunks)
  • client/components/open/forms/OpenCompleteForm.vue (3 hunks)
  • client/components/open/forms/components/form-components/FormCustomization.vue (3 hunks)
  • client/composables/forms/initForm.js (1 hunks)
  • config/services.php (1 hunks)
  • database/migrations/2024_08_12_091853_add_font_family_to_forms.php (1 hunks)
  • routes/api.php (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/Models/Forms/Form.php
Additional comments not posted (15)
database/migrations/2024_08_12_091853_add_font_family_to_forms.php (2)

13-15: Migration script looks good.

The migration adds a nullable font_family column to the forms table, which is appropriate for the intended functionality. Ensure that this migration is run in the correct environment.


23-25: Ensure safe rollback.

The down method correctly drops the font_family column, allowing for safe rollback of the migration.

app/Http/Controllers/FontsController.php (1)

12-23: Verify caching duration.

The caching duration is set to one hour. Ensure this duration aligns with your application's performance and data freshness requirements.

Verification successful

Caching Duration Verified

The caching duration for the Google Fonts API call is set to one hour, which is consistent with other parts of the application, such as in ChangelogController and SelfHostedCredentialsMiddleware. This suggests a standard practice for caching durations across the application. No changes are needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the caching duration for Google Fonts.

# Test: Check if the caching duration is consistent with other parts of the application.
rg --type php 'Cache::remember' -A 5

Length of output: 2796

.env.example (1)

86-86: Verify Google redirect URL change.

The change in GOOGLE_REDIRECT_URL should be verified to ensure it aligns with any new authentication flow or requirements.

client/composables/forms/initForm.js (1)

12-12: Addition of font_family property is appropriate.

The addition of the font_family property allows for future customization and does not interfere with existing functionality. This is a well-considered enhancement.

config/services.php (1)

74-74: Addition of google_fonts_api_key is consistent with configuration practices.

Adding the google_fonts_api_key to the configuration file aligns with the existing pattern for managing API keys. This is essential for the Google Fonts integration.

client/components/open/editors/GoogleFontPicker.vue (2)

1-83: Template structure is well-organized.

The template is well-structured, using slots effectively for icon and title customization. The use of v-if for loading states and v-for for dynamic font rendering is appropriate.


85-165: Script logic is clear and efficient.

The script setup uses Vue's Composition API effectively. The use of ref, computed, and watch provides a clear and reactive data flow. The integration with external libraries like Fuse.js for search functionality is well-implemented.

app/Http/Requests/UserFormRequest.php (1)

32-32: Validation rule for font_family looks good.

The addition of the font_family validation rule enhances the form's customization capabilities without impacting existing functionality.

client/components/open/forms/components/form-components/FormCustomization.vue (3)

56-70: Integration of font style selection UI looks good.

The addition of the GoogleFontPicker component and related UI elements enhances the form customization options.


212-215: Font application logic in onApplyFont looks good.

The logic for applying the selected font and updating the state is correctly implemented.


192-199: Ensure GoogleFontPicker component is correctly integrated.

The import and usage of GoogleFontPicker should be verified to ensure it is correctly integrated and functioning as expected.

Verification successful

GoogleFontPicker component is correctly integrated.

The GoogleFontPicker component is imported and used within the FormCustomization.vue file. It is displayed conditionally based on the showGoogleFontPicker ref and interacts with the form's font settings through events like @close and @apply. This indicates proper integration and usage.

  • File: client/components/open/forms/components/form-components/FormCustomization.vue
    • The component is imported and used with appropriate bindings and event handlers.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `GoogleFontPicker` component.

# Test: Search for the `GoogleFontPicker` component usage across the codebase. Expect: Correct usage and integration.
rg --type vue 'GoogleFontPicker'

Length of output: 60


Script:

#!/bin/bash
# Description: Verify the integration of `GoogleFontPicker` component.

# Corrected Test: Search for the `GoogleFontPicker` component usage across the codebase, focusing on .vue files.
rg 'GoogleFontPicker' --glob '*.vue' -A 5

Length of output: 2969

client/components/open/forms/OpenCompleteForm.vue (3)

5-10: Dynamic font styling and loading logic looks good.

The use of CSS variables for dynamic font styling and conditional rendering of the font link enhances the form's customization.


345-347: Global font styling with CSS variables looks good.

The use of CSS variables to apply the font family globally within the .open-complete-form component is a clean approach to styling.


260-263: Ensure getFontUrl method is functioning correctly.

The logic for generating the Google Font URL should be verified to ensure it constructs URLs correctly based on the font_family.

Verification successful

The getFontUrl method is functioning correctly. The method is used appropriately in OpenCompleteForm.vue to generate a URL for Google Fonts, aligning with its intended functionality. No issues were found with its usage.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of `getFontUrl` method.

# Test: Search for the `getFontUrl` method usage across the codebase. Expect: Correct usage and functionality.
rg --type vue 'getFontUrl'

Length of output: 54


Script:

#!/bin/bash
# Description: Verify the correctness of `getFontUrl` method.

# Test: Search for the `getFontUrl` method usage across the codebase without specifying a file type.
rg 'getFontUrl'

Length of output: 340

Comment on lines 12 to 23
return \Cache::remember('google_fonts', 60 * 60, function () {
$url = "https://www.googleapis.com/webfonts/v1/webfonts?key=" . config('services.google_fonts_api_key');
$response = Http::get($url);
if ($response->successful()) {
$fonts = collect($response->json()['items'])->map(function ($font) {
return $font['family'];
})->toArray();
return response()->json($fonts);
}

return [];
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling and logging.

The index method caches Google Fonts data and handles successful responses. Consider adding logging for errors or unsuccessful responses to aid in debugging.

if ($response->failed()) {
    \Log::error('Failed to fetch Google Fonts', ['url' => $url]);
    return response()->json(['error' => 'Unable to fetch fonts'], 500);
}

Copy link
Owner

@JhumanJ JhumanJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work - very cool addition to the tool. I've added few comments - thanks

ref="scrollContainer"
class="grid grid-cols-3 gap-2 p-5 mb-5 overflow-y-scroll max-h-[24rem]"
>
<div
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create a dedicated component for the font cards FontCard.
Also, while the fonts load, we can display skeleton to avoid the card height to change once the font is loaded (see https://ui.nuxt.com/components/skeleton)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic to detect if the card is visible and to load the font should probably in FontCard to simplify the code and more readability

$url = "https://www.googleapis.com/webfonts/v1/webfonts?key=" . config('services.google_fonts_api_key');
$response = Http::get($url);
if ($response->successful()) {
$fonts = collect($response->json()['items'])->map(function ($font) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's filter out iconset (they probably have a specific attribute you can use to filter out - either in the api endpoint or in the back-end here)

CleanShot 2024-08-13 at 11 02 51@2x

class="flex-grow"
@click="$emit('apply', selectedFont)"
>
Apply
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure the text is centered for this button

>
<link
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only want to keep this here for adminPreview mode. When not in adminPreview, instead of having this here - ideally we should have this in the <head>. To do this you can use useHead (see this). I think when adminPreview is disabled and we're seeing the live form, we should add the useHead in /forms/slug/index instead. So:

  • Keep this just when adminPreview true (same for the style binding)
  • Add the useHead on the public form page (and add the style binding)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
client/pages/forms/[slug]/index.vue (1)

182-186: Ensure null handling for getFontUrl usage.

The getFontUrl computed property is used in several components without proper null handling. Ensure that the href attribute does not receive a null value, which could lead to unintended behavior.

  • client/pages/forms/[slug]/index.vue: Line where href: getFontUrl.value is used.
  • client/components/open/editors/FontCard.vue: Line where :href="getFontUrl" is used.
  • client/components/open/forms/OpenCompleteForm.vue: Line where :href="getFontUrl" is used.

Consider adding a check or a default value to handle cases where getFontUrl returns null.

Analysis chain

Ensure null handling in getFontUrl.

The computed property getFontUrl correctly constructs the Google Fonts URL. Ensure that the null return value is handled where this property is used.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of `getFontUrl` to ensure null handling.

# Test: Search for `getFontUrl` usage. Expect: Proper null handling in logic.
rg --type vue -A 5 $'getFontUrl'

Length of output: 59


Script:

#!/bin/bash
# Description: Verify usage of `getFontUrl` to ensure null handling.

# Test: Search for `getFontUrl` usage in all files. Expect: Proper null handling in logic.
rg 'getFontUrl' -A 5

Length of output: 2650

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 18ce6c6 and 983e5d2.

Files selected for processing (5)
  • app/Http/Controllers/FontsController.php (1 hunks)
  • client/components/open/editors/FontCard.vue (1 hunks)
  • client/components/open/editors/GoogleFontPicker.vue (1 hunks)
  • client/components/open/forms/OpenCompleteForm.vue (3 hunks)
  • client/pages/forms/[slug]/index.vue (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • app/Http/Controllers/FontsController.php
  • client/components/open/editors/GoogleFontPicker.vue
  • client/components/open/forms/OpenCompleteForm.vue
Additional comments not posted (3)
client/components/open/editors/FontCard.vue (2)

1-33: Template is well-structured.

The template correctly uses props to conditionally render content and emits the select-font event appropriately. The use of Google Fonts via a <link> tag is correctly implemented.


35-59: Script setup is correctly implemented.

Props are defined with appropriate types and defaults. The computed property getFontUrl correctly constructs the Google Fonts URL.

client/pages/forms/[slug]/index.vue (1)

188-212: headLinks computed property is well-structured.

The headLinks computed property correctly constructs link elements for fonts and favicons, enhancing maintainability and readability.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 983e5d2 and 0193909.

Files selected for processing (1)
  • client/components/open/forms/components/form-components/FormCustomization.vue (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • client/components/open/forms/components/form-components/FormCustomization.vue

- Update FontsController to fetch Google fonts sorted by popularity.
- Enhance FontCard component with additional skeleton loaders for better UX during font loading.
- Adjust check icon positioning in FontCard to be absolute for consistent UI.
- Remove unnecessary class in GoogleFontPicker's text input.
- Add border and rounded styling to the font list container in GoogleFontPicker.
- Simplify computed property for enrichedFonts in GoogleFontPicker.
- Implement inline font style preview in FormCustomization component.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0193909 and 0ce9df5.

Files selected for processing (5)
  • app/Http/Controllers/FontsController.php (1 hunks)
  • client/components/open/editors/FontCard.vue (1 hunks)
  • client/components/open/editors/GoogleFontPicker.vue (1 hunks)
  • client/components/open/forms/components/form-components/FormCustomization.vue (3 hunks)
  • routes/api.php (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • app/Http/Controllers/FontsController.php
  • client/components/open/editors/FontCard.vue
  • client/components/open/editors/GoogleFontPicker.vue
  • client/components/open/forms/components/form-components/FormCustomization.vue
  • routes/api.php

@JhumanJ JhumanJ merged commit 1ac71ec into main Aug 16, 2024
5 checks passed
@JhumanJ JhumanJ deleted the 7e8d1-google-fonts branch August 16, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants