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

refactor: Move page components to composables (no-changelog) #11494

Merged
merged 6 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 64 additions & 71 deletions packages/editor-ui/src/components/TemplateList.vue
Original file line number Diff line number Diff line change
@@ -1,82 +1,75 @@
<script lang="ts">
import { type PropType, defineComponent } from 'vue';
<script lang="ts" setup>
import { onBeforeUnmount, onMounted, ref } from 'vue';
import TemplateCard from './TemplateCard.vue';
import type { ITemplatesWorkflow } from '@/Interface';

export default defineComponent({
name: 'TemplateList',
components: {
TemplateCard,
},
props: {
infiniteScrollEnabled: {
type: Boolean,
default: false,
},
loading: {
type: Boolean,
},
useWorkflowButton: {
type: Boolean,
default: false,
},
workflows: {
type: Array as PropType<ITemplatesWorkflow[]>,
default: () => [],
},
totalWorkflows: {
type: Number,
default: 0,
},
simpleView: {
type: Boolean,
default: false,
},
totalCount: {
type: Number,
default: 0,
},
},
mounted() {
if (this.infiniteScrollEnabled) {
const content = document.getElementById('content');
if (content) {
content.addEventListener('scroll', this.onScroll);
}
}
},
beforeUnmount() {
interface Props {
workflows?: ITemplatesWorkflow[];
infiniteScrollEnabled?: boolean;
loading?: boolean;
useWorkflowButton?: boolean;
totalWorkflows?: number;
simpleView?: boolean;
totalCount?: number;
}

const emit = defineEmits<{
loadMore: [];
openTemplate: [{ event: MouseEvent; id: number }];
useWorkflow: [{ event: MouseEvent; id: number }];
}>();

const props = withDefaults(defineProps<Props>(), {
infiniteScrollEnabled: false,
loading: false,
useWorkflowButton: false,
workflows: () => [],
totalWorkflows: 0,
simpleView: false,
totalCount: 0,
});

const loader = ref<HTMLElement | null>(null);

onMounted(() => {
if (props.infiniteScrollEnabled) {
const content = document.getElementById('content');
if (content) {
content.removeEventListener('scroll', this.onScroll);
content.addEventListener('scroll', onScroll);
}
},
methods: {
onScroll() {
const loaderRef = this.$refs.loader as HTMLElement | undefined;
if (!loaderRef || this.loading) {
return;
}

const rect = loaderRef.getBoundingClientRect();
const inView =
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth);
}
});

if (inView) {
this.$emit('loadMore');
}
},
onCardClick(event: MouseEvent, id: number) {
this.$emit('openTemplate', { event, id });
},
onUseWorkflow(event: MouseEvent, id: number) {
this.$emit('useWorkflow', { event, id });
},
},
onBeforeUnmount(() => {
const content = document.getElementById('content');
if (content) {
content.removeEventListener('scroll', onScroll);
}
});

function onScroll() {
const loaderRef = loader.value as HTMLElement | undefined;
if (!loaderRef || props.loading) {
return;
}

const rect = loaderRef.getBoundingClientRect();
const inView =
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth);

if (inView) {
emit('loadMore');
}
}
function onCardClick(event: MouseEvent, id: number) {
emit('openTemplate', { event, id });
}
function onUseWorkflow(event: MouseEvent, id: number) {
emit('useWorkflow', { event, id });
}
</script>

<template>
Expand Down
18 changes: 0 additions & 18 deletions packages/editor-ui/src/components/layouts/PageViewLayout.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { mapStores } from 'pinia';
import { useUIStore } from '@/stores/ui.store';

export default defineComponent({
name: 'PageViewLayout',
data() {
return {
loading: false,
};
},
computed: {
...mapStores(useUIStore),
},
});
</script>

<template>
<div :class="$style.wrapper">
<slot name="header" />
Expand Down
15 changes: 6 additions & 9 deletions packages/editor-ui/src/components/layouts/PageViewLayoutList.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<script lang="ts">
import { defineComponent } from 'vue';
<script lang="ts" setup>
interface Props {
overflow: boolean;
}

export default defineComponent({
props: {
overflow: {
type: Boolean,
default: false,
},
},
withDefaults(defineProps<Props>(), {
overflow: false,
});
</script>

Expand Down
8 changes: 4 additions & 4 deletions packages/editor-ui/src/views/TemplatesCollectionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ const scrollToTop = () => {
}, 50);
};

const onOpenTemplate = ({ event, id }: { event: MouseEvent; id: string }) => {
navigateTo(event, VIEWS.TEMPLATE, id);
const onOpenTemplate = ({ event, id }: { event: MouseEvent; id: number }) => {
navigateTo(event, VIEWS.TEMPLATE, `${id}`);
};

const onUseWorkflow = async ({ event, id }: { event: MouseEvent; id: string }) => {
const onUseWorkflow = async ({ event, id }: { event: MouseEvent; id: number }) => {
await useTemplateWorkflow({
posthogStore,
router,
templateId: id,
templateId: `${id}`,
inNewBrowserTab: event.metaKey || event.ctrlKey,
templatesStore,
externalHooks,
Expand Down
20 changes: 7 additions & 13 deletions packages/editor-ui/src/views/TemplatesView.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
<script lang="ts">
import { defineComponent } from 'vue';
<script lang="ts" setup>
import GoBackButton from '@/components/GoBackButton.vue';

export default defineComponent({
name: 'TemplatesView',
components: {
GoBackButton,
},
props: {
goBackEnabled: {
type: Boolean,
default: false,
},
},
interface Props {
goBackEnabled?: boolean;
}

withDefaults(defineProps<Props>(), {
goBackEnabled: false,
});
</script>

Expand Down
Loading