2024-07-06 20:57:32 -07:00
|
|
|
import { computed, defineComponent, h, onBeforeUnmount, ref, watch } from "vue";
|
|
|
|
|
import { startLoading, stopLoading, useNuxtApp } from "#imports";
|
2023-03-09 10:05:32 -07:00
|
|
|
|
|
|
|
|
export default defineComponent({
|
2024-07-06 20:57:32 -07:00
|
|
|
name: "ModrinthLoadingIndicator",
|
2023-03-09 10:05:32 -07:00
|
|
|
props: {
|
|
|
|
|
throttle: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 50,
|
|
|
|
|
},
|
|
|
|
|
duration: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 500,
|
|
|
|
|
},
|
|
|
|
|
height: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 3,
|
|
|
|
|
},
|
|
|
|
|
color: {
|
|
|
|
|
type: [String, Boolean],
|
|
|
|
|
default:
|
Project, Search, User redesign (#1281)
* New project page
* fix silly icon tailwind classes
* Start new versions page, add new ButtonStyled component
* Pagination and finish mocking up versions page functionality
* green download button
* hover animation
* New Modal, Avatar refactor, subpages in NavTabs
* lint
* Download modal
* New user page + fix lint
* fix ui lint
* Download animation fix
* Versions filter + finish project page
* Improve consistency of buttons on home page
* Fix ButtonStyled breaking
* Fix margin on version summary
* finish search, new modals, user + project page mobile
* fix gallery image pages
* New project header
* Fix gallery tab showing improperly
* Use auto direction + position for all popouts
* Preliminary user page
* test to see if this fixes login stuff
* remove extra slash
* Add version actions, move download button on versions page
* Listed -> public
* Shorten download modal selector height
* Fix user menu open direction
* Change breakpoint for header collapse
* Only underline title
* Tighten padding on stats a little
* New nav
* Make mobile breakpoint more consistent
* fix header breakpoint regression
* Add sign in button
* Fix edit icon color
* Fix margin at top of screen
* Fix user bios and ad width
* Fix user nav showing when there's only one type of project
* Fix plural projects on user page & extract i18n
* Remove ads on mobile for now
* Fix overflow menu showing hidden items
* NavTabs on mobile
* Fix navbar z index
* Search filter overhaul + negative filters
* fix no-max-height
* port version filters, fix following/collections, lint
* hide promos
* ui lint
* Disable modal background animation to reduce reported motion sickness
* Hide install with modrinth app button on mobile
---------
Signed-off-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
Co-authored-by: Prospector <prospectordev@gmail.com>
2024-08-20 23:03:16 -07:00
|
|
|
"repeating-linear-gradient(to right, var(--color-green) 0%, var(--landing-green-label) 100%)",
|
2023-03-09 10:05:32 -07:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
setup(props, { slots }) {
|
|
|
|
|
const indicator = useLoadingIndicator({
|
|
|
|
|
duration: props.duration,
|
|
|
|
|
throttle: props.throttle,
|
2024-07-06 20:57:32 -07:00
|
|
|
});
|
2023-03-09 10:05:32 -07:00
|
|
|
|
2024-07-06 20:57:32 -07:00
|
|
|
const nuxtApp = useNuxtApp();
|
|
|
|
|
nuxtApp.hook("page:start", () => {
|
|
|
|
|
startLoading();
|
|
|
|
|
indicator.start();
|
|
|
|
|
});
|
|
|
|
|
nuxtApp.hook("page:finish", () => {
|
|
|
|
|
stopLoading();
|
|
|
|
|
indicator.finish();
|
|
|
|
|
});
|
|
|
|
|
onBeforeUnmount(() => indicator.clear);
|
2023-03-09 10:05:32 -07:00
|
|
|
|
2024-07-06 20:57:32 -07:00
|
|
|
const loading = useLoading();
|
2023-03-09 10:05:32 -07:00
|
|
|
|
2023-05-06 22:17:43 +03:00
|
|
|
watch(loading, (newValue) => {
|
2023-03-09 10:05:32 -07:00
|
|
|
if (newValue) {
|
2024-07-06 20:57:32 -07:00
|
|
|
indicator.start();
|
2023-03-09 10:05:32 -07:00
|
|
|
} else {
|
2024-07-06 20:57:32 -07:00
|
|
|
indicator.finish();
|
2023-03-09 10:05:32 -07:00
|
|
|
}
|
2024-07-06 20:57:32 -07:00
|
|
|
});
|
2023-03-09 10:05:32 -07:00
|
|
|
|
|
|
|
|
return () =>
|
|
|
|
|
h(
|
2024-07-06 20:57:32 -07:00
|
|
|
"div",
|
2023-03-09 10:05:32 -07:00
|
|
|
{
|
2024-07-06 20:57:32 -07:00
|
|
|
class: "nuxt-loading-indicator",
|
2023-03-09 10:05:32 -07:00
|
|
|
style: {
|
2024-07-06 20:57:32 -07:00
|
|
|
position: "fixed",
|
2023-03-09 10:05:32 -07:00
|
|
|
top: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
left: 0,
|
2024-07-06 20:57:32 -07:00
|
|
|
pointerEvents: "none",
|
2023-03-09 10:05:32 -07:00
|
|
|
width: `${indicator.progress.value}%`,
|
|
|
|
|
height: `${props.height}px`,
|
|
|
|
|
opacity: indicator.isLoading.value ? 1 : 0,
|
|
|
|
|
background: props.color || undefined,
|
|
|
|
|
backgroundSize: `${(100 / indicator.progress.value) * 100}% auto`,
|
2024-07-06 20:57:32 -07:00
|
|
|
transition: "width 0.1s, height 0.4s, opacity 0.4s",
|
2023-03-09 10:05:32 -07:00
|
|
|
zIndex: 999999,
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-07-06 20:57:32 -07:00
|
|
|
slots,
|
|
|
|
|
);
|
2023-03-09 10:05:32 -07:00
|
|
|
},
|
2024-07-06 20:57:32 -07:00
|
|
|
});
|
2023-03-09 10:05:32 -07:00
|
|
|
|
|
|
|
|
function useLoadingIndicator(opts: { duration: number; throttle: number }) {
|
2024-07-06 20:57:32 -07:00
|
|
|
const progress = ref(0);
|
|
|
|
|
const isLoading = ref(false);
|
|
|
|
|
const step = computed(() => 10000 / opts.duration);
|
2023-03-09 10:05:32 -07:00
|
|
|
|
2024-07-06 20:57:32 -07:00
|
|
|
let _timer: any = null;
|
|
|
|
|
let _throttle: any = null;
|
2023-03-09 10:05:32 -07:00
|
|
|
|
|
|
|
|
function start() {
|
2024-07-06 20:57:32 -07:00
|
|
|
clear();
|
|
|
|
|
progress.value = 0;
|
2024-07-10 22:17:04 -07:00
|
|
|
if (opts.throttle && import.meta.client) {
|
2023-03-09 10:05:32 -07:00
|
|
|
_throttle = setTimeout(() => {
|
2024-07-06 20:57:32 -07:00
|
|
|
isLoading.value = true;
|
|
|
|
|
_startTimer();
|
|
|
|
|
}, opts.throttle);
|
2023-03-09 10:05:32 -07:00
|
|
|
} else {
|
2024-07-06 20:57:32 -07:00
|
|
|
isLoading.value = true;
|
|
|
|
|
_startTimer();
|
2023-03-09 10:05:32 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function finish() {
|
2024-07-06 20:57:32 -07:00
|
|
|
progress.value = 100;
|
|
|
|
|
_hide();
|
2023-03-09 10:05:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clear() {
|
2024-07-06 20:57:32 -07:00
|
|
|
clearInterval(_timer);
|
|
|
|
|
clearTimeout(_throttle);
|
|
|
|
|
_timer = null;
|
|
|
|
|
_throttle = null;
|
2023-03-09 10:05:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _increase(num: number) {
|
2024-07-06 20:57:32 -07:00
|
|
|
progress.value = Math.min(100, progress.value + num);
|
2023-03-09 10:05:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _hide() {
|
2024-07-06 20:57:32 -07:00
|
|
|
clear();
|
2024-07-10 22:17:04 -07:00
|
|
|
if (import.meta.client) {
|
2023-03-09 10:05:32 -07:00
|
|
|
setTimeout(() => {
|
2024-07-06 20:57:32 -07:00
|
|
|
isLoading.value = false;
|
2023-03-09 10:05:32 -07:00
|
|
|
setTimeout(() => {
|
2024-07-06 20:57:32 -07:00
|
|
|
progress.value = 0;
|
|
|
|
|
}, 400);
|
|
|
|
|
}, 500);
|
2023-03-09 10:05:32 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _startTimer() {
|
2024-07-10 22:17:04 -07:00
|
|
|
if (import.meta.client) {
|
2023-03-09 10:05:32 -07:00
|
|
|
_timer = setInterval(() => {
|
2024-07-06 20:57:32 -07:00
|
|
|
_increase(step.value);
|
|
|
|
|
}, 100);
|
2023-03-09 10:05:32 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
progress,
|
|
|
|
|
isLoading,
|
|
|
|
|
start,
|
|
|
|
|
finish,
|
|
|
|
|
clear,
|
2024-07-06 20:57:32 -07:00
|
|
|
};
|
2023-03-09 10:05:32 -07:00
|
|
|
}
|