-
Notifications
You must be signed in to change notification settings - Fork 54
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
0d8776a
commit ee91b5a
Showing
101 changed files
with
2,848 additions
and
723 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,70 @@ | ||
<script lang="ts"> | ||
import { currentUser, emptyBotInstance, OpenChat } from "openchat-client"; | ||
import { i18nKey } from "../../i18n/i18n"; | ||
import ModalContent from "../ModalContent.svelte"; | ||
import Translatable from "../Translatable.svelte"; | ||
import BotBuilder from "./BotBuilder.svelte"; | ||
import Button from "../Button.svelte"; | ||
import { mobileWidth } from "../../stores/screenDimensions"; | ||
import { getContext } from "svelte"; | ||
import { toastStore } from "../../stores/toast"; | ||
import ButtonGroup from "../ButtonGroup.svelte"; | ||
// This is just a dummy modal for dev purposes. For the real thing the bot builder | ||
// will be embedded in the make proposal UI | ||
const client = getContext<OpenChat>("client"); | ||
interface Props { | ||
onClose: () => void; | ||
} | ||
let { onClose }: Props = $props(); | ||
let valid = $state(false); | ||
let registering = $state(false); | ||
let bot = $state(emptyBotInstance()); | ||
function onUpdate() {} | ||
function register() { | ||
if (bot !== undefined && valid) { | ||
registering = true; | ||
const snapshot = $state.snapshot(bot); | ||
client | ||
.registerBot({ | ||
...snapshot, | ||
ownerId: $currentUser.userId, | ||
}) | ||
.then((success) => { | ||
if (!success) { | ||
toastStore.showFailureToast(i18nKey("Unable to register test bot")); | ||
} else { | ||
console.log("Bot registered"); | ||
onClose(); | ||
} | ||
}) | ||
.finally(() => (registering = false)); | ||
} | ||
} | ||
</script> | ||
|
||
<ModalContent on:close> | ||
<ModalContent on:close={onClose}> | ||
<div class="header" slot="header"> | ||
<Translatable resourceKey={i18nKey("bots.builder.title")}></Translatable> | ||
</div> | ||
<div class="body" slot="body"> | ||
<BotBuilder {onUpdate} bind:valid /> | ||
<BotBuilder onUpdate={(b) => (bot = b)} bind:valid /> | ||
</div> | ||
<div class="footer" slot="footer"> | ||
<ButtonGroup> | ||
<Button secondary small={!$mobileWidth} tiny={$mobileWidth} on:click={onClose}> | ||
<Translatable resourceKey={i18nKey("cancel")} /> | ||
</Button> | ||
<Button | ||
on:click={register} | ||
disabled={!valid || registering} | ||
loading={registering} | ||
small={!$mobileWidth} | ||
tiny={$mobileWidth}> | ||
<Translatable resourceKey={i18nKey("Register")} /> | ||
</Button> | ||
</ButtonGroup> | ||
</div> | ||
</ModalContent> | ||
|
||
<style lang="scss"> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<script lang="ts"> | ||
import { i18nKey, type CommunitySummary, type OpenChat } from "openchat-client"; | ||
import Search from "../Search.svelte"; | ||
import { getContext } from "svelte"; | ||
import { botSearchState } from "../../stores/search.svelte"; | ||
import Button from "../Button.svelte"; | ||
import Translatable from "../Translatable.svelte"; | ||
import BotMatch from "./BotMatch.svelte"; | ||
const client = getContext<OpenChat>("client"); | ||
const PAGE_SIZE = 50; | ||
interface Props { | ||
community: CommunitySummary; | ||
} | ||
let { community }: Props = $props(); | ||
let initialised = $state(false); | ||
let searching = $state(false); | ||
let more = $derived(botSearchState.total > botSearchState.results.length); | ||
function onSearchEntered(reset = false) { | ||
searching = true; | ||
if (reset) { | ||
botSearchState.reset(); | ||
} else { | ||
botSearchState.nextPage(); | ||
} | ||
console.log("Search entered: ", botSearchState.term); | ||
client | ||
.exploreBots( | ||
botSearchState.term === "" ? undefined : botSearchState.term, | ||
botSearchState.index, | ||
PAGE_SIZE, | ||
) | ||
.then((results) => { | ||
console.log("Results: ", results); | ||
if (results.kind === "success") { | ||
if (reset) { | ||
botSearchState.results = results.matches; | ||
} else { | ||
botSearchState.appendResults(results.matches); | ||
} | ||
botSearchState.total = results.total; | ||
} | ||
}) | ||
.finally(() => (searching = false)); | ||
} | ||
$effect(() => { | ||
if (!initialised) { | ||
onSearchEntered(true); | ||
initialised = true; | ||
} | ||
}); | ||
</script> | ||
|
||
<Search | ||
on:searchEntered={() => onSearchEntered(true)} | ||
searching={false} | ||
bind:searchTerm={botSearchState.term} | ||
placeholder={i18nKey("search")} /> | ||
|
||
{#if more} | ||
<div class="more"> | ||
<Button disabled={searching} loading={searching} on:click={() => onSearchEntered(false)} | ||
><Translatable resourceKey={i18nKey("bots.explorer.loadMore")} /></Button> | ||
</div> | ||
{/if} | ||
|
||
{#each botSearchState.results as match} | ||
<BotMatch {community} {match} /> | ||
{/each} | ||
|
||
<style lang="scss"></style> |
Oops, something went wrong.