Last active
December 24, 2021 10:36
-
-
Save Jimeux/832b845be100a4456b9bdba6a1ca1f2c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<script lang="ts"> | |
import { computed, defineComponent, PropType } from "vue" | |
import { useStore } from "@/store/store" | |
import { User } from "@/store/data" | |
export default defineComponent({ | |
name: "UserItem", | |
props: { | |
user: { | |
type: Object as PropType<User>, | |
required: true, | |
}, | |
}, | |
setup(props) { | |
const store = useStore() | |
const unreadClass = computed(() => { | |
const u = store.state.unread | |
return u.has(props.user.connectionId) ? "" : "inactive" | |
}) | |
const separatorClass = computed(() => | |
store.state.currentRecipient?.connectionId === props.user.connectionId | |
? "active" | |
: "" | |
) | |
const containerClass = computed(() => { | |
const r = store.state.currentRecipient | |
return r?.connectionId === props.user.connectionId ? "active" : "" | |
}) | |
function setRecipient() { | |
store.setRecipient(props.user) | |
} | |
return { | |
separatorClass, | |
unreadClass, | |
klass, | |
setRecipient, | |
} | |
}, | |
}) | |
</script> |
This file contains hidden or 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
<script setup lang="ts"> | |
import {computed, PropType} from "vue" | |
import {useStore} from "../store/store" | |
import {User} from "../store/data" | |
const props = defineProps({ | |
user: { | |
type: Object as PropType<User>, | |
required: true, | |
}, | |
}) | |
const store = useStore() | |
const unreadClass = computed(() => { | |
const u = store.state.unread | |
return u.has(props.user.connectionId) ? "" : "inactive" | |
}) | |
const separatorClass = computed(() => | |
store.state.currentRecipient?.connectionId === props.user.connectionId | |
? "active" | |
: "" | |
) | |
const containerClass = computed(() => { | |
const r = store.state.currentRecipient | |
return r?.connectionId === props.user.connectionId ? "active" : "" | |
}) | |
function setRecipient() { | |
store.setRecipient(props.user) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment