Skip to content

Commit

Permalink
1,577th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Oct 28, 2024
1 parent 4946971 commit f788004
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 33 deletions.
3 changes: 2 additions & 1 deletion ui/src/components/form-control/FormControl.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts" setup>
import { useId } from 'vue';
import { type FormControlProps, formControlDefaults } from './config';
import type { FormControlProps } from './types';
import { formControlDefaults } from './helpers';
withDefaults(defineProps<FormControlProps>(), formControlDefaults);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { computed } from 'vue';

export type FormControlProps = {
label?: string;
required?: boolean;
invalid?: boolean | string;
help?: string;
sub?: boolean;
};
import type { FormControlProps } from './types';

export const formControlDefaults: FormControlProps = {
label: '',
Expand Down
3 changes: 2 additions & 1 deletion ui/src/components/form-control/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import FormControl from './FormControl.vue';

export * from './config';
export * from './helpers';
export * from './types';

export default FormControl;
7 changes: 7 additions & 0 deletions ui/src/components/form-control/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type FormControlProps = {
label?: string;
required?: boolean;
invalid?: boolean | string;
help?: string;
sub?: boolean;
};
29 changes: 5 additions & 24 deletions ui/src/components/rich-text-editor/RichTextEditor.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import type { Extensions } from '@tiptap/vue-3';
import { nextTick, ref, computed, watch, onMounted, getCurrentInstance } from 'vue';
import { nextTick, ref, computed, watch, onMounted } from 'vue';
import { Editor, EditorContent } from '@tiptap/vue-3';
import Blockquote from '@tiptap/extension-blockquote';
import Bold from '@tiptap/extension-bold';
Expand Down Expand Up @@ -32,7 +32,8 @@ import FormControl, { type FormControlProps, formControlDefaults } from '../form
import Listbox from '../listbox';
import Popover from '../popover/Popover.vue';
import Tooltip from '../tooltip/Tooltip.vue';
import request from '../../utilities/request/request';
import { uploadImage } from './config';
const defaultModel = defineModel<string>({ default: '' });
Expand All @@ -56,12 +57,6 @@ const props = withDefaults(
},
);
const emit = defineEmits<{
(evt: 'upload', file: File, uploaded: (src: string) => void): void;
}>();
const instance = getCurrentInstance();
const editor = ref<Editor>();
const editorClass = computed(() => {
Expand Down Expand Up @@ -234,7 +229,7 @@ onChange((files) => {
uploadFile(file);
});
async function uploadFile(file: File) {
function uploadFile(file: File) {
const uploadIndicator = '[Uploading...]';
uploadIndicatorRange.value = {
Expand All @@ -244,21 +239,7 @@ async function uploadFile(file: File) {
editor.value?.chain().focus().insertContent(uploadIndicator).run();
if (instance?.vnode?.props?.onUpload) {
emit('upload', file, uploaded);
} else {
const formData = new FormData();
formData.append('file', file);
const response = await request<{ url: string }>('/file-uploads', {
method: 'POST',
body: formData,
});
if (response.ok && response._data) {
uploaded(response._data.url);
}
}
uploadImage(file, uploaded);
}
async function uploaded(src: string) {
Expand Down
15 changes: 15 additions & 0 deletions ui/src/components/rich-text-editor/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import request from '../../utilities/request/request';

export const uploadImage = async (file: File, uploaded: (src: string) => Promise<void>) => {
const formData = new FormData();
formData.append('file', file);

const response = await request<{ url: string }>('/file-uploads', {
method: 'POST',
body: formData,
});

if (response.ok && response._data) {
uploaded(response._data.url);
}
};

0 comments on commit f788004

Please sign in to comment.