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

[front] feat: Add a tab for "good short videos" #1825

Merged
merged 4 commits into from
Nov 6, 2023

Conversation

sigmike
Copy link
Collaborator

@sigmike sigmike commented Nov 1, 2023

Related issue #1786


Description

I added the new tab for "good short videos".

I increased the width of the dialog to make all the tabs visible without horizontal scrolling.

image

image

Checklist

  • I added the related issue(s) id in the related issues section (if any)
  • I described my changes and my decisions in the PR description
  • I read the development guidelines of the [CONTRIBUTING.md][development-guidelines]
  • The tests pass and have been updated if relevant
  • The code quality check pass

Copy link
Collaborator

@GresilleSiffle GresilleSiffle left a comment

Choose a reason for hiding this comment

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

Hello @sigmike

It works well 👌

I made few suggestions, mainly to improve how the user's preferences are retrieved.

Comment on lines 161 to 168
{
name: 'good-short-videos',
label: t('entitySelector.goodShortVideos'),
fetch: async () => {
return await getGoodShortVideos();
},
disabled: !isLoggedIn,
},
Copy link
Collaborator

@GresilleSiffle GresilleSiffle Nov 2, 2023

Choose a reason for hiding this comment

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

(a) I think we can reduce even more the name of the tab (just a personal opinion).

Instead of good short videos, we can display only "short videos" (or even "short vid." and "vid. courtes"). The main goal of this tab is to display short videos, and as long as we don't have a "bad short videos" I think we can safely keep the "good" aspect implicit.

(b) There is a description for each tab, defined in the component TabInfo of the file EntityTabsBox. This description is displayed to new users (users having a low number of comparisons).

We should also add a description to this tab, it could be something like "A random sample of short videos recommended by the community."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(a) Done in 37745a2. The dialog still required an increased width to avoid the horizontal scrolling on the tab names.

(b) Done in 42d71c2

};

export const getGoodShortVideos = async (): Promise<Recommendation[]> => {
const languages = initRecommendationsLanguages();
Copy link
Collaborator

@GresilleSiffle GresilleSiffle Nov 2, 2023

Choose a reason for hiding this comment

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

I think this is the old way to retrieve the languages.

It's useful in the preferences form to initialize the languages when the user hasn't explicitly configured anything, but for logged users it shouldn't be used alone elsewhere in the application. It should be a fallback used when the preferred languages are undefined.

Even if it currently works, I'd suggest to use the primary source of truth first, and fallback to the local storage in case of need.

We can use something like this (I didn't test):

// this code goes in the component VideoInput
const userSettings = useSelector(selectSettings).settings;
const preferredLanguages =
  userSettings?.[pollName as PollUserSettingsKeys]
    ?.recommendations__default_languages;

// preferredLanguages can be passed as a parameter to the function getGoodShortVideos
let languages = preferredLanguages?.join(',') ?? null;

if (languages == null) {
  languages = initRecommendationsLanguages();
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in 487c1b3.

I wonder if usePreferredLanguages should get the poll name itself. I think it's good to make it explicit that it depends on the poll, but adding a parameter for that is probably not the best solution. Maybe it should be in the name instead (usePreferredLanguagesFromCurrentPoll for example).

But it brings up another comment: useCurrentPoll is widely used but it does some calculations that are a bit wasteful to repeat. Its return value could be memoized with just the poll as a dependency, but we need to be sure that this value is not muted. Or we could have a useCurrentPollName which doesn't do any calculations, since useCurrentPoll is often used just for the name (25 times out of the 78 uses of useCurrentPoll).

All this is very minor and can be done later though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you very much.

About usePreferredLanguages vs usePreferredLanguagesFromCurrentPoll, I don't have a strong preference. I think we can keep usePreferredLanguages for now, and refactor it if we optimize useCurrentPoll.

Regarding useCurrentPoll you are right, it could be good in theory to optimize it, but I'm not sure I understood correctly the risk of poll being muted, and the potential complexity added because of this. Can we talk about it on Discord or during our next meeting?

@GresilleSiffle GresilleSiffle added the Frontend Front-end code of Tournesol label Nov 2, 2023
@GresilleSiffle GresilleSiffle merged commit 1bae766 into main Nov 6, 2023
6 checks passed
@GresilleSiffle GresilleSiffle deleted the good-short-videos-tab branch November 6, 2023 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frontend Front-end code of Tournesol
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants