Skip to content

Commit 2629438

Browse files
authored
always use username for posting (#10)
1 parent 8c6b71a commit 2629438

6 files changed

Lines changed: 42 additions & 59 deletions

File tree

packages/client/src/components/channels/Channel.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
2-
import { api, type Id } from "@packages/convex";
3-
import type { Doc } from "@packages/convex/src/convex/_generated/dataModel";
2+
import { api, type Doc, type Id } from "@packages/convex";
43
import { useQuery } from "convex-svelte";
54
import MessageInput from "../chat/MessageInput.svelte";
65
import MessageList from "../chat/MessageList.svelte";

packages/client/src/components/channels/ChannelList.svelte

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
| { type: "chat"; selectedChannelId: Id<"channels"> | undefined }
88
| { type: "personalization"; selectedChannelId: undefined };
99
10-
/*<<<<<<< HEAD:packages/client/src/components/chat/ChannelList.svelte
11-
screenMode: Selection;
12-
}
13-
14-
let {
15-
screenMode = $bindable(),
16-
}: Props = $props();
17-
=======
18-
*/
1910
interface Props {
2011
organizationId: Id<"organizations">;
2112
screenMode: Selection;
@@ -45,7 +36,10 @@
4536
: "hover:bg-base-300",
4637
].join(" ")}
4738
onclick={() => {
48-
screenMode = { type: "chat", selectedChannelId: channel._id };
39+
screenMode = {
40+
type: "chat",
41+
selectedChannelId: channel._id as Id<"channels">,
42+
};
4943
}}
5044
>
5145
<div class="font-medium"># {channel.name}</div>

packages/client/src/components/chat/MessageInput.svelte

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<script lang="ts">
2-
import { api, type Id } from "@packages/convex";
3-
import type { Doc } from "@packages/convex/src/convex/_generated/dataModel";
2+
import { api, type Doc, type Id } from "@packages/convex";
43
import { useConvexClient, useQuery } from "convex-svelte";
54
import FilePreview from "~/features/files/upload/FilePreview.svelte";
65
import FileSelector from "~/features/files/upload/Selector.svelte";
76
import { FileUploader } from "~/features/files/upload/uploader.svelte";
7+
import Attachment from "~/icons/attachment.svelte";
88
import MdiClose from "~/icons/mdi-close.svelte";
99
import { useMutation } from "~/lib/useMutation.svelte.ts";
10+
1011
import EmojiPalette from "./EmojiPalette.svelte";
1112
import VoteMaker from "./VoteMaker.svelte";
1213
@@ -33,46 +34,49 @@
3334
const convex = useConvexClient();
3435
3536
let messageContent = $state("");
36-
let authorName = $state("");
3737
let showEmojiPalette = $state(false);
3838
let showFileSelector = $state(false);
3939
let attachedFiles = $state<File[]>([]);
4040
41+
const clickable = $derived.by<boolean>(() => {
42+
// post ongoing
43+
if (sendMessageMutation.processing) return false;
44+
// identity not loaded yet
45+
if (!identity.data) return false;
46+
// empty content
47+
if (!messageContent.trim() && attachedFiles.length === 0 && !voteIsValid())
48+
return false;
49+
return true;
50+
});
51+
4152
let showVoteMaker = $state(false);
4253
let vote = $state<Vote>({
4354
title: "",
4455
maxVotes: 1,
4556
voteOptions: [],
4657
voters: [],
4758
});
48-
49-
const personalization = useQuery(api.personalization.getPersonalization, {
50-
organizationId: organizationId,
51-
});
52-
53-
$effect(() => {
54-
if (identity?.data && !authorName) {
55-
authorName =
56-
personalization.data?.nickname ??
57-
identity.data.name ??
58-
identity.data.email ??
59-
"匿名";
60-
}
61-
});
59+
function voteIsValid() {
60+
if (!vote.title.trim()) return false;
61+
if (vote.voteOptions.length === 0) return false;
62+
if (vote.maxVotes === 0) return false;
63+
return true;
64+
}
6265
6366
const uploader = new FileUploader(() => ({
6467
organizationId,
6568
}));
6669
6770
async function sendMessage() {
68-
if (!messageContent.trim() && attachedFiles.length === 0) return;
71+
if (!clickable) return;
72+
if (!identity.data) return;
6973
7074
const attachments = (await uploader.uploadAll(attachedFiles)).map(
7175
(it) => it.id,
7276
);
7377
7478
let voteId: Id<"votes"> | undefined;
75-
if (vote.title.trim() && vote.voteOptions.length !== 0) {
79+
if (voteIsValid()) {
7680
voteId = await convex.mutation(api.vote.addVote, {
7781
title: vote.title,
7882
maxVotes: vote.maxVotes,
@@ -83,7 +87,7 @@
8387
await sendMessageMutation.run({
8488
channelId,
8589
content: messageContent.trim() || "",
86-
author: authorName.trim() || "匿名",
90+
author: identity.data.name,
8791
parentId: replyingTo?._id ?? undefined,
8892
attachments,
8993
vote: voteId,
@@ -167,15 +171,7 @@
167171
{#if showVoteMaker}
168172
<VoteMaker bind:vote />
169173
{/if}
170-
171-
<div class="flex gap-2">
172-
<input
173-
type="text"
174-
placeholder="ユーザー名"
175-
class="input input-sm input-bordered w-32"
176-
bind:value={authorName}
177-
/>
178-
</div>
174+
<div class="flex gap-2"></div>
179175

180176
<div class="flex gap-2">
181177
<div class="flex-1 space-y-2">
@@ -195,19 +191,7 @@
195191
title="ファイルを添付"
196192
type="button"
197193
>
198-
<svg
199-
class="h-4 w-4"
200-
fill="none"
201-
stroke="currentColor"
202-
viewBox="0 0 24 24"
203-
>
204-
<path
205-
stroke-linecap="round"
206-
stroke-linejoin="round"
207-
stroke-width="2"
208-
d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"
209-
></path>
210-
</svg>
194+
<Attachment />
211195
{showFileSelector ? "キャンセル" : "ファイル添付"}
212196
</button>
213197
<button
@@ -224,8 +208,7 @@
224208
<button
225209
class="btn btn-primary self-end"
226210
onclick={sendMessage}
227-
disabled={(!messageContent.trim() && attachedFiles.length === 0) ||
228-
sendMessageMutation.processing}
211+
disabled={!clickable}
229212
>
230213
{#if sendMessageMutation.processing}
231214
<span class="loading loading-spinner loading-sm"></span>

packages/client/src/components/chat/MessageList.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
2-
import { api, type Id } from "@packages/convex";
3-
import type { Doc } from "@packages/convex/src/convex/_generated/dataModel";
2+
import { api, type Doc, type Id } from "@packages/convex";
43
import { useQuery } from "convex-svelte";
54
import { onMount } from "svelte";
65
import Modal, { ModalManager } from "$lib/modal/modal.svelte";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2+
<path
3+
stroke-linecap="round"
4+
stroke-linejoin="round"
5+
stroke-width="2"
6+
d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"
7+
></path>
8+
</svg>

packages/convex/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { api } from "./src/convex/_generated/api";
2-
export type { Id } from "./src/convex/_generated/dataModel";
2+
export type { Doc, Id } from "./src/convex/_generated/dataModel";
33

44
import type { DataModel } from "./src/convex/_generated/dataModel";
55
export type Task = DataModel["tasks"]["document"];

0 commit comments

Comments
 (0)