mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-09 09:15:42 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da2639786d | ||
|
|
3cf77da293 | ||
|
|
3dd7633194 | ||
|
|
ae7f4edf4a | ||
|
|
52eab28f27 | ||
|
|
6098d32bce |
20
CHANGELOG.md
20
CHANGELOG.md
@@ -2,6 +2,26 @@
|
||||
|
||||
<!-- changelog -->
|
||||
|
||||
## [v1.52.1](https://github.com/wanderer-industries/wanderer/compare/v1.52.0...v1.52.1) (2025-02-20)
|
||||
|
||||
|
||||
|
||||
|
||||
### Bug Fixes:
|
||||
|
||||
* proper virtual scroller usage (#192)
|
||||
|
||||
* restore delete key functionality for nodes (#191)
|
||||
|
||||
## [v1.52.0](https://github.com/wanderer-industries/wanderer/compare/v1.51.3...v1.52.0) (2025-02-19)
|
||||
|
||||
|
||||
|
||||
|
||||
### Features:
|
||||
|
||||
* Map: Added map characters view
|
||||
|
||||
## [v1.51.3](https://github.com/wanderer-industries/wanderer/compare/v1.51.2...v1.51.3) (2025-02-19)
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ const INITIAL_DATA: MapData = {
|
||||
userPermissions: {},
|
||||
systemSignatures: {} as Record<string, SystemSignature[]>,
|
||||
options: {} as Record<string, string | boolean>,
|
||||
is_subscription_active: false,
|
||||
isSubscriptionActive: false,
|
||||
};
|
||||
|
||||
export interface MapContextProps {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useMemo, useRef, useEffect, useState } from 'react';
|
||||
import React, { useMemo } from 'react';
|
||||
import clsx from 'clsx';
|
||||
import { DetailedKill } from '@/hooks/Mapper/types/kills';
|
||||
import { VirtualScroller } from 'primereact/virtualscroller';
|
||||
@@ -6,7 +6,6 @@ import { useSystemKillsItemTemplate } from '../hooks/useSystemKillsItemTemplate'
|
||||
import classes from './SystemKillsContent.module.scss';
|
||||
|
||||
export const ITEM_HEIGHT = 35;
|
||||
export const CONTENT_MARGINS = 5;
|
||||
|
||||
export interface SystemKillsContentProps {
|
||||
kills: DetailedKill[];
|
||||
@@ -39,45 +38,21 @@ export const SystemKillsContent: React.FC<SystemKillsContentProps> = ({
|
||||
}
|
||||
}, [kills, timeRange, limit]);
|
||||
|
||||
const computedHeight = autoSize ? Math.max(processedKills.length, 1) * ITEM_HEIGHT + CONTENT_MARGINS : undefined;
|
||||
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const scrollerRef = useRef<VirtualScroller | null>(null);
|
||||
const [containerHeight, setContainerHeight] = useState<number>(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (!autoSize && containerRef.current) {
|
||||
const measure = () => {
|
||||
const newHeight = containerRef.current?.clientHeight || 0;
|
||||
setContainerHeight(newHeight);
|
||||
};
|
||||
|
||||
measure();
|
||||
const observer = new ResizeObserver(measure);
|
||||
observer.observe(containerRef.current);
|
||||
window.addEventListener('resize', measure);
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
window.removeEventListener('resize', measure);
|
||||
};
|
||||
}
|
||||
}, [autoSize]);
|
||||
const computedHeight = autoSize ? Math.max(processedKills.length, 1) * ITEM_HEIGHT : undefined;
|
||||
const scrollerHeight = autoSize ? `${computedHeight}px` : '100%';
|
||||
|
||||
const itemTemplate = useSystemKillsItemTemplate(systemNameMap, onlyOneSystem);
|
||||
const scrollerHeight = autoSize ? `${computedHeight}px` : containerHeight ? `${containerHeight}px` : '100%';
|
||||
|
||||
return (
|
||||
<div ref={autoSize ? undefined : containerRef} className={clsx('w-full h-full', classes.wrapper)}>
|
||||
<div className={clsx('w-full h-full', classes.wrapper)}>
|
||||
<VirtualScroller
|
||||
ref={autoSize ? undefined : scrollerRef}
|
||||
items={processedKills}
|
||||
itemSize={ITEM_HEIGHT}
|
||||
itemTemplate={itemTemplate}
|
||||
autoSize={autoSize}
|
||||
scrollWidth="100%"
|
||||
style={{ height: scrollerHeight }}
|
||||
className={clsx('w-full h-full custom-scrollbar select-none overflow-x-hidden overflow-y-auto', {
|
||||
className={clsx('w-full h-full custom-scrollbar select-none', {
|
||||
[classes.VirtualScroller]: !autoSize,
|
||||
})}
|
||||
pt={{
|
||||
@@ -89,3 +64,5 @@ export const SystemKillsContent: React.FC<SystemKillsContentProps> = ({
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default SystemKillsContent;
|
||||
|
||||
@@ -114,11 +114,7 @@ export function SystemSignaturesContent({
|
||||
]);
|
||||
|
||||
useHotkey(true, ['a'], handleSelectAll);
|
||||
useHotkey(false, ['Backspace', 'Delete'], (event: KeyboardEvent) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
handleDeleteSelected();
|
||||
});
|
||||
useHotkey(false, ['Backspace', 'Delete'], handleDeleteSelected);
|
||||
|
||||
const [nameColumnWidth, setNameColumnWidth] = useState('auto');
|
||||
const handleResize = useCallback(() => {
|
||||
|
||||
@@ -66,6 +66,7 @@ export type CommandInit = {
|
||||
routes: RoutesList;
|
||||
options: Record<string, string | boolean>;
|
||||
reset?: boolean;
|
||||
is_subscription_active?: boolean;
|
||||
};
|
||||
export type CommandAddSystems = SolarSystemRawType[];
|
||||
export type CommandUpdateSystems = SolarSystemRawType[];
|
||||
|
||||
84
lib/wanderer_app_web/components/map_characters.ex
Normal file
84
lib/wanderer_app_web/components/map_characters.ex
Normal file
@@ -0,0 +1,84 @@
|
||||
defmodule WandererAppWeb.MapCharacters do
|
||||
use WandererAppWeb, :live_component
|
||||
use LiveViewEvents
|
||||
|
||||
@impl true
|
||||
def mount(socket) do
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def update(
|
||||
assigns,
|
||||
socket
|
||||
) do
|
||||
{:ok,
|
||||
socket
|
||||
|> handle_info_or_assign(assigns)}
|
||||
end
|
||||
|
||||
# attr(:groups, :any, required: true)
|
||||
# attr(:character_settings, :any, required: true)
|
||||
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<div id={@id}>
|
||||
<ul :for={group <- @groups} class="space-y-4 border-t border-b border-gray-200 py-4">
|
||||
<li :for={character <- group.characters}>
|
||||
<div class="flex items-center justify-between w-full space-x-2 p-1 hover:bg-gray-900">
|
||||
<.character_entry character={character} character_settings={@character_settings} />
|
||||
<button
|
||||
phx-click="untrack"
|
||||
phx-value-event-data={character.id}
|
||||
class="btn btn-sm btn-icon"
|
||||
>
|
||||
<.icon name="hero-eye-slash" class="h-5 w-5" /> Untrack
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
attr(:character, :any, required: true)
|
||||
attr(:character_settings, :any, required: true)
|
||||
|
||||
defp character_entry(assigns) do
|
||||
~H"""
|
||||
<div class="flex items-center gap-3 text-sm w-[450px]">
|
||||
<span
|
||||
:if={is_tracked?(@character.id, @character_settings)}
|
||||
class="text-green-500 rounded-full px-2 py-1"
|
||||
>
|
||||
Tracked
|
||||
</span>
|
||||
<div class="avatar">
|
||||
<div class="rounded-md w-8 h-8">
|
||||
<img src={member_icon_url(@character.eve_id)} alt={@character.name} />
|
||||
</div>
|
||||
</div>
|
||||
<span><%= @character.name %></span>
|
||||
<span :if={@character.alliance_ticker}>[<%= @character.alliance_ticker %>]</span>
|
||||
<span :if={@character.corporation_ticker}>[<%= @character.corporation_ticker %>]</span>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("undo", %{"event-data" => event_data} = _params, socket) do
|
||||
# notify_to(socket.assigns.notify_to, socket.assigns.event_name, map_slug)
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
defp is_tracked?(character_id, character_settings) do
|
||||
Enum.any?(character_settings, fn setting ->
|
||||
setting.character_id == character_id && setting.tracked
|
||||
end)
|
||||
end
|
||||
|
||||
defp get_event_name(name), do: name
|
||||
|
||||
defp get_event_data(_name, data), do: Jason.encode!(data)
|
||||
end
|
||||
151
lib/wanderer_app_web/live/maps/map_characters_live.ex
Executable file
151
lib/wanderer_app_web/live/maps/map_characters_live.ex
Executable file
@@ -0,0 +1,151 @@
|
||||
defmodule WandererAppWeb.MapCharactersLive do
|
||||
use WandererAppWeb, :live_view
|
||||
|
||||
require Logger
|
||||
|
||||
alias WandererAppWeb.MapCharacters
|
||||
|
||||
def mount(
|
||||
%{"slug" => map_slug} = _params,
|
||||
_session,
|
||||
%{assigns: %{current_user: current_user}} = socket
|
||||
) do
|
||||
WandererApp.Maps.check_user_can_delete_map(map_slug, current_user)
|
||||
|> case do
|
||||
{:ok,
|
||||
%{
|
||||
id: map_id,
|
||||
name: map_name
|
||||
} = _map} ->
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(
|
||||
map_id: map_id,
|
||||
map_name: map_name,
|
||||
map_slug: map_slug
|
||||
)
|
||||
|> assign(:groups, [])}
|
||||
|
||||
_ ->
|
||||
{:ok,
|
||||
socket
|
||||
|> put_flash(:error, "You don't have an access.")
|
||||
|> push_navigate(to: ~p"/maps")}
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, socket |> assign(user_id: nil)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(params, _url, socket) do
|
||||
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info(
|
||||
_event,
|
||||
socket
|
||||
) do
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
def handle_event(
|
||||
"untrack",
|
||||
%{"event-data" => character_id},
|
||||
%{
|
||||
assigns: %{
|
||||
map_id: map_id,
|
||||
current_user: _current_user,
|
||||
character_settings: character_settings
|
||||
}
|
||||
} = socket
|
||||
) do
|
||||
socket =
|
||||
character_settings
|
||||
|> Enum.find(&(&1.character_id == character_id))
|
||||
|> case do
|
||||
nil ->
|
||||
socket
|
||||
|
||||
character_setting ->
|
||||
case character_setting.tracked do
|
||||
true ->
|
||||
{:ok, map_character_settings} =
|
||||
character_setting
|
||||
|> WandererApp.MapCharacterSettingsRepo.untrack()
|
||||
|
||||
WandererApp.Map.Server.remove_character(map_id, map_character_settings.character_id)
|
||||
|
||||
socket |> put_flash(:info, "Character untracked!") |> load_characters()
|
||||
|
||||
_ ->
|
||||
socket
|
||||
end
|
||||
end
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("noop", _, socket) do
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event(event, body, socket) do
|
||||
Logger.warning(fn -> "unhandled event: #{event} #{inspect(body)}" end)
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
defp apply_action(socket, :index, _params) do
|
||||
socket
|
||||
|> assign(:active_page, :map_characters)
|
||||
|> assign(:page_title, "Map - Characters")
|
||||
|> load_characters()
|
||||
end
|
||||
|
||||
defp load_characters(%{assigns: %{map_id: map_id}} = socket) do
|
||||
map_characters =
|
||||
map_id
|
||||
|> WandererApp.Map.list_characters()
|
||||
|> Enum.map(&map_ui_character/1)
|
||||
|
||||
groups =
|
||||
map_characters
|
||||
|> Enum.group_by(& &1.user_id)
|
||||
|> Enum.reduce([], fn {user_id, values}, acc ->
|
||||
acc ++ [%{id: user_id, characters: values}]
|
||||
end)
|
||||
|
||||
{:ok, character_settings} =
|
||||
case WandererApp.MapCharacterSettingsRepo.get_all_by_map(map_id) do
|
||||
{:ok, settings} -> {:ok, settings}
|
||||
_ -> {:ok, []}
|
||||
end
|
||||
|
||||
socket
|
||||
|> assign(:character_settings, character_settings)
|
||||
|> assign(:characters_count, map_characters |> length())
|
||||
|> assign(:groups, groups)
|
||||
end
|
||||
|
||||
defp map_ui_character(character),
|
||||
do:
|
||||
character
|
||||
|> Map.take([
|
||||
:id,
|
||||
:user_id,
|
||||
:eve_id,
|
||||
:name,
|
||||
:online,
|
||||
:corporation_id,
|
||||
:corporation_name,
|
||||
:corporation_ticker,
|
||||
:alliance_id,
|
||||
:alliance_name,
|
||||
:alliance_ticker
|
||||
])
|
||||
end
|
||||
23
lib/wanderer_app_web/live/maps/map_characters_live.html.heex
Normal file
23
lib/wanderer_app_web/live/maps/map_characters_live.html.heex
Normal file
@@ -0,0 +1,23 @@
|
||||
<nav class="fixed top-0 z-100 px-6 pl-20 flex items-center justify-between w-full h-12 pointer-events-auto border-b border-stone-800 bg-opacity-70 bg-neutral-900">
|
||||
<span className="w-full font-medium text-sm">
|
||||
<.link navigate={~p"/#{@map_slug}"} class="text-neutral-100">
|
||||
<%= @map_name %>
|
||||
</.link>
|
||||
- Characters [<%= @characters_count %>]
|
||||
</span>
|
||||
</nav>
|
||||
<main
|
||||
id="map-character-list"
|
||||
class="pt-20 w-full h-full col-span-2 lg:col-span-1 p-4 pl-20 pb-20 overflow-auto"
|
||||
>
|
||||
<div class="flex flex-col gap-4 w-full">
|
||||
<.live_component
|
||||
module={MapCharacters}
|
||||
id="map-characters"
|
||||
notify_to={self()}
|
||||
groups={@groups}
|
||||
character_settings={@character_settings}
|
||||
event_name="character_event"
|
||||
/>
|
||||
</div>
|
||||
</main>
|
||||
@@ -29,6 +29,15 @@
|
||||
>
|
||||
<.icon name="hero-key-solid" class="w-6 h-6" />
|
||||
</.link>
|
||||
|
||||
<.link
|
||||
:if={(@user_permissions || %{}) |> Map.get(:delete_map, false)}
|
||||
id={"map-characters-#{@map_slug}"}
|
||||
class="h-8 w-8 hover:text-white"
|
||||
navigate={~p"/#{@map_slug}/characters"}
|
||||
>
|
||||
<.icon name="hero-user-group-solid" class="w-6 h-6" />
|
||||
</.link>
|
||||
</div>
|
||||
|
||||
<.modal
|
||||
|
||||
@@ -323,11 +323,17 @@ defmodule WandererAppWeb.MapsLive do
|
||||
|> push_patch(to: ~p"/maps/#{slug}/edit")}
|
||||
end
|
||||
|
||||
def handle_event("open_audit", %{"data" => slug}, socket) do
|
||||
{:noreply,
|
||||
socket
|
||||
|> push_navigate(to: ~p"/#{slug}/audit?period=1H&activity=all")}
|
||||
end
|
||||
def handle_event("open_audit", %{"data" => slug}, socket),
|
||||
do:
|
||||
{:noreply,
|
||||
socket
|
||||
|> push_navigate(to: ~p"/#{slug}/audit?period=1H&activity=all")}
|
||||
|
||||
def handle_event("open_characters", %{"data" => slug}, socket),
|
||||
do:
|
||||
{:noreply,
|
||||
socket
|
||||
|> push_navigate(to: ~p"/#{slug}/characters")}
|
||||
|
||||
def handle_event("open_settings", %{"data" => slug}, socket) do
|
||||
{:noreply,
|
||||
|
||||
@@ -74,6 +74,16 @@
|
||||
</span>
|
||||
</h2>
|
||||
<div class="flex gap-2 justify-end">
|
||||
<button
|
||||
:if={WandererApp.Maps.can_edit?(map, @current_user)}
|
||||
id={"map-characters-#{map.slug}"}
|
||||
phx-hook="MapAction"
|
||||
data-event="open_characters"
|
||||
data-data={map.slug}
|
||||
class="h-8 w-8 hover:text-white"
|
||||
>
|
||||
<.icon name="hero-user-group-solid" class="w-6 h-6" />
|
||||
</button>
|
||||
<button
|
||||
:if={WandererApp.Maps.can_edit?(map, @current_user)}
|
||||
id={"map-audit-#{map.slug}"}
|
||||
@@ -257,7 +267,9 @@
|
||||
:if={@map_subscriptions_enabled?}
|
||||
class={[
|
||||
"p-unselectable-text",
|
||||
classes("p-tabview-selected p-highlight": @active_settings_tab == "subscription")
|
||||
classes(
|
||||
"p-tabview-selected p-highlight": @active_settings_tab == "subscription"
|
||||
)
|
||||
]}
|
||||
role="presentation"
|
||||
data-pc-name=""
|
||||
@@ -309,7 +321,9 @@
|
||||
:if={not WandererApp.Env.public_api_disabled?()}
|
||||
class={[
|
||||
"p-unselectable-text",
|
||||
classes("p-tabview-selected p-highlight": @active_settings_tab == "public_api")
|
||||
classes(
|
||||
"p-tabview-selected p-highlight": @active_settings_tab == "public_api"
|
||||
)
|
||||
]}
|
||||
role="presentation"
|
||||
data-pc-name=""
|
||||
@@ -411,7 +425,10 @@
|
||||
</div>
|
||||
|
||||
<div
|
||||
:if={@active_settings_tab == "public_api" and not WandererApp.Env.public_api_disabled?()}
|
||||
:if={
|
||||
@active_settings_tab == "public_api" and
|
||||
not WandererApp.Env.public_api_disabled?()
|
||||
}
|
||||
class="p-6"
|
||||
>
|
||||
<h2 class="text-lg font-semibold mb-4">Public API</h2>
|
||||
@@ -680,8 +697,10 @@
|
||||
<.button
|
||||
:if={@active_settings_tab == "subscription" && not @is_adding_subscription?}
|
||||
type="button"
|
||||
disabled={@map_subscriptions |> Enum.at(0) |> Map.get(:status) == :active &&
|
||||
@map_subscriptions |> Enum.at(0) |> Map.get(:plan) != :alpha}
|
||||
disabled={
|
||||
@map_subscriptions |> Enum.at(0) |> Map.get(:status) == :active &&
|
||||
@map_subscriptions |> Enum.at(0) |> Map.get(:plan) != :alpha
|
||||
}
|
||||
phx-click="add_subscription"
|
||||
>
|
||||
Add subscription
|
||||
|
||||
@@ -143,7 +143,6 @@ defmodule WandererAppWeb.Router do
|
||||
post "/acls", MapAccessListAPIController, :create
|
||||
end
|
||||
|
||||
|
||||
scope "/api/characters", WandererAppWeb do
|
||||
pipe_through [:api, :api_character]
|
||||
get "/", CharactersAPIController, :index
|
||||
@@ -260,6 +259,7 @@ defmodule WandererAppWeb.Router do
|
||||
live "/profile/deposit", ProfileLive, :deposit
|
||||
live "/profile/subscribe", ProfileLive, :subscribe
|
||||
live "/:slug/audit", MapAuditLive, :index
|
||||
live "/:slug/characters", MapCharactersLive, :index
|
||||
live "/:slug", MapLive, :index
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user