Skip to content

Rename button "download torrent" to "download private torrent" when the tracker is in close mode#487

Merged
josecelano merged 5 commits intotorrust:developfrom
josecelano:486-rename-button-download-torrent-to-download-private-torrent-when-the-tracker-is-in-close-mode
Feb 27, 2024
Merged

Rename button "download torrent" to "download private torrent" when the tracker is in close mode#487
josecelano merged 5 commits intotorrust:developfrom
josecelano:486-rename-button-download-torrent-to-download-private-torrent-when-the-tracker-is-in-close-mode

Conversation

@josecelano
Copy link
Copy Markdown
Member

@josecelano josecelano commented Feb 27, 2024

  • Fix bug. The button was always shown even when the tracker was private and the user was not logged in.
  • Fix bug. The function to detect tracker mode was not working.
  • Rename the button for private trackers.
  • Improve error message when tasks in the database for users fail.

even when it has to be hidden. For example, when the tracker is private
and the user is not logged in.
@josecelano josecelano self-assigned this Feb 27, 2024
@josecelano josecelano added Enhancement / Feature Request Something New - User - Enjoyable to Use our Software Bug Incorrect Behavior labels Feb 27, 2024
@josecelano josecelano added this to the v3.0.0 milestone Feb 27, 2024
@josecelano
Copy link
Copy Markdown
Member Author

There was a bug. The button to download torrents should be hidden when the tracker is private and the user is not logged in.

image

Tracker modes can be:

```typescript
export declare enum TrackerMode {
    Public = 0,
    Private = 1,
    Whitelisted = 2,
    PrivateWhitelisted = 3
}
```

We also call a public tracker to the subset: `Public` and `Whitelisted`.

This refactor uses "open" and "close" for:

- Open: `Public` or `Whitelisted`
- Close: `Private` or `PrivateWhitelisted`

See: torrust/torrust-tracker#717
when the user is not logged in and the tracker is private.
The type TrackerMode was being used but the API wrapper returns a
string: `Public`, `Private`, ...

It was not detecting the rigth tracker mode.

todo: change the `useSettings` function to return typed value if we want
to compare to another type (TrackerMode).
@josecelano josecelano requested a review from mario-nt February 27, 2024 14:36
@josecelano josecelano marked this pull request as ready for review February 27, 2024 14:36
@josecelano
Copy link
Copy Markdown
Member Author

There was also a bug in this function:

export function isTrackerPublic (): boolean {
  const settings = useSettings();

  return settings.value.tracker_mode === TrackerMode.Public ||
        settings.value.tracker_mode === TrackerMode.Whitelisted;
}

export function isUserLoggedIn (): boolean {
  return !!useUser().value?.username;
}

It was not working because settings.value.tracker_mode is an string from the JSON response. It's not the type TrackerMode.

The temporary patch is:

export function isTrackerOpen (): boolean {
  const settings = useSettings();

  // todo: we are not using the type TrackerMode in
  // settings.value.tracker_mode

  return settings.value.tracker_mode === "Public" ||
        settings.value.tracker_mode === "Whitelisted";
}

We could change the useSettings function to return the types instead of the raw JSON objects from the API calls.

@josecelano
Copy link
Copy Markdown
Member Author

ACK 385b695

@josecelano josecelano merged commit 84fa730 into torrust:develop Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

- User - Enjoyable to Use our Software Bug Incorrect Behavior Enhancement / Feature Request Something New

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rename button "download torrent" to "download private torrent" when the tracker is in close mode

1 participant