Skip to content

Commit

Permalink
refactor: Fix blocked images
Browse files Browse the repository at this point in the history
  • Loading branch information
reeko committed Mar 25, 2022
1 parent 8f320e9 commit 7d2a8e5
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 22 deletions.
9 changes: 8 additions & 1 deletion src/components/MatchdFileView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
<ul class="matchd-file-view__list">
<li v-for="file in files" :key="file.id" class="matchd-file-view__item flex items-center">
<template v-if="file.mimeType.indexOf('image/') > -1">
<img :src="getImageUrlWithStack(file.url)" class="w-40 h-40 border-r" alt="Bild" />
<StackImage
:url="file.url"
stack="desktop-square"
class="w-40 h-40 border-r"
alt="Bild"
/>
</template>
<template v-else-if="file.mimeType.indexOf('video/') > -1">
<div class="px-8">
Expand Down Expand Up @@ -61,6 +66,7 @@ import Loading from "@/assets/icons/loading.svg";
import MatchdButton from "@/components/MatchdButton.vue";
import { QueuedFile } from "@/store/modules/upload/state";
import { Options, prop, Vue } from "vue-class-component";
import StackImage from "./StackImage.vue";
class Props {
files = prop<Attachment[]>({});
Expand All @@ -72,6 +78,7 @@ class Props {
MatchdButton,
Loading,
ErrorIcon,
StackImage,
},
emits: ["deleteFile"],
})
Expand Down
24 changes: 24 additions & 0 deletions src/components/StackImage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<template>
<img :src="src" />
</template>

<script lang="ts">
import fetchAttachmentDataUri from "@/helpers/fetchAttachmentDataUri";
import { prop, Vue } from "vue-class-component";
import { Watch } from "vue-property-decorator";
class Props {
url = prop<string>({ required: true });
stack = prop<string>({ required: true });
}
export default class EditLink extends Vue.with(Props) {
src: string = "";
@Watch("url", { immediate: true })
async fetchUrl() {
this.src = await fetchAttachmentDataUri(this.url, this.stack);
}
}
</script>

<style lang="postcss" scoped></style>
12 changes: 5 additions & 7 deletions src/components/dashboard/StudentDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
class="bg-student-gradient-t-b text-white p-9 flex flex-col border-b xl:border-b-0 xl:border-r border-green-1"
>
<div class="flex justify-center m-5 lg:m-20 lg:w-86 lg:h-86">
<img
<StackImage
class="avatar rounded-full object-cover"
:src="replaceStack(avatar.url, 'avatar')"
:url="avatar.url"
stack="avatar"
:alt="`${user?.firstName} Profilbild`"
/>
</div>
Expand Down Expand Up @@ -165,8 +166,8 @@ import MatchdButton from "@/components/MatchdButton.vue";
import MatchdFileUpload from "@/components/MatchdFileUpload.vue";
import MatchdFileView from "@/components/MatchdFileView.vue";
import ProfileSection from "@/components/ProfileSection.vue";
import { replaceStack } from "@/helpers/replaceStack";
import { Options, prop, Vue } from "vue-class-component";
import StackImage from "../StackImage.vue";
class Props {
dashboard = prop<Dashboard>({ required: true });
Expand All @@ -181,6 +182,7 @@ class Props {
MatchdFileView,
ProfileSection,
CompanyMatchGroup,
StackImage,
},
})
export default class StudentDashboard extends Vue.with(Props) {
Expand All @@ -207,10 +209,6 @@ export default class StudentDashboard extends Vue.with(Props) {
undefined
);
}
replaceStack(url: string, stack: string) {
return replaceStack(url, stack);
}
}
</script>
Expand Down
12 changes: 12 additions & 0 deletions src/helpers/fetchAttachmentDataUri.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Attachment } from "@/api/models/types";
import { useStore } from "@/store";

export default async function fetchAttachmentDataUri(url: Attachment["url"], stack: string) {
const store = useStore();
const result = await fetch(url.replace("{stack}", stack), {
headers: {
authorization: `JWT ${store.getters["accessToken"]}`,
},
});
return URL.createObjectURL(await result.blob());
}
13 changes: 5 additions & 8 deletions src/views/StudentProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
class="bg-student-gradient-t-b text-white p-9 flex flex-col border-b xl:border-b-0 xl:border-r border-green-1"
>
<div v-if="avatarSrc" class="flex justify-center mt-9">
<img
<StackImage
class="avatar rounded-full object-cover"
width="300"
height="300"
:src="replaceStack(avatarSrc, 'avatar')"
:url="avatarSrc"
stack="avatar"
:alt="`Profilbild von ${user.firstName} ${user.lastName}`"
/>
</div>
Expand Down Expand Up @@ -109,21 +110,21 @@
</template>
<script lang="ts">
import type { User } from "@/api/models/types";
import { AttachmentKey, DateMode } from "@/api/models/types";
import ArrowDown from "@/assets/icons/arrow-down.svg";
import ProfileSection from "@/components/ProfileSection.vue";
import { calculateMargins } from "@/helpers/calculateMargins";
import { formatDate } from "@/helpers/formatDate";
import { replaceStack } from "@/helpers/replaceStack";
import { ParamStrings } from "@/router/paramStrings";
import { ActionTypes as UploadActionTypes } from "@/store/modules/upload/action-types";
import { Options, Vue } from "vue-class-component";
import StackImage from "../components/StackImage.vue";
@Options({
components: {
ProfileSection,
ArrowDown,
StackImage,
},
})
export default class StudentProfile extends Vue {
Expand Down Expand Up @@ -171,10 +172,6 @@ export default class StudentProfile extends Vue {
}
}
replaceStack(url: string, stack: string) {
return replaceStack(url, stack);
}
getStepName(step: number) {
return `${ParamStrings.STEP}${step}`;
}
Expand Down
13 changes: 7 additions & 6 deletions src/views/profile/student/StudentStep5.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
@click-nickname="onClickNickname"
/></div
></template>
<template v-else #info
>Du kannst dein Profil anonym oder öffentlich nutzen. Willst du anonym bleiben, zeigen wir
diesen Nickname an.</template
>
<template v-else #info>
Du kannst dein Profil anonym oder öffentlich nutzen. Willst du anonym bleiben, zeigen wir
diesen Nickname an.
</template>
</MatchdField>
<MatchdFileBlock>
<template #label>Dein Profilbild</template>
Expand All @@ -38,10 +37,12 @@
<MatchdFileUpload
v-if="studentAvatar.length === 0"
:upload-configuration="studentAvatarUploadConfigurations"
:formal="true"
class="mb-10"
@select-files="onSelectStudentAvatar"
>Bild hochladen</MatchdFileUpload
>
Bild hochladen
</MatchdFileUpload>
</MatchdFileBlock>
<template v-if="edit">
<teleport to="footer">
Expand Down

0 comments on commit 7d2a8e5

Please sign in to comment.