Skip to content

Commit

Permalink
Add support for Canada (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmreed authored Dec 28, 2023
1 parent 0f4a17e commit 40046cc
Show file tree
Hide file tree
Showing 12 changed files with 618 additions and 127 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ PayTransparency.work is built by <a href="https://ktema.org">David Reed</a> usin

</p>
<p>
State map icons are from
United States map icons are from
<a href="https://github.com/coryetzkorn/state-svg-defs">coryetzkorn</a> and originally derive from
<a href="https://github.com/propublica/stateface">ProPublica's StateFace</a>.
<a href="https://github.com/propublica/stateface">ProPublica's StateFace</a>. Canada map icons are
derived from <a href="https://commons.wikimedia.org/wiki/File:Canada_blank_map.svg">Wikimedia's Canada
map</a>.
</p>
<p>
This site is <a href="https://github.com/davidmreed/paytransparency.work">open source</a> and
Expand Down
4 changes: 3 additions & 1 deletion src/lib/CheckSituation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import SituationDescription from './SituationDescription.svelte';
import type { z } from 'zod';
import { locales, OTHER_LOCALE, US_REMOTE_LOCALE } from '$lib/data';
import { CA_REMOTE_LOCALE, locales, OTHER_LOCALE, US_REMOTE_LOCALE } from '$lib/data';
export let params: z.infer<typeof Params>;
function localeName(l: string): string {
if (l === US_REMOTE_LOCALE) {
return 'the entire United States';
} else if (l === CA_REMOTE_LOCALE) {
return 'all of Canada';
} else if (l === OTHER_LOCALE) {
return "a location for which we don't track laws";
} else {
Expand Down
220 changes: 116 additions & 104 deletions src/lib/StateIcon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,109 +3,121 @@
export let locale: Locale;
const stateCode = locale.stateCode;
const country = locale.country;
</script>

<!-- We use this repetitive logic because our SVG-inlining package will not process dynamic SVG paths -->
<!-- This ensures that paths are static at build time. -->

{#if stateCode == 'AK'}
<svg data-inline-src="AK.svg" />
{:else if stateCode == 'AL'}
<svg data-inline-src="AL.svg" />
{:else if stateCode == 'AR'}
<svg data-inline-src="AR.svg" />
{:else if stateCode == 'AZ'}
<svg data-inline-src="AZ.svg" />
{:else if stateCode == 'CA'}
<svg data-inline-src="CA.svg" />
{:else if stateCode == 'CO'}
<svg data-inline-src="CO.svg" />
{:else if stateCode == 'CT'}
<svg data-inline-src="CT.svg" />
{:else if stateCode == 'DC'}
<svg data-inline-src="DC.svg" />
{:else if stateCode == 'DE'}
<svg data-inline-src="DE.svg" />
{:else if stateCode == 'FL'}
<svg data-inline-src="FL.svg" />
{:else if stateCode == 'GA'}
<svg data-inline-src="GA.svg" />
{:else if stateCode == 'HI'}
<svg data-inline-src="HI.svg" />
{:else if stateCode == 'IA'}
<svg data-inline-src="IA.svg" />
{:else if stateCode == 'ID'}
<svg data-inline-src="ID.svg" />
{:else if stateCode == 'IL'}
<svg data-inline-src="IN.svg" />
{:else if stateCode == 'KS'}
<svg data-inline-src="KS.svg" />
{:else if stateCode == 'KY'}
<svg data-inline-src="KY.svg" />
{:else if stateCode == 'LA'}
<svg data-inline-src="LA.svg" />
{:else if stateCode == 'MA'}
<svg data-inline-src="MA.svg" />
{:else if stateCode == 'MD'}
<svg data-inline-src="MD.svg" />
{:else if stateCode == 'ME'}
<svg data-inline-src="ME.svg" />
{:else if stateCode == 'MI'}
<svg data-inline-src="MI.svg" />
{:else if stateCode == 'MN'}
<svg data-inline-src="MN.svg" />
{:else if stateCode == 'MO'}
<svg data-inline-src="MO.svg" />
{:else if stateCode == 'MS'}
<svg data-inline-src="MS.svg" />
{:else if stateCode == 'MT'}
<svg data-inline-src="MT.svg" />
{:else if stateCode == 'NC'}
<svg data-inline-src="NC.svg" />
{:else if stateCode == 'ND'}
<svg data-inline-src="ND.svg" />
{:else if stateCode == 'NE'}
<svg data-inline-src="NE.svg" />
{:else if stateCode == 'NH'}
<svg data-inline-src="NH.svg" />
{:else if stateCode == 'NJ'}
<svg data-inline-src="NJ.svg" />
{:else if stateCode == 'NM'}
<svg data-inline-src="NM.svg" />
{:else if stateCode == 'NV'}
<svg data-inline-src="NV.svg" />
{:else if stateCode == 'NY'}
<svg data-inline-src="NY.svg" />
{:else if stateCode == 'OH'}
<svg data-inline-src="OH.svg" />
{:else if stateCode == 'OK'}
<svg data-inline-src="OK.svg" />
{:else if stateCode == 'OR'}
<svg data-inline-src="OR.svg" />
{:else if stateCode == 'PA'}
<svg data-inline-src="PA.svg" />
{:else if stateCode == 'RI'}
<svg data-inline-src="RI.svg" />
{:else if stateCode == 'SC'}
<svg data-inline-src="SC.svg" />
{:else if stateCode == 'SD'}
<svg data-inline-src="SD.svg" />
{:else if stateCode == 'TN'}
<svg data-inline-src="TN.svg" />
{:else if stateCode == 'TX'}
<svg data-inline-src="TX.svg" />
{:else if stateCode == 'UT'}
<svg data-inline-src="UT.svg" />
{:else if stateCode == 'VA'}
<svg data-inline-src="VA.svg" />
{:else if stateCode == 'VT'}
<svg data-inline-src="VT.svg" />
{:else if stateCode == 'WA'}
<svg data-inline-src="WA.svg" />
{:else if stateCode == 'WI'}
<svg data-inline-src="WI.svg" />
{:else if stateCode == 'WV'}
<svg data-inline-src="WV.svg" />
{:else if stateCode == 'WY'}
<svg data-inline-src="WY.svg" />
{/if}
<span style="text-decoration: none; display: inline-block;">
<!-- We use this repetitive logic because our SVG-inlining package will not process dynamic SVG paths -->
<!-- This ensures that paths are static at build time. -->
{#if country == 'United States'}
<span style="font-size: 28px; position:relative; left: 15px;">🇺🇸</span>
{#if stateCode == 'AK'}
<svg data-inline-src="AK.svg" />
{:else if stateCode == 'AL'}
<svg data-inline-src="AL.svg" />
{:else if stateCode == 'AR'}
<svg data-inline-src="AR.svg" />
{:else if stateCode == 'AZ'}
<svg data-inline-src="AZ.svg" />
{:else if stateCode == 'CA'}
<svg data-inline-src="CA.svg" />
{:else if stateCode == 'CO'}
<svg data-inline-src="CO.svg" />
{:else if stateCode == 'CT'}
<svg data-inline-src="CT.svg" />
{:else if stateCode == 'DC'}
<svg data-inline-src="DC.svg" />
{:else if stateCode == 'DE'}
<svg data-inline-src="DE.svg" />
{:else if stateCode == 'FL'}
<svg data-inline-src="FL.svg" />
{:else if stateCode == 'GA'}
<svg data-inline-src="GA.svg" />
{:else if stateCode == 'HI'}
<svg data-inline-src="HI.svg" />
{:else if stateCode == 'IA'}
<svg data-inline-src="IA.svg" />
{:else if stateCode == 'ID'}
<svg data-inline-src="ID.svg" />
{:else if stateCode == 'IL'}
<svg data-inline-src="IN.svg" />
{:else if stateCode == 'KS'}
<svg data-inline-src="KS.svg" />
{:else if stateCode == 'KY'}
<svg data-inline-src="KY.svg" />
{:else if stateCode == 'LA'}
<svg data-inline-src="LA.svg" />
{:else if stateCode == 'MA'}
<svg data-inline-src="MA.svg" />
{:else if stateCode == 'MD'}
<svg data-inline-src="MD.svg" />
{:else if stateCode == 'ME'}
<svg data-inline-src="ME.svg" />
{:else if stateCode == 'MI'}
<svg data-inline-src="MI.svg" />
{:else if stateCode == 'MN'}
<svg data-inline-src="MN.svg" />
{:else if stateCode == 'MO'}
<svg data-inline-src="MO.svg" />
{:else if stateCode == 'MS'}
<svg data-inline-src="MS.svg" />
{:else if stateCode == 'MT'}
<svg data-inline-src="MT.svg" />
{:else if stateCode == 'NC'}
<svg data-inline-src="NC.svg" />
{:else if stateCode == 'ND'}
<svg data-inline-src="ND.svg" />
{:else if stateCode == 'NE'}
<svg data-inline-src="NE.svg" />
{:else if stateCode == 'NH'}
<svg data-inline-src="NH.svg" />
{:else if stateCode == 'NJ'}
<svg data-inline-src="NJ.svg" />
{:else if stateCode == 'NM'}
<svg data-inline-src="NM.svg" />
{:else if stateCode == 'NV'}
<svg data-inline-src="NV.svg" />
{:else if stateCode == 'NY'}
<svg data-inline-src="NY.svg" />
{:else if stateCode == 'OH'}
<svg data-inline-src="OH.svg" />
{:else if stateCode == 'OK'}
<svg data-inline-src="OK.svg" />
{:else if stateCode == 'OR'}
<svg data-inline-src="OR.svg" />
{:else if stateCode == 'PA'}
<svg data-inline-src="PA.svg" />
{:else if stateCode == 'RI'}
<svg data-inline-src="RI.svg" />
{:else if stateCode == 'SC'}
<svg data-inline-src="SC.svg" />
{:else if stateCode == 'SD'}
<svg data-inline-src="SD.svg" />
{:else if stateCode == 'TN'}
<svg data-inline-src="TN.svg" />
{:else if stateCode == 'TX'}
<svg data-inline-src="TX.svg" />
{:else if stateCode == 'UT'}
<svg data-inline-src="UT.svg" />
{:else if stateCode == 'VA'}
<svg data-inline-src="VA.svg" />
{:else if stateCode == 'VT'}
<svg data-inline-src="VT.svg" />
{:else if stateCode == 'WA'}
<svg data-inline-src="WA.svg" />
{:else if stateCode == 'WI'}
<svg data-inline-src="WI.svg" />
{:else if stateCode == 'WV'}
<svg data-inline-src="WV.svg" />
{:else if stateCode == 'WY'}
<svg data-inline-src="WY.svg" />
{/if}
{:else if country == 'Canada'}
<span style="font-size: 28px; position:relative; left: 15px;">🇨🇦</span>
{#if stateCode == 'BC'}
<svg data-inline-src="CA-BC.svg" />
{:else if stateCode == 'PE'}
<svg data-inline-src="CA-PE.svg" />
{/if}
{/if}
</span>
4 changes: 2 additions & 2 deletions src/lib/URLParamStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export function createQueryStore<K extends ZodType>(paramType: K) {
};
}

export function asURLSearchParams(p: any): URLSearchParams {
export function asURLSearchParams(p: unknown): URLSearchParams {
return new URLSearchParams(QueryParams.parse(p));
}

export function asQueryString(p: any): string {
export function asQueryString(p: unknown): string {
return asURLSearchParams(p).toString();
}
9 changes: 7 additions & 2 deletions src/lib/checking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
type WhatDisclosure,
Situation,
allLocales,
type AbstractLocale
type AbstractLocale,
CA_REMOTE_LOCALE
} from '$lib/data';
import { sortByBoolean, sortByCriteria } from './sorting';

Expand Down Expand Up @@ -42,7 +43,11 @@ export const Params = z.object({
.transform((s) => s.split(',').filter((m) => m !== ''))
.refine((s) =>
s.every(
(l) => Object.keys(locales).includes(l) || l === OTHER_LOCALE || l === US_REMOTE_LOCALE
(l) =>
Object.keys(locales).includes(l) ||
l === OTHER_LOCALE ||
l === US_REMOTE_LOCALE ||
l === CA_REMOTE_LOCALE
)
)
});
Expand Down
Loading

0 comments on commit 40046cc

Please sign in to comment.