refactor(client): use setup syntax

This commit is contained in:
syuilo 2022-09-05 18:51:23 +09:00
parent 9132c72545
commit 9db2380c20
3 changed files with 54 additions and 61 deletions

View File

@ -8,12 +8,12 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { } from 'vue';
export default defineComponent({ function focus() {
// TODO
}); }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -30,7 +30,7 @@ export default defineComponent({
} else { } else {
if (nextBracketOpen > 0) parsed.push(str.substr(0, nextBracketOpen)); if (nextBracketOpen > 0) parsed.push(str.substr(0, nextBracketOpen));
parsed.push({ parsed.push({
arg: str.substring(nextBracketOpen + 1, nextBracketClose) arg: str.substring(nextBracketOpen + 1, nextBracketClose),
}); });
} }
@ -38,5 +38,5 @@ export default defineComponent({
} }
return h(this.tag, parsed.map(x => typeof x === 'string' ? (this.textTag ? h(this.textTag, x) : x) : this.$slots[x.arg]())); return h(this.tag, parsed.map(x => typeof x === 'string' ? (this.textTag ? h(this.textTag, x) : x) : this.$slots[x.arg]()));
} },
}); });

View File

@ -4,12 +4,13 @@
<div class="ujigsodd"> <div class="ujigsodd">
<MkLoading v-if="fetching"/> <MkLoading v-if="fetching"/>
<div v-if="!fetching && images.length > 0" class="stream"> <div v-if="!fetching && images.length > 0" class="stream">
<MkA v-for="image in images" <MkA
:key="image.id" v-for="image in images"
:key="image.note.id + image.file.id"
class="img" class="img"
:to="notePage(image.note)" :to="notePage(image.note)"
> >
<ImgWithBlurhash :hash="image.blurhash" :src="thumbnail(image.file)" :alt="image.name" :title="image.name"/> <ImgWithBlurhash :hash="image.file.blurhash" :src="thumbnail(image.file)" :title="image.file.name"/>
</MkA> </MkA>
</div> </div>
<p v-if="!fetching && images.length == 0" class="empty">{{ $ts.nothing }}</p> <p v-if="!fetching && images.length == 0" class="empty">{{ $ts.nothing }}</p>
@ -17,64 +18,56 @@
</MkContainer> </MkContainer>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { onMounted } from 'vue';
import * as misskey from 'misskey-js';
import { getStaticImageUrl } from '@/scripts/get-static-image-url'; import { getStaticImageUrl } from '@/scripts/get-static-image-url';
import { notePage } from '@/filters/note'; import { notePage } from '@/filters/note';
import * as os from '@/os'; import * as os from '@/os';
import MkContainer from '@/components/ui/container.vue'; import MkContainer from '@/components/ui/container.vue';
import ImgWithBlurhash from '@/components/MkImgWithBlurhash.vue'; import ImgWithBlurhash from '@/components/MkImgWithBlurhash.vue';
import { defaultStore } from '@/store';
export default defineComponent({ const props = defineProps<{
components: { user: misskey.entities.UserDetailed;
MkContainer, }>();
ImgWithBlurhash,
}, let fetching = $ref(true);
props: { let images = $ref<{
user: { note: misskey.entities.Note;
type: Object, file: misskey.entities.DriveFile;
required: true }[]>([]);
},
}, function thumbnail(image: misskey.entities.DriveFile): string {
data() { return defaultStore.state.disableShowingAnimatedImages
return { ? getStaticImageUrl(image.thumbnailUrl)
fetching: true, : image.thumbnailUrl;
images: [], }
};
}, onMounted(() => {
mounted() { const image = [
const image = [ 'image/jpeg',
'image/jpeg', 'image/png',
'image/png', 'image/gif',
'image/gif', 'image/apng',
'image/apng', 'image/vnd.mozilla.apng',
'image/vnd.mozilla.apng', ];
]; os.api('users/notes', {
os.api('users/notes', { userId: props.user.id,
userId: this.user.id, fileType: image,
fileType: image, excludeNsfw: defaultStore.state.nsfw !== 'ignore',
excludeNsfw: this.$store.state.nsfw !== 'ignore', limit: 10,
limit: 10, }).then(notes => {
}).then(notes => { for (const note of notes) {
for (const note of notes) { for (const file of note.files) {
for (const file of note.files) { images.push({
this.images.push({ note,
note, file,
file });
});
}
} }
this.fetching = false; }
}); fetching = false;
}, });
methods: {
thumbnail(image: any): string {
return this.$store.state.disableShowingAnimatedImages
? getStaticImageUrl(image.thumbnailUrl)
: image.thumbnailUrl;
},
notePage
},
}); });
</script> </script>