forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release_23.1' into dev
- Loading branch information
Showing
19 changed files
with
310 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,92 @@ | ||
import { defineStore } from "pinia"; | ||
import { computed, ref, set } from "vue"; | ||
import Vue, { computed, ref } from "vue"; | ||
|
||
import { fetchAllBroadcasts } from "@/api/notifications.broadcast"; | ||
import type { components } from "@/api/schema"; | ||
import { useUserLocalStorage } from "@/composables/userLocalStorage"; | ||
import type { components } from "@/schema"; | ||
import { loadBroadcastsFromServer } from "@/stores/services/broadcasts.service"; | ||
import { mergeObjectListsById } from "@/utils/utils"; | ||
|
||
export type BroadcastNotification = components["schemas"]["BroadcastNotificationResponse"]; | ||
type Expirable = Pick<BroadcastNotification, "expiration_time">; | ||
|
||
export const useBroadcastsStore = defineStore("broadcastsStore", () => { | ||
const broadcasts = ref<BroadcastNotification[]>([]); | ||
export const useBroadcastsStore = defineStore( | ||
"broadcastsStore", | ||
() => { | ||
const broadcasts = ref<BroadcastNotification[]>([]); | ||
|
||
const loadingBroadcasts = ref<boolean>(false); | ||
const dismissedBroadcasts = useUserLocalStorage<{ [key: string]: Expirable }>("dismissed-broadcasts", {}); | ||
const loadingBroadcasts = ref<boolean>(false); | ||
const dismissedBroadcasts = ref<{ [key: string]: Expirable }>({}); | ||
|
||
const activeBroadcasts = computed(() => { | ||
return broadcasts.value.filter((b) => !dismissedBroadcasts.value[b.id]); | ||
}); | ||
const activeBroadcasts = computed(() => { | ||
return broadcasts.value.filter(isActive); | ||
}); | ||
|
||
async function loadBroadcasts() { | ||
loadingBroadcasts.value = true; | ||
await fetchAllBroadcasts() | ||
.then((data) => { | ||
broadcasts.value = mergeObjectListsById(data, [], "create_time", "desc"); | ||
}) | ||
.finally(() => { | ||
loadingBroadcasts.value = false; | ||
}); | ||
} | ||
async function loadBroadcasts() { | ||
loadingBroadcasts.value = true; | ||
await loadBroadcastsFromServer() | ||
.then((data) => { | ||
broadcasts.value = mergeObjectListsById(data, [], "create_time", "desc"); | ||
}) | ||
.finally(() => { | ||
loadingBroadcasts.value = false; | ||
}); | ||
} | ||
|
||
function updateBroadcasts(broadcastList: BroadcastNotification[]) { | ||
broadcasts.value = mergeObjectListsById(broadcasts.value, broadcastList, "create_time", "desc").filter( | ||
(b) => !hasExpired(b.expiration_time) | ||
); | ||
} | ||
function updateBroadcasts(broadcastList: BroadcastNotification[]) { | ||
broadcasts.value = mergeObjectListsById(broadcasts.value, broadcastList, "create_time", "desc").filter( | ||
(b) => !hasExpired(b.expiration_time) | ||
); | ||
} | ||
|
||
function dismissBroadcast(broadcast: BroadcastNotification) { | ||
set(dismissedBroadcasts.value, broadcast.id, { expiration_time: broadcast.expiration_time }); | ||
} | ||
function dismissBroadcast(broadcast: BroadcastNotification) { | ||
Vue.set(dismissedBroadcasts.value, broadcast.id, { expiration_time: broadcast.expiration_time }); | ||
} | ||
|
||
function hasExpired(expirationTimeStr?: string) { | ||
if (!expirationTimeStr) { | ||
return false; | ||
function isActive(broadcast: BroadcastNotification) { | ||
return ( | ||
!dismissedBroadcasts.value[broadcast.id] && | ||
!hasExpired(broadcast.expiration_time) && | ||
hasBeenPublished(broadcast) | ||
); | ||
} | ||
const expirationTime = new Date(`${expirationTimeStr}Z`); | ||
const now = new Date(); | ||
return now > expirationTime; | ||
} | ||
|
||
function clearExpiredDismissedBroadcasts() { | ||
for (const key in dismissedBroadcasts.value) { | ||
if (hasExpired(dismissedBroadcasts.value[key]?.expiration_time)) { | ||
delete dismissedBroadcasts.value[key]; | ||
function hasExpired(expirationTimeStr?: string) { | ||
if (!expirationTimeStr) { | ||
return false; | ||
} | ||
const expirationTime = new Date(`${expirationTimeStr}Z`); | ||
const now = new Date(); | ||
return now > expirationTime; | ||
} | ||
} | ||
|
||
clearExpiredDismissedBroadcasts(); | ||
function hasBeenPublished(broadcast: BroadcastNotification) { | ||
const publicationTime = new Date(`${broadcast.publication_time}Z`); | ||
const now = new Date(); | ||
return now >= publicationTime; | ||
} | ||
|
||
return { | ||
broadcasts, | ||
dismissedBroadcasts, | ||
loadingBroadcasts, | ||
activeBroadcasts, | ||
dismissBroadcast, | ||
loadBroadcasts, | ||
updateBroadcasts, | ||
}; | ||
}); | ||
function clearExpiredDismissedBroadcasts() { | ||
for (const key in dismissedBroadcasts.value) { | ||
if (hasExpired(dismissedBroadcasts.value[key]?.expiration_time)) { | ||
delete dismissedBroadcasts.value[key]; | ||
} | ||
} | ||
} | ||
|
||
clearExpiredDismissedBroadcasts(); | ||
|
||
return { | ||
broadcasts, | ||
dismissedBroadcasts, | ||
loadingBroadcasts, | ||
activeBroadcasts, | ||
dismissBroadcast, | ||
loadBroadcasts, | ||
updateBroadcasts, | ||
}; | ||
}, | ||
{ | ||
persist: { | ||
paths: ["dismissedBroadcasts"], | ||
}, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.