Skip to content

Commit

Permalink
Merge pull request #4 from Kagashino/dev
Browse files Browse the repository at this point in the history
refactor: migrate almanac helpers to published npm package
  • Loading branch information
Kagashino authored Mar 17, 2020
2 parents cf40dd2 + 6273dc9 commit 0adcb2b
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 225 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"version": "1.0.1",
"author": "Kagashino",
"license": "MIT",
"typings": "./src/types/index.d.ts",
"dependencies": {
"dayjs": "^1.8.17",
"programmer-almanac-generator": "^0.9.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-markdown": "^4.2.2",
Expand Down
41 changes: 0 additions & 41 deletions src/assets/api/almanac_set.json

This file was deleted.

2 changes: 0 additions & 2 deletions src/assets/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ export default {
}
}
}

export const getAlmanacSet = ()=>import('./almanac_set.json');
110 changes: 0 additions & 110 deletions src/assets/helpers/Almanac.ts

This file was deleted.

25 changes: 3 additions & 22 deletions src/container/Almanac.hook.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
import {useEffect, useState} from "react";
import {init} from "programmer-almanac-generator";

import { getAlmanacSet } from "../assets/api";
import { generateAlmanac } from "../assets/helpers/Almanac";
import { AlmanacResult, AlmanacSet} from "../types";

export const useAlmanac = ()=>{
const [result, setResult] = useState<AlmanacResult>({
bad: [],
direction: '',
drink: [],
good: [],
rate: '',
todayStr: '',
})
useEffect(()=>{
getAlmanacSet().then(res=>{
const Assets: AlmanacSet = res.default;
const Almanac = generateAlmanac(Assets, new Date())
setResult(Almanac);
})
}, [])
return result;
export const useAlmanac = (): AlmanacResult => {
return init(new Date());
}
1 change: 0 additions & 1 deletion src/container/Almanac.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import { AlmanacResult } from "../types";
import { useAlmanac } from './Almanac.hook'

import './styles/Almanac.scss'
Expand Down
29 changes: 29 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
declare type AlmanacActivity = {
name: string,
good: string,
bad: string,
weekend?: boolean
}


declare type AlmanacSet = {
Weeks: Array
Activities: Array
Specials: Array
Directions: Array
Tools: Array
Variables: Array
Drinks: Array
}


declare type AlmanacResult = {
todayStr: string
good: Array<{ name: string, good: string, bad: string, weekend?: boolean }>
bad: Array<{ name: string, good: string, bad: string, weekend?: boolean }>
direction: string
drink: string[]
rate: string
}

declare module 'programmer-almanac-generator';
49 changes: 0 additions & 49 deletions src/types/index.d.ts

This file was deleted.

21 changes: 21 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export interface Paging {
page: number,
size?: number,
count: number,
}

export interface PagingList<T> extends Paging {
list: T[]
}

export interface Article {
access: number,
author: string,
content?: string,
created: number,
id: number | string,
tags: string
title: string
}

export interface Articles extends PagingList<Article>{}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8363,6 +8363,11 @@ process@^0.11.10:
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI=

programmer-almanac-generator@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/programmer-almanac-generator/-/programmer-almanac-generator-0.9.1.tgz#2f2c48bd9410ee293c9658c4c58a97fa53ce2e91"
integrity sha512-F3qz7W0kiW3U7nAutfKlCmwmRMWcdYYFTv9cYyJfmAIlyLCOy9fIJtP4JQbyYz0Xjot8EJdoQI4kDeb7BHP9LA==

progress@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
Expand Down

0 comments on commit 0adcb2b

Please sign in to comment.