This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
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
2d3882e
commit c358a4f
Showing
5 changed files
with
182 additions
and
6 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,94 @@ | ||
<script> | ||
import Invites from './Invites.svelte'; | ||
import { chat, authHeader } from './../../stores.js'; | ||
import Spinner from './../../Spinner.svelte'; | ||
import { apiUrl } from '../../urls'; | ||
import Modal from "../../Modal.svelte"; | ||
import * as modals from "../../modals"; | ||
import { writable } from 'svelte/store'; | ||
import Container from '../../Container.svelte'; | ||
if (!$chat.invites) $chat.invites = []; | ||
// @ts-ignore | ||
if ((typeof $chat.invites) != 'Array') $chat.invites = []; | ||
async function fetchInvites() { | ||
let data = await (await fetch(`${apiUrl}chats/${$chat._id}/invites`, { | ||
headers: $authHeader | ||
})).json(); | ||
console.log(data) | ||
$chat.invites = data.invites; | ||
} | ||
</script> | ||
|
||
<Modal on:close={modals.closeLastModal}> | ||
<h1 slot="header"> | ||
Chat Invites | ||
</h1> | ||
|
||
<div slot="default"> | ||
{#await fetchInvites()} | ||
<Spinner /> | ||
{/await} | ||
|
||
{#each $chat.invites as invite} | ||
<Container> | ||
<div class="inline"> | ||
<a href="https://app.meower.org/invite/{invite._id}" target="_blank"> | ||
https://app.meower.org/invite/{invite._id} | ||
</a> | ||
<div class="delete"> | ||
<button class="right_align" | ||
on:click|preventDefault={() => { | ||
fetch(`${apiUrl}chats/invites/${invite._id}`, { | ||
method: 'DELETE', | ||
headers: $authHeader | ||
}); | ||
modals.closeLastModal(); | ||
}} | ||
> | ||
Revoke Invite | ||
</button> | ||
</div> | ||
</div> | ||
|
||
</Container> | ||
{/each} | ||
<hr> | ||
<button on:click|preventDefault={async () => { | ||
let invite = await (await fetch(`${apiUrl}chats/${$chat._id}/invites`, { | ||
method: 'POST', | ||
headers: $authHeader | ||
})).json(); | ||
|
||
|
||
$chat.invites = [...$chat.invites, {_id: invite.invite, chat_id: $chat._id}]; | ||
}} >Create Invite</button> | ||
</div> | ||
|
||
</Modal> | ||
|
||
<style> | ||
.right_align { | ||
align-self: right; | ||
} | ||
.delete { | ||
justify-content: right; | ||
flex: right; | ||
} | ||
.inline { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
align-items: left; | ||
vertical-align: middle; | ||
} | ||
.inline a { | ||
justify-self: center; | ||
align-self: center; | ||
} | ||
</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
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,51 @@ | ||
<script> | ||
import {authHeader, chats, user} from "./../../lib/stores.js"; | ||
import {apiUrl} from "../../lib/urls"; | ||
import {params, goto} from "@roxi/routify"; | ||
import {onMount} from "svelte"; | ||
import Container from "../../lib/Container.svelte"; | ||
import Spinner from "../../lib/Spinner.svelte"; | ||
import { writable } from "svelte/store"; | ||
let ok = writable(true); | ||
onMount(() => { | ||
(async () => { | ||
let response = await fetch( | ||
`${apiUrl}chats/join/${$params.invite}`, | ||
{ | ||
method: "GET", | ||
headers: { | ||
...$authHeader, | ||
}, | ||
} | ||
); | ||
if (response.status === 404) { | ||
$goto("/404"); | ||
} else if (!response.ok) { | ||
$goto("/500"); | ||
} | ||
let data = await response.json(); | ||
// Cursed code because the server does not seem to want to send a packet | ||
$chats.findLast( | ||
chat => chat._id === data.chat | ||
).members.push($user.name); | ||
$goto(`/chats/${data.chat}`); | ||
})(); | ||
}); | ||
</script> | ||
|
||
<Container> | ||
<h1>Joining Invite...</h1> | ||
|
||
{#if $ok} | ||
<Spinner /> | ||
{:else} | ||
<h1>Invalid Invite</h1> | ||
|
||
Or you could have been banned. | ||
{/if} | ||
</Container> |