-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-implement user timeline in profile
- Loading branch information
Showing
6 changed files
with
134 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/renderer/components/TimelineSpace/Detail/Profile/Posts.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<template> | ||
<DynamicScroller :items="statuses" :min-item-size="86"> | ||
<template v-slot="{ item, index, active }"> | ||
<DynamicScrollerItem :item="item" :active="active" :size-dependencies="[item.uri]" :data-index="index" :watchData="true"> | ||
<Toot | ||
v-if="account && server" | ||
:message="item" | ||
:focused="item.uri + item.id === focusedId" | ||
:overlaid="modalOpened" | ||
:account="account" | ||
:server="server" | ||
@update="updateToot" | ||
@delete="deleteToot" | ||
@select-toot="focusToot(item)" | ||
/> | ||
</DynamicScrollerItem> | ||
</template> | ||
</DynamicScroller> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, PropType, onMounted, ref, watch, toRefs, computed } from 'vue' | ||
import generator, { Entity, MegalodonInterface } from 'megalodon' | ||
import Toot from '@/components/organisms/Toot.vue' | ||
import { LocalAccount } from '~/src/types/localAccount' | ||
import { LocalServer } from '~/src/types/localServer' | ||
import { useStore } from '@/store' | ||
export default defineComponent({ | ||
name: 'Posts', | ||
components: { Toot }, | ||
props: { | ||
user: { | ||
type: Object as PropType<Entity.Account>, | ||
required: true | ||
}, | ||
account: { | ||
type: Object as PropType<LocalAccount>, | ||
required: true | ||
}, | ||
server: { | ||
type: Object as PropType<LocalServer>, | ||
required: true | ||
} | ||
}, | ||
setup(props) { | ||
const { user, account, server } = toRefs(props) | ||
const store = useStore() | ||
const statuses = ref<Array<Entity.Status>>([]) | ||
const client = ref<MegalodonInterface | null>(null) | ||
const focusedId = ref<string | null>(null) | ||
const userAgent = computed(() => store.state.App.userAgent) | ||
const modalOpened = computed<boolean>(() => store.getters[`TimelineSpace/Modals/modalOpened`]) | ||
onMounted(async () => { | ||
client.value = generator(server.value.sns, server.value.baseURL, account.value.accessToken, userAgent.value) | ||
const res = await client.value.getAccountStatuses(user.value.id) | ||
statuses.value = res.data | ||
}) | ||
watch(user, async current => { | ||
if (client.value) { | ||
const res = await client.value.getAccountStatuses(current.id) | ||
statuses.value = res.data | ||
} | ||
}) | ||
const updateToot = (toot: Entity.Status) => { | ||
statuses.value = statuses.value.map(s => { | ||
if (s.id === toot.id) { | ||
return toot | ||
} | ||
return s | ||
}) | ||
} | ||
const deleteToot = (toot: Entity.Status) => { | ||
statuses.value = statuses.value.filter(s => s.id !== toot.id) | ||
} | ||
const focusToot = (toot: Entity.Status) => { | ||
focusedId.value = toot.uri + toot.id | ||
} | ||
return { | ||
statuses, | ||
modalOpened, | ||
updateToot, | ||
deleteToot, | ||
focusedId, | ||
focusToot | ||
} | ||
} | ||
}) | ||
</script> | ||
|
||
<style lang="scss" scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters