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

[Refactor] Profile page | Implement the new design for visited sites tab #3582

Conversation

CREDO23
Copy link
Contributor

@CREDO23 CREDO23 commented Feb 3, 2025

Description

Closes #3579

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Current screenshots

Screenshot 2025-02-03 at 22 16 47 Screenshot 2025-02-03 at 22 17 03

Summary by CodeRabbit

  • New Features
    • Refreshed the visited sites activity view with a modern layout featuring rounded elements, gradient backgrounds, and consistent two-digit time formatting for enhanced readability.
  • Localization
    • Expanded language support by adding clear labels and messages for visited sites across multiple languages, improving the user experience for a diverse audience.

@CREDO23 CREDO23 added enhancement New feature or request UI/UX WEB Web app Ever Teams labels Feb 3, 2025
@CREDO23 CREDO23 self-assigned this Feb 3, 2025
Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/web/app/helpers/date.ts

Oops! Something went wrong! :(

ESLint: 8.46.0

ESLint couldn't find the config "next/core-web-vitals" to extend from. Please check that the name of the config is correct.

The config "next/core-web-vitals" was referenced from the config file in "/apps/web/.eslintrc.json".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

apps/web/lib/features/activity/apps.tsx

Oops! Something went wrong! :(

ESLint: 8.46.0

ESLint couldn't find the config "next/core-web-vitals" to extend from. Please check that the name of the config is correct.

The config "next/core-web-vitals" was referenced from the config file in "/apps/web/.eslintrc.json".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

apps/web/lib/features/activity/components/visited-Item.tsx

Oops! Something went wrong! :(

ESLint: 8.46.0

ESLint couldn't find the config "next/core-web-vitals" to extend from. Please check that the name of the config is correct.

The config "next/core-web-vitals" was referenced from the config file in "/apps/web/.eslintrc.json".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

  • 2 others

Walkthrough

This pull request makes several minor formatting and implementation adjustments in the date helper functions and updates the visited site components. Changes include updating function signatures and return values, renaming components (e.g., from AppVisitedItem to VisitedItem), and reworking the VisitedSitesTab layout and data handling. New localization keys for visited sites are also added across multiple language files.

Changes

File(s) Change Summary
apps/web/app/helpers/date.ts Formatting adjustments, semicolon additions, and updating the return type of differenceBetweenHours from 0 to undefined.
apps/web/lib/features/activity/apps.tsx Replaced components: AppVisitedSkeletonVisitedItemSkeleton and AppVisitedItemVisitedItem.
apps/web/lib/features/activity/components/visited-Item.tsx
apps/web/lib/features/activity/components/visited-item-skeleton.tsx
Renamed components from AppVisitedItem/AppVisitedSkeleton to VisitedItem/VisitedItemSkeleton, with added two-digit time formatting.
apps/web/lib/features/activity/visited-sites.tsx Converted memoized VisitedSitesTab to a standard function; changed hook parameter from "URL" to "SITE"; updated layout and skeleton state handling.
apps/web/locales/*.{json} Added new keys "VISITED_SITES" and "NO_VISITED_SITE_MESSAGE" in each localization file to support visited sites.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant V as VisitedSitesTab
  participant H as useTimeDailyActivity
  participant VI as VisitedItem
  participant VS as VisitedItemSkeleton

  U->>V: Request visited sites
  V->>H: Fetch sites with parameter "SITE"
  H-->>V: Return visited sites (or empty array)
  alt Sites available
    V->>VI: Render each visited site
  else No sites
    V->>VS: Render skeleton loading state
  end
Loading

Possibly related issues

Possibly related PRs

Suggested labels

Improvement

Suggested reviewers

  • evereq
  • Cedric921

Poem

I'm a rabbit, hopping with delight,
Across neat changes day and night,
From dates to tabs and keys set free,
New names and formats dance in glee,
Each line a hop, each fix a playful cheer,
In code gardens where bugs disappear,
Hop on, dear changes—time to reappear!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@CREDO23 CREDO23 requested review from evereq and Cedric921 February 3, 2025 20:32
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: 1

🔭 Outside diff range comments (2)
apps/web/app/helpers/date.ts (2)

72-79: Return undefined instead of 0 for invalid dates.

The function documentation states it should return undefined for invalid dates, but it returns 0. This should be fixed to match the documentation.

export function differenceBetweenHours(startedAt: Date, stoppedAt: Date): number {
  const started = new Date(startedAt);
  const stopped = new Date(stoppedAt);
  if (!isNaN(started.getTime()) && !isNaN(stopped.getTime())) {
    return (stopped.getTime() - started.getTime()) / 1000;
  }
-  return 0;
+  return undefined;
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 75-75: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)


[error] 75-75: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)


92-99: Add error handling for date parsing.

The formatTimeFromDate function should handle invalid date strings gracefully.

export const formatTimeFromDate = (date: string | Date | undefined) => {
  if (!date) return '';
  const dateObject = date instanceof Date ? date : new Date(date);
+  if (isNaN(dateObject.getTime())) {
+    return '';
+  }
  const hours = dateObject.getHours().toString().padStart(2, '0');
  const minutes = dateObject.getMinutes().toString().padStart(2, '0');

  return `${hours}:${minutes}`;
};
🧹 Nitpick comments (4)
apps/web/lib/features/activity/components/visited-Item.tsx (2)

52-55: Consider extracting time formatting logic to a utility function.

The time formatting logic could be moved to a separate utility function to improve reusability and maintainability.

+// In a new file: utils/formatTime.ts
+export const formatTimeDisplay = (h: number, m: number, s: number): string => {
+  return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`;
+};

// In visited-Item.tsx
-<p style={{ flexBasis: itemCellsWidth['time-spent-in-hours'] }} className="">
-  {`${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`}
-</p>
+<p style={{ flexBasis: itemCellsWidth['time-spent-in-hours'] }} className="">
+  {formatTimeDisplay(h, m, s)}
+</p>

19-27: Consider moving itemCellsWidth outside component.

The itemCellsWidth object could be defined outside the component since it doesn't depend on any props or state. This would prevent unnecessary recreations on each render.

+const ITEM_CELLS_WIDTH = {
+  apps: '20%',
+  'visited-dates': '25%',
+  'percent-used': '40%',
+  'time-spent-in-hours': '15%'
+} as const;

const VisitedItem = ({ app, totalMilliseconds, type }: Props) => {
-  const itemCellsWidth = useMemo(
-    () => ({
-      apps: '20%',
-      'visited-dates': '25%',
-      'percent-used': '40%',
-      'time-spent-in-hours': '15%'
-    }),
-    []
-  );
+  const itemCellsWidth = ITEM_CELLS_WIDTH;
apps/web/lib/features/activity/visited-sites.tsx (2)

14-34: Consider moving headers outside component.

The headers array could be defined outside the component and memoized with only the translation function as a dependency.

+const getHeaders = (t: TranslationHooks) => [
+  {
+    title: t('timer.VISITED_SITES'),
+    width: '20%'
+  },
+  {
+    title: t('timer.VISITED_DATES'),
+    width: '25%'
+  },
+  {
+    title: t('timer.PERCENT_USED'),
+    width: '40%'
+  },
+  {
+    title: t('timer.TIME_SPENT_IN_HOURS'),
+    width: '15%'
+  }
+];

export function VisitedSitesTab() {
  const { visitedSites, loading } = useTimeDailyActivity('SITE');
  const t = useTranslations();
  const sites = groupAppsByHour(visitedSites ?? []);
-  const headers = useMemo(
-    () => [
-      {
-        title: t('timer.VISITED_SITES'),
-        width: '20%'
-      },
-      // ... other headers
-    ],
-    [t]
-  );
+  const headers = useMemo(() => getHeaders(t), [t]);

71-76: Loading state could be more specific.

The loading state check could be simplified and made more specific to avoid potential race conditions.

-{loading && visitedSites?.length < 1 && (
+{loading && (
  <>
    <VisitedItemSkeleton />
    <VisitedItemSkeleton />
  </>
)}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f109f1 and 2b8cd5f.

📒 Files selected for processing (18)
  • apps/web/app/helpers/date.ts (5 hunks)
  • apps/web/lib/features/activity/apps.tsx (3 hunks)
  • apps/web/lib/features/activity/components/visited-Item.tsx (2 hunks)
  • apps/web/lib/features/activity/components/visited-item-skeleton.tsx (1 hunks)
  • apps/web/lib/features/activity/visited-sites.tsx (1 hunks)
  • apps/web/locales/ar.json (1 hunks)
  • apps/web/locales/bg.json (1 hunks)
  • apps/web/locales/de.json (1 hunks)
  • apps/web/locales/en.json (1 hunks)
  • apps/web/locales/es.json (1 hunks)
  • apps/web/locales/fr.json (1 hunks)
  • apps/web/locales/he.json (1 hunks)
  • apps/web/locales/it.json (1 hunks)
  • apps/web/locales/nl.json (1 hunks)
  • apps/web/locales/pl.json (1 hunks)
  • apps/web/locales/pt.json (1 hunks)
  • apps/web/locales/ru.json (1 hunks)
  • apps/web/locales/zh.json (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • apps/web/lib/features/activity/components/visited-item-skeleton.tsx
  • apps/web/lib/features/activity/apps.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: deploy
🔇 Additional comments (14)
apps/web/lib/features/activity/components/visited-Item.tsx (1)

7-15: LGTM! Component props are well-typed and documented.

The interface definition is clear and the props are properly typed with meaningful names.

apps/web/locales/zh.json (1)

716-717: LGTM! Translations are properly added.

The new translations for visited sites are consistent with the feature requirements and other language files.

apps/web/locales/he.json (1)

716-717: Ensure Proper Localization in Hebrew:
The new keys "VISITED_SITES": "אתרים שביקרת בהם" and "NO_VISITED_SITE_MESSAGE": "אין אתרים שביקרת בהם" have been added in the "timer" section as intended for the visited sites feature. The translations appear accurate and consistent in tone with other keys in the file.

apps/web/locales/ar.json (1)

716-717: Verify Arabic Translation Consistency:
The additions "VISITED_SITES": "المواقع التي تمت زيارتها" and "NO_VISITED_SITE_MESSAGE": "لا يوجد مواقع تمت زيارتها" in the "timer" section are correctly implemented and provide necessary labels for displaying visited sites. Please ensure that these translations align with your overall Arabic localization standards and the new design’s terminology.

apps/web/locales/en.json (1)

717-718: Confirm English Labels for Visited Sites:
The keys "VISITED_SITES": "Visited sites" and "NO_VISITED_SITE_MESSAGE": "There are no visited sites" have been added in the "timer" section, clearly reflecting the new functionality. Ensure that these labels are integrated correctly within the UI components for the visited sites tab.

apps/web/locales/nl.json (1)

716-717: Dutch Localization for Visited Sites Added

The new keys "VISITED_SITES": "Bezochte sites" and "NO_VISITED_SITE_MESSAGE": "Er zijn geen bezochte sites" have been added to the timer section. They appear to be correctly localized for Dutch. Please ensure that the corresponding application code uses these keys consistently for rendering the visited sites tab.

apps/web/locales/bg.json (1)

715-717: Bulgarian Localization for Visited Sites Added

The keys "VISITED_SITES": "Посетени сайтове" and "NO_VISITED_SITE_MESSAGE": "Няма посетени сайтове" have been included. The translations accurately reflect the intended messages for Bulgarian users. Confirm that these keys are integrated with the visited sites component in the UI.

apps/web/locales/pl.json (1)

716-718: Polish Localization for Visited Sites Added

The additions of "VISITED_SITES": "Odwiedzone strony" and "NO_VISITED_SITE_MESSAGE": "Brak odwiedzonych stron" are consistent with similar changes in other languages. Please verify that the new keys are referenced properly within the visited sites tab implementation.

apps/web/locales/it.json (1)

715-717: New Localization Keys Added for Visited Sites

The addition of "VISITED_SITES": "Siti visitati" and "NO_VISITED_SITE_MESSAGE": "Non ci sono siti visitati" is clear and consistent with the new design requirements for the visited sites tab. Ensure these values are aligned with the UI design and match the terminology used in other language files.

apps/web/locales/ru.json (1)

715-717: New Localization Keys Added for Visited Sites

The new keys "VISITED_SITES": "Посещенные сайты" and "NO_VISITED_SITE_MESSAGE": "Нет посещенных сайтов" have been added correctly in the "timer" section. They are consistent with the overall localization strategy for the visited sites tab.

apps/web/locales/pt.json (1)

715-717: New Localization Keys Added for Visited Sites

The additions of "VISITED_SITES": "Sites visitados" and "NO_VISITED_SITE_MESSAGE": "Não há sites visitados" appropriately extend the timer’s localization. Their inclusion provides the necessary text for indicating visited sites and handling empty states.

apps/web/locales/es.json (1)

716-717: New Localization Keys Added for Visited Sites

The keys "VISITED_SITES": "Sitios visitados" and "NO_VISITED_SITE_MESSAGE": "No hay sitios visitados" have been added within the "timer" section. They follow the expected naming conventions and are consistent with similar entries in other locale files. Please ensure that these translations align with design and product terminology across the application.

apps/web/locales/de.json (1)

716-717: New Localization Entries Added for Visited Sites

The additions "VISITED_SITES": "Besuchte Seiten" and "NO_VISITED_SITE_MESSAGE": "Es gibt keine besuchten Seiten" in the "timer" object correctly extend the localization support. The German translations are accurate and consistent with similar updates in other files. It is recommended to verify that the capitalization and phrasing match any existing style guidelines for your project.

apps/web/locales/fr.json (1)

715-716: Addition of Visited Sites Localization Keys

The new keys "VISITED_SITES": "Sites visités" and "NO_VISITED_SITE_MESSAGE": "Il n'y a pas de sites visités" have been integrated into the "timer" section. These entries maintain consistency with the multilingual update across the project and appear correct. Please double-check that the terminology aligns with the overall product language guidelines.

@evereq evereq merged commit df7689f into develop Feb 3, 2025
13 checks passed
@evereq evereq deleted the 3579-improvement-profile-page-implement-the-new-design-for-the-visited-site-tab branch February 3, 2025 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Ever Teams UI/UX WEB Web app
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Improvement] Profile page | Implement the new design for the visited site tab
2 participants