feat: added the linked application system

This commit is contained in:
Andre Henriques 2024-10-04 14:17:21 +01:00
parent 69c60986ff
commit 7217f6afe1
5 changed files with 138 additions and 26 deletions

View File

@ -32,6 +32,7 @@ data class Application(
var company: String,
var recruiter: String,
var message: String,
var linked_application: String,
var flairs: List<Flair>,
var views: List<View>,
) {
@ -50,6 +51,7 @@ data class Application(
rs.getString("company"),
rs.getString("recruiter"),
rs.getString("message"),
rs.getString("linked_application"),
emptyList(),
emptyList(),
)
@ -179,6 +181,7 @@ class ApplicationsController(
"",
"",
"",
"",
emptyList(),
emptyList(),
)
@ -463,7 +466,7 @@ class ApplicationService(
}
db.update(
"insert into applications (id, url, original_url, unique_url, title, user_id, extra_data, payrange, status, company, recruiter, message) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
"insert into applications (id, url, original_url, unique_url, title, user_id, extra_data, payrange, status, company, recruiter, message, linked_application) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
application.id,
application.url,
application.original_url,
@ -476,6 +479,7 @@ class ApplicationService(
application.company,
application.recruiter,
application.message,
application.linked_application,
)
return true
@ -491,6 +495,17 @@ class ApplicationService(
.toList()
}
// If it's to apply also remove the linked_application to only show the main
if (info.status == 0) {
return db.query(
"select * from applications where user_id=? and linked_application='' and status=0 order by title asc;",
arrayOf(user.id),
Application
)
.toList()
}
return db.query(
"select * from applications where user_id=? and status=? order by title asc;",
arrayOf(user.id, info.status),
@ -501,7 +516,7 @@ class ApplicationService(
public fun update(application: Application): Application {
db.update(
"update applications set url=?, original_url=?, unique_url=?, title=?, user_id=?, extra_data=?, payrange=?, status=?, company=?, recruiter=?, message=? where id=?",
"update applications set url=?, original_url=?, unique_url=?, title=?, user_id=?, extra_data=?, payrange=?, status=?, company=?, recruiter=?, message=?, linked_application=? where id=?",
application.url,
application.original_url,
application.unique_url,
@ -513,6 +528,7 @@ class ApplicationService(
application.company,
application.recruiter,
application.message,
application.linked_application,
application.id,
)
return application

View File

@ -12,17 +12,18 @@ CREATE TABLE IF NOT EXISTS tokens (
);
create table if not exists applications (
id text primary key,
url text not null,
original_url text,
unique_url text,
company text,
recruiter text,
title text,
mesasge text default '',
user_id text,
extra_data text,
status integer
id text primary key,
url text not null,
original_url text,
unique_url text,
company text,
recruiter text,
title text,
mesasge text default '',
user_id text,
extra_data text,
status integer,
linked_application text default ''
);
create table if not exists views (

View File

@ -40,8 +40,9 @@ export type Application = {
status: number;
recruiter: string;
company: string;
flairs: Flair[];
message: string;
linked_application: string;
flairs: Flair[];
views: View[];
};

View File

@ -0,0 +1,79 @@
<script lang="ts">
import type { Application } from '$lib/ApplicationsStore.svelte';
import { post, put } from '$lib/utils';
let {
application,
dialog = $bindable(),
onreload
}: {
application: Application;
dialog: HTMLDialogElement;
onreload: (item: Application) => void;
} = $props();
let filter = $state('');
let applications: Application[] = $state([]);
async function getApplicationList() {
const app: Application[] = await post('application/list', {});
applications = app.filter((a) => a.id != application.id);
}
$effect(() => {
getApplicationList();
});
async function submit(item: Application) {
try {
application.linked_application = item.id;
await put('application/update', application);
dialog.close();
onreload(item);
} catch (e) {
// Show message to the user
console.log(e);
}
}
</script>
<dialog class="card max-w-[50vw]" bind:this={dialog}>
<div class="flex">
<input placeholder="Filter" class="p-2 flex-grow" bind:value={filter} />
<div>
{applications.length}
</div>
</div>
<div class="overflow-y-auto overflow-x-hidden flex-grow p-2">
{#each applications.filter((i) => {
if (!filter) {
return true;
}
const f = new RegExp(filter, 'ig');
let x = i.title;
if (i.company) {
x = `${x} @ ${i.company}`;
}
return x.match(f);
}) as item}
<div class="card p-2 my-2 bg-slate-100 max-w-full" role="none">
<button class="text-left max-w-full" type="button" onclick={() => submit(item)}>
<h2 class="text-lg text-blue-500">
{item.title}
{#if item.company}
<div class="text-violet-800">
@ {item.company}
</div>
{/if}
</h2>
<span class="text-violet-600 overflow-hidden whitespace-nowrap block max-w-full">
{item.url}
</span>
</button>
</div>
{/each}
</div>
</dialog>

View File

@ -13,11 +13,13 @@
import NewUrlDialog from './NewUrlDialog.svelte';
import DropZone from './DropZone.svelte';
import { userStore } from '$lib/UserStore.svelte';
import LinkApplication from './LinkApplication.svelte';
let activeItem: Application | undefined = $state();
let extractTokens: HTMLDialogElement;
let changeUrl: HTMLDialogElement;
let linkApplication: HTMLDialogElement;
let lastExtData: any = $state(undefined);
let autoExtData = false;
@ -268,29 +270,28 @@
onchange={save}
/>
</fieldset>
<fieldset
draggable="false"
onmouseenter={() => (drag = false)}
onmouseleave={() => (drag = true)}
class="max-w-full min-w-0 overflow-hidden"
>
<fieldset draggable="false" class="max-w-full min-w-0 overflow-hidden">
<div class="flabel">Url</div>
<div class="finput bg-white w-full break-keep">
{activeItem.url}
</div>
</fieldset>
{#if activeItem.unique_url}
<fieldset
draggable="false"
onmouseenter={() => (drag = false)}
onmouseleave={() => (drag = true)}
>
{#if activeItem.unique_url && activeItem.unique_url !== activeItem.url}
<fieldset draggable="false">
<div class="flabel">Unique Url</div>
<div class="finput bg-white">
{activeItem.unique_url}
</div>
</fieldset>
{/if}
{#if activeItem.linked_application}
<fieldset draggable="false">
<div class="flabel">Linked Application</div>
<div class="finput bg-white">
{activeItem.linked_application}
</div>
</fieldset>
{/if}
<div>
<div class="flabel">Tags</div>
<div class="flex gap-2 flex-wrap">
@ -342,6 +343,7 @@
Open
</button>
<button class="btn-primary" onclick={() => openCV()}> Open CV </button>
<div class="px-10"></div>
<button class="btn-primary" onclick={() => extractTokens.showModal()}>
Extract Flair
</button>
@ -363,9 +365,14 @@
Update Url
</button>
{/if}
<div class="px-10"></div>
<button class="btn-primary" onclick={() => linkApplication.showModal()}>
Link Application
</button>
{#if activeItem.original_url != null}
<button class="btn-danger" onclick={resetUrl}> Reset Url </button>
{/if}
<button class:btn-primary={drag} class:btn-danger={!drag} onclick={() => (drag = !drag)}> 👋 </button>
</div>
</div>
{#if applicationStore.dragging}
@ -462,3 +469,11 @@
onreload={(item) => (activeItem = item)}
/>
{/if}
{#if activeItem}
<LinkApplication
application={activeItem}
bind:dialog={linkApplication}
onreload={(item) => (activeItem = item)}
/>
{/if}