UserCard - allow changing nick

This commit is contained in:
Sam Hoffman
2026-01-12 23:14:53 -05:00
parent 31eff22d95
commit 7a567292ae
4 changed files with 84 additions and 17 deletions

View File

@@ -1,21 +1,17 @@
<script setup>
import { ref, onMounted } from "vue";
import { onMounted } from "vue";
import { useIRCStore } from "@/stores/irc";
const store = useIRCStore();
const inputBuffer = ref();
onMounted(store.connect);
function send() {
store.sendActiveBuffer(inputBuffer.value);
inputBuffer.value = "";
}
</script>
<template>
<div class="d-flex flex-row" style="height: 100vh">
<v-sheet border class="buffers">
<UserCard />
<v-divider />
<BufferList />
</v-sheet>
<div class="messages d-flex flex-column">
@@ -30,14 +26,16 @@ function send() {
:me="store.clientInfo.nick"
/>
<v-sheet>
<v-text-field
variant="outlined"
:placeholder="`Message ${store.activeBufferName}`"
v-model="inputBuffer"
hide-details
class="ma-2"
@keydown.enter.exact.prevent="send"
/>
<!-- <v-text-field -->
<!-- variant="outlined" -->
<!-- :placeholder="`Message ${store.activeBufferName}`" -->
<!-- v-model="inputBuffer" -->
<!-- hide-details -->
<!-- class="ma-2" -->
<!-- @keydown.enter.exact.prevent="send" -->
<!-- /> -->
<InputBuffer @send="store.sendActiveBuffer" />
</v-sheet>
</div>
<v-sheet class="user-list h-100" border>

View File

@@ -0,0 +1,44 @@
<script setup>
import { ref } from "vue";
import { useIRCStore } from "@/stores/irc";
import { storeToRefs } from "pinia";
const { selfAvatar } = storeToRefs(useIRCStore());
const { client, clientInfo, setAvatar, setNick } = useIRCStore();
const avatarDialog = ref(false);
const newNick = ref();
function changeAvatar() {
avatarDialog.value = true;
}
function submitAvatar() {
setAvatar(selfAvatar.value);
avatarDialog.value = false;
if (newNick.value && clientInfo.nick !== newNick.value) {
console.log("nick changed");
client.changeNick(newNick.value);
}
}
</script>
<template>
<v-dialog v-model="avatarDialog">
<v-card title="Edit Profile">
<v-card-text>
<v-text-field v-model="selfAvatar" label="Avatar URL" />
<v-text-field v-model="newNick" label="Nick" />
</v-card-text>
<v-card-actions>
<v-btn text="OK" @click="submitAvatar" />
</v-card-actions>
</v-card>
</v-dialog>
<v-card>
<v-card-title>
<v-avatar @click="changeAvatar" v-if="selfAvatar" :image="selfAvatar" />
{{ clientInfo.nick }}
</v-card-title>
<v-card-text> </v-card-text>
</v-card>
</template>

View File

@@ -13,6 +13,17 @@ export const useIRCStore = defineStore("irc", () => {
gecos: "IrChad",
});
const selfAvatar = ref("https://placekittens.com/128/128");
function setAvatar(v) {
selfAvatar.value = v;
client.raw(`METADATA * SET avatar ${selfAvatar.value}`);
}
function setNick(v) {
client.changeNick(v);
}
const buffers = ref({});
const activeBufferName = ref();
const metadata = ref({});
@@ -87,7 +98,18 @@ export const useIRCStore = defineStore("irc", () => {
client.on("registered", function () {
client.list();
client.raw("METADATA * SUB avatar");
client.raw("METADATA * SET avatar https://placekittens.com/128/128");
client.raw(`METADATA * SET avatar ${selfAvatar.value}`);
});
client.on("nick", function ({ nick, new_nick }) {
if (nick === clientInfo.value.nick) {
clientInfo.value.nick = new_nick;
}
for (let buff of Object.values(buffers.value)) {
const idx = buff.users.findIndex((u) => u.nick === nick);
if (idx === -1) continue;
buff.users[idx].nick = new_nick;
}
});
client.on("unknown command", function (ircCommand) {
@@ -192,5 +214,8 @@ export const useIRCStore = defineStore("irc", () => {
setActiveBuffer,
getMetadata,
metadata,
selfAvatar,
setAvatar,
setNick,
};
});