-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fff9149
commit 7ec4128
Showing
12 changed files
with
258 additions
and
130 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {popup, removePopups, toast} from "../actions.mjs"; | ||
import {PopupComponents} from "../components/popup.mjs"; | ||
import {Api} from "./Api.mjs"; | ||
import {Live} from "../live/Live.mjs"; | ||
import {CommonTemplates} from "../components/common.mjs"; | ||
import {signal} from "https://fjs.targoninc.com/f.js"; | ||
import {Store} from "./Store.mjs"; | ||
|
||
export class Popups { | ||
static newDm() { | ||
const userSearchResults = signal([]); | ||
const channels = Store.get("channels"); | ||
|
||
popup(PopupComponents.searchPopup(() => { | ||
removePopups(); | ||
}, (e) => { | ||
const query = e.target.value; | ||
if (query.length < 3) { | ||
userSearchResults.value = []; | ||
return; | ||
} | ||
|
||
Api.search(query).then((res) => { | ||
if (res.status !== 200) { | ||
toast("Failed to search for users", "error"); | ||
return; | ||
} | ||
userSearchResults.value = res.data.filter(user => { | ||
return !channels.value.some(channel => { | ||
if (channel.type === "dm" && channel.members.length === 1) { | ||
return channel.members[0].id === user.id; | ||
} | ||
|
||
return channel.type === "dm" && channel.members[1].id === user.id; | ||
}); | ||
}); | ||
}) | ||
}, () => {}, userSearchResults, (result) => { | ||
return CommonTemplates.chatWithButton(result.username, () => { | ||
Api.createDirect(result.id).then((res) => { | ||
if (res.status !== 200) { | ||
toast("Failed to create DM", "error"); | ||
removePopups(); | ||
return; | ||
} | ||
toast("DM created", "success"); | ||
Live.send({ | ||
type: "createChannel", | ||
channelId: res.data.id, | ||
}); | ||
removePopups(); | ||
}); | ||
}); | ||
}, "New DM", "Search for users")); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import {computedSignal, create, ifjs, signal, signalMap} from "https://fjs.targoninc.com/f.js"; | ||
import {Live} from "../live/Live.mjs"; | ||
import {truncate} from "../tooling/Text.mjs"; | ||
|
||
export class ChannelTemplates { | ||
static dmChannel(channel, messages, activeChannel) { | ||
const activeClass = computedSignal(activeChannel, (id) => id === channel.id ? "active" : "_"); | ||
|
||
return create("div") | ||
.classes("channel", "flex-v", "no-gap", "full-width", activeClass) | ||
.onclick(() => { | ||
activeChannel.value = channel.id; | ||
}) | ||
.children( | ||
create("span") | ||
.text(channel.name) | ||
.build(), | ||
create("span") | ||
.classes("text-small", "one-line") | ||
.text(truncate(messages.value[channel.id]?.at(-1)?.text || "No messages", 100)) | ||
.build(), | ||
).build(); | ||
} | ||
|
||
static groupChannel(channel, messages, activeChannel) { | ||
const activeClass = computedSignal(activeChannel, (id) => id === channel.id ? "active" : "_"); | ||
const editing = signal(false); | ||
|
||
return create("div") | ||
.classes("channel", "flex-v", "full-width", activeClass) | ||
.onclick(() => { | ||
activeChannel.value = channel.id; | ||
}) | ||
.children( | ||
ifjs(editing, create("input") | ||
.type("text") | ||
.value(channel.name) | ||
.onchange((e) => { | ||
Live.send({ | ||
type: "updateChannel", | ||
channelId: channel.id, | ||
name: e.target.value, | ||
}); | ||
}).build()), | ||
ifjs(editing, create("span") | ||
.text(channel.name) | ||
.build(), true), | ||
create("span") | ||
.classes("text-small") | ||
.text("Group") | ||
.build(), | ||
).build(); | ||
} | ||
|
||
static channelList(channels, messages, activeChannel) { | ||
return signalMap(channels, | ||
create("div") | ||
.classes("flex-v", "no-gap") | ||
, channel => { | ||
if (channel.type === "gr") { | ||
return ChannelTemplates.groupChannel(channel, messages, activeChannel); | ||
} else { | ||
return ChannelTemplates.dmChannel(channel, messages, activeChannel); | ||
} | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.