rewrite URLs to represent instance (#2)
This commit is contained in:
parent
41143cdddf
commit
a3fdd0007c
15 changed files with 199 additions and 168 deletions
|
@ -18,7 +18,10 @@ app.subscribe(app => {
|
|||
*/
|
||||
function saveApp(app) {
|
||||
if (!browser) return;
|
||||
if (!app) localStorage.removeItem(app_name + "_app");
|
||||
if (!app) {
|
||||
localStorage.removeItem(app_name + "_app");
|
||||
return;
|
||||
}
|
||||
localStorage.setItem(app_name + "_app", JSON.stringify(app));
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,10 @@ export async function createServer(host) {
|
|||
*/
|
||||
function saveServer(server) {
|
||||
if (!browser) return;
|
||||
if (!server) localStorage.removeItem(app_name + "_server");
|
||||
if (!server) {
|
||||
localStorage.removeItem(app_name + "_server");
|
||||
return;
|
||||
}
|
||||
localStorage.setItem(app_name + "_server", JSON.stringify(server));
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
</div>
|
||||
</header>
|
||||
|
||||
{#if $logged_in}
|
||||
{#if $account}
|
||||
<div id="nav-items">
|
||||
<Button label="Timeline"
|
||||
on:click={() => handle_btn("timeline")}
|
||||
|
@ -180,6 +180,7 @@
|
|||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<span class="version">
|
||||
campfire v{VERSION}
|
||||
<br>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<script>
|
||||
import * as api from '$lib/api';
|
||||
import { get } from 'svelte/store';
|
||||
import { server } from '$lib/client/server';
|
||||
import { app } from '$lib/client/app';
|
||||
import { account } from '@cf/store/account';
|
||||
|
@ -20,11 +19,13 @@
|
|||
export let post;
|
||||
|
||||
async function toggleBoost() {
|
||||
if (!$app || !$app.token) return;
|
||||
|
||||
let data;
|
||||
if (post.boosted)
|
||||
data = await api.unboostPost(get(server).host, get(app).token, post.id);
|
||||
data = await api.unboostPost($server.host, $app.token, post.id);
|
||||
else
|
||||
data = await api.boostPost(get(server).host, get(app).token, post.id);
|
||||
data = await api.boostPost($server.host, $app.token, post.id);
|
||||
if (!data) {
|
||||
console.error(`Failed to boost post ${post.id}`);
|
||||
return;
|
||||
|
@ -34,11 +35,13 @@
|
|||
}
|
||||
|
||||
async function toggleFavourite() {
|
||||
if (!$app || !$app.token) return;
|
||||
|
||||
let data;
|
||||
if (post.favourited)
|
||||
data = await api.unfavouritePost(get(server).host, get(app).token, post.id);
|
||||
data = await api.unfavouritePost($server.host, $app.token, post.id);
|
||||
else
|
||||
data = await api.favouritePost(get(server).host, get(app).token, post.id);
|
||||
data = await api.favouritePost($server.host, $app.token, post.id);
|
||||
if (!data) {
|
||||
console.error(`Failed to favourite post ${post.id}`);
|
||||
return;
|
||||
|
@ -69,13 +72,13 @@
|
|||
<ActionButton type="reply" label="Reply" bind:count={post.reply_count} sound="post" disabled>
|
||||
<ReplyIcon/>
|
||||
</ActionButton>
|
||||
<ActionButton type="boost" label="Boost" on:click={toggleBoost} bind:active={post.boosted} bind:count={post.boost_count} sound="boost">
|
||||
<ActionButton type="boost" label="Boost" on:click={toggleBoost} bind:active={post.boosted} bind:count={post.boost_count} sound="boost" disabled={!$account}>
|
||||
<RepostIcon/>
|
||||
<svelte:fragment slot="activeIcon">
|
||||
<RepostIcon/>
|
||||
</svelte:fragment>
|
||||
</ActionButton>
|
||||
<ActionButton type="favourite" label="Favourite" on:click={toggleFavourite} bind:active={post.favourited} bind:count={post.favourite_count}>
|
||||
<ActionButton type="favourite" label="Favourite" on:click={toggleFavourite} bind:active={post.favourited} bind:count={post.favourite_count} disabled={!$account}>
|
||||
<FavouriteIcon/>
|
||||
<svelte:fragment slot="activeIcon">
|
||||
<FavouriteIconFill/>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { server } from '$lib/client/server';
|
||||
|
||||
import BoostContext from './BoostContext.svelte';
|
||||
import ReplyContext from './ReplyContext.svelte';
|
||||
|
@ -31,7 +32,7 @@
|
|||
event.ctrlKey)) return;
|
||||
if (event.key && event.key !== "Enter") return;
|
||||
}
|
||||
goto(`/post/${post.id}`);
|
||||
goto(`/${$server.host}/${post.account.mention}/${post.id}`);
|
||||
}
|
||||
|
||||
let el;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import * as api from '$lib/api.js';
|
||||
import { server, capabilities } from '$lib/client/server.js';
|
||||
import { app } from '$lib/client/app.js';
|
||||
import { get } from 'svelte/store';
|
||||
import { account } from '@cf/store/account';
|
||||
import { parseReactions } from '$lib/post.js';
|
||||
|
||||
import ReactionButton from './ReactionButton.svelte';
|
||||
|
@ -11,6 +11,8 @@
|
|||
export let post;
|
||||
|
||||
async function toggleReaction(reaction) {
|
||||
if (!$app || !$app.token) return;
|
||||
|
||||
if (
|
||||
reaction.name.includes('@') &&
|
||||
!$server.capabilities.includes(capabilities.FOREIGN_REACTIONS)
|
||||
|
@ -18,9 +20,9 @@
|
|||
|
||||
let data;
|
||||
if (reaction.me)
|
||||
data = await api.unreactPost(get(server).host, get(app).token, post.id, reaction.name);
|
||||
data = await api.unreactPost($server.host, $app.token, post.id, reaction.name);
|
||||
else
|
||||
data = await api.reactPost(get(server).host, get(app).token, post.id, reaction.name);
|
||||
data = await api.reactPost($server.host, $app.token, post.id, reaction.name);
|
||||
if (!data) {
|
||||
console.error(`Failed to favourite post ${post.id}`);
|
||||
return;
|
||||
|
@ -39,7 +41,7 @@
|
|||
on:click={() => toggleReaction(reaction)}
|
||||
bind:active={reaction.me}
|
||||
bind:count={reaction.count}
|
||||
disabled={reaction.name.includes('@') && !$server.capabilities.includes(capabilities.FOREIGN_REACTIONS)}
|
||||
disabled={!$account || (reaction.name.includes('@') && !$server.capabilities.includes(capabilities.FOREIGN_REACTIONS))}
|
||||
title={reaction.name}
|
||||
label="">
|
||||
{#if reaction.url}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue