Skip to content

Commit

Permalink
Merge pull request #10842 from Blkandwhtgaming/feature/wishlist-refresh
Browse files Browse the repository at this point in the history
Feature/wishlist refresh
  • Loading branch information
bhollis authored Dec 14, 2024
2 parents 7eec723 + bb23182 commit 3b04bf5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
5 changes: 4 additions & 1 deletion config/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,9 @@
"SpacesSize": "{{count}} space",
"SpacesSize_plural": "{{count}} spaces",
"Theme": "Theme",
"VaultGroupingNone": "None"
"VaultGroupingNone": "None",
"WishlistRefreshNotificationBody": "If you do not see any updates, be sure the source (such as GitHub) reflects them!",
"WishlistRefreshNotificationTitle": "Wishlists Reloaded"
},
"Sockets": {
"ApplyPerks": "Apply Perks",
Expand Down Expand Up @@ -1510,6 +1512,7 @@
"Num": "{{num, number}} rolls in your wish list",
"NumRolls": "{{num, number}} rolls",
"PreMadeFiles": "Use A Pre-Made Wish List",
"Refresh": "Refresh Wishlist",
"SourceAlreadyAdded": "Wish List already added",
"UpdateExternalSource": "Add Wish List",
"Untitled": "Untitled Wish List",
Expand Down
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

* Added a wishlist refresh button in Settings to help with wishlist development. Note that GitHub can take upwards of 10min to actually reflect your changes. Refreshing won't speed up GitHub.

## 8.50.1 <span class="changelog-date">(2024-12-12)</span>

* Notes now appear in the tooltips on item tiles.
Expand Down
21 changes: 18 additions & 3 deletions src/app/settings/WishListSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ConfirmButton } from 'app/dim-ui/ConfirmButton';
import { PressTip } from 'app/dim-ui/PressTip';
import { I18nKey, t } from 'app/i18next-t';
import { showNotification } from 'app/notifications/notifications';
import { AppIcon, banIcon, deleteIcon, plusIcon } from 'app/shell/icons';
import { AppIcon, banIcon, deleteIcon, plusIcon, refreshIcon } from 'app/shell/icons';
import { wishListGuideLink } from 'app/shell/links';
import { useThunkDispatch } from 'app/store/thunk-dispatch';
import { errorMessage } from 'app/utils/errors';
Expand Down Expand Up @@ -36,9 +36,12 @@ export default function WishListSettings() {
? settingsWishListSource.split('|').map((url) => url.trim())
: [];

const reloadWishList = async (reloadWishListSource: string | undefined) => {
const reloadWishList = async (
reloadWishListSource: string | undefined,
manualRefresh?: boolean | false,
) => {
try {
await dispatch(fetchWishList(reloadWishListSource));
await dispatch(fetchWishList(reloadWishListSource, manualRefresh));
} catch (e) {
showNotification({
type: 'error',
Expand Down Expand Up @@ -82,6 +85,15 @@ export default function WishListSettings() {
reloadWishList(newUrls.join('|'));
};

const handleReloadWishlists = () => {
reloadWishList(activeWishlistUrls.join('|'), true);
showNotification({
type: 'warning',
title: t('Settings.WishlistRefreshNotificationTitle'),
body: t('Settings.WishlistRefreshNotificationBody'),
});
};

const addUrlDisabled = (url: string) => {
const urls = validateWishListURLs(url);
if (!urls.length) {
Expand Down Expand Up @@ -116,6 +128,9 @@ export default function WishListSettings() {
<button type="button" className="dim-button" onClick={clearWishListEvent}>
<AppIcon icon={banIcon} /> {t('WishListRoll.Clear')}
</button>
<button type="button" className="dim-button" onClick={handleReloadWishlists}>
<AppIcon icon={refreshIcon} /> {t('WishListRoll.Refresh')}
</button>
</div>
{wishListLastUpdated && (
<div className={fineprintClass}>
Expand Down
7 changes: 4 additions & 3 deletions src/app/wishlists/wishlist-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function hoursAgo(dateToCheck?: Date): number {
* this performs both the initial fetch (after setting a new wishlist) (when arg0 exists)
* and subsequent fetches (checking for updates) (arg-less)
*/
export function fetchWishList(newWishlistSource?: string): ThunkResult {
export function fetchWishList(newWishlistSource?: string, manualRefresh?: boolean): ThunkResult {
return async (dispatch, getState) => {
await dispatch(loadWishListAndInfoFromIndexedDB());
await settingsReady;
Expand Down Expand Up @@ -107,16 +107,17 @@ export function fetchWishList(newWishlistSource?: string): ThunkResult {

// Only update if the length changed. The wish list may actually be different - we don't do a deep check -
// but this is good enough to avoid re-doing the work over and over.
// If the user manually refreshed, do the work anyway
if (
loadedWishListRolls?.length !== wishListAndInfo.wishListRolls.length ||
wishListURLsChanged
wishListURLsChanged ||
manualRefresh
) {
await dispatch(transformAndStoreWishList(wishListAndInfo));
} else {
infoLog(TAG, 'Refreshed wishlist, but it matched the one we already have');
dispatch(touchWishLists());
}
await dispatch(transformAndStoreWishList(wishListAndInfo));
};
}

Expand Down
5 changes: 4 additions & 1 deletion src/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,9 @@
"Theme": "Theme",
"VaultArmorGroupingStyle": "Separate armor on different lines by class",
"VaultGroupingNone": "None",
"VaultWeaponGroupingStyle": "Separate weapon groups on different lines"
"VaultWeaponGroupingStyle": "Separate weapon groups on different lines",
"WishlistRefreshNotificationBody": "If you do not see any updates, be sure the source (such as GitHub) reflects them!",
"WishlistRefreshNotificationTitle": "Wishlists Reloaded"
},
"Sockets": {
"ApplyPerks": "Apply Perks",
Expand Down Expand Up @@ -1493,6 +1495,7 @@
"LastUpdated": "Last updated: {{lastUpdatedDate}} at {{lastUpdatedTime}}",
"Num": "{{num, number}} rolls in your wish list",
"NumRolls": "{{num, number}} rolls",
"Refresh": "Refresh Wishlist",
"SourceAlreadyAdded": "Wish List already added",
"UpdateExternalSource": "Add Wish List",
"Voltron": "voltron (default)",
Expand Down

0 comments on commit 3b04bf5

Please sign in to comment.